Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect state extraction from query string #197

Merged
merged 4 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@auth0/component-cdn-uploader": "auth0/component-cdn-uploader#v2.2.2",
"@types/cypress": "^1.1.3",
"@types/jest": "^24.0.15",
"@types/qs": "^6.5.3",
"@typescript-eslint/eslint-plugin-tslint": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"cli-table": "^0.3.1",
Expand All @@ -50,6 +49,7 @@
"pem": "^1.14.2",
"prettier": "^1.18.2",
"pretty-quick": "^1.11.1",
"qss": "^2.0.3",
luisrudge marked this conversation as resolved.
Show resolved Hide resolved
"rimraf": "^3.0.0",
"rollup": "^1.17.0",
"rollup-plugin-commonjs": "^10.0.1",
Expand All @@ -73,7 +73,6 @@
"es-cookie": "^1.2.0",
"fast-text-encoding": "^1.0.0",
"promise-polyfill": "^8.1.3",
"qss": "^2.0.3",
"unfetch": "^4.1.0"
},
"files": [
Expand Down
21 changes: 15 additions & 6 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as qs from 'qss';
import fetch from 'unfetch';

import { DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS } from './constants';
Expand All @@ -13,11 +12,17 @@ export const getUniqueScopes = (...scopes: string[]) => {
.trim();
};

export const parseQueryResult = (hash: string) => {
var hashed = <any>qs.decode(hash);
export const parseQueryResult = (queryString: string) => {
let queryParams = queryString.split('&');
let parsedQuery: any = {};
queryParams.forEach(qp => {
let [key, val] = qp.split('=');
parsedQuery[key] = decodeURIComponent(val);
});

return <AuthenticationResult>{
...hashed,
expires_in: parseInt(hashed.expires_in)
...parsedQuery,
expires_in: parseInt(parsedQuery.expires_in)
};
};

Expand Down Expand Up @@ -96,7 +101,11 @@ export const createRandomString = () => {
export const encodeState = (state: string) => btoa(state);
export const decodeState = (state: string) => atob(state);

export const createQueryParams = (params: any) => qs.encode(params);
export const createQueryParams = (params: any) => {
return Object.keys(params)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
.join('&');
};

export const sha256 = (s: string) =>
window.crypto.subtle.digest({ name: 'SHA-256' }, new TextEncoder().encode(s));
Expand Down