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

Update auth0.js and add flag to enable impersonation #1290

Merged
merged 3 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@
"zuul-ngrok": "4.0.0"
},
"dependencies": {
"auth0-js": "^9.3.0",
"auth0-js": "^9.3.3",
"blueimp-md5": "2.3.1",
"fbjs": "^0.3.1",
"idtoken-verifier": "^1.0.1",
"immutable": "^3.7.3",
"jsonp": "^0.2.0",
"password-sheriff": "^1.1.0",
Expand Down
24 changes: 24 additions & 0 deletions src/__tests__/core/web_api/__snapshots__/p2_api.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ Object {
}
`;

exports[`Auth0APIClient parseHash should pass __enableImpersonation when options._enableImpersonation===true 1`] = `
Array [
Object {
"__enableImpersonation": true,
"hash": "hash",
"nonce": undefined,
"state": undefined,
},
"cb",
]
`;

exports[`Auth0APIClient parseHash should pass __enableImpersonation:false when options._enableImpersonation is not present 1`] = `
Array [
Object {
"__enableImpersonation": false,
"hash": "hash",
"nonce": undefined,
"state": undefined,
},
"cb",
]
`;

exports[`Auth0APIClient passwordlessStart should call client.passwordlessStart 1`] = `
Array [
Object {
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/core/web_api/p2_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,22 @@ describe('Auth0APIClient', () => {
expect(mock.calls.length).toBe(1);
expect(mock.calls[0]).toMatchSnapshot();
});
describe('parseHash', () => {
it('should pass __enableImpersonation:false when options._enableImpersonation is not present', () => {
const client = getClient({});
client.parseHash('hash', 'cb');
const mock = getAuth0ClientMock();
const parseHashMock = mock.WebAuth.mock.instances[0].parseHash.mock;
expect(parseHashMock.calls.length).toBe(1);
expect(parseHashMock.calls[0]).toMatchSnapshot();
});
it('should pass __enableImpersonation when options._enableImpersonation===true', () => {
const client = getClient({ _enableImpersonation: true });
client.parseHash('hash', 'cb');
const mock = getAuth0ClientMock();
const parseHashMock = mock.WebAuth.mock.instances[0].parseHash.mock;
expect(parseHashMock.calls.length).toBe(1);
expect(parseHashMock.calls[0]).toMatchSnapshot();
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides checking that the option is set on the auth0js client, you can also check that a real auth0js client can parse or throws an exception depending on the flag and on the state passed in the hash. (2 more tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not testing auth0.js internals inside lock

2 changes: 2 additions & 0 deletions src/core/web_api/p2_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Auth0APIClient {
this.authOpt = null;
this.domain = domain;
this.isUniversalLogin = window.location.host === domain;
this._enableImpersonation = !!opts._enableImpersonation;

const default_telemetry = {
name: 'lock.js',
Expand Down Expand Up @@ -93,6 +94,7 @@ class Auth0APIClient {
parseHash(hash = '', cb) {
return this.client.parseHash(
{
__enableImpersonation: this._enableImpersonation,
hash,
nonce: this.authOpt.nonce,
state: this.authOpt.state
Expand Down
61 changes: 16 additions & 45 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -392,12 +392,12 @@ atob@~1.1.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/atob/-/atob-1.1.3.tgz#95f13629b12c3a51a5d215abdce2aa9f32f80773"

auth0-js@^9.3.0:
version "9.3.0"
resolved "https://registry.yarnpkg.com/auth0-js/-/auth0-js-9.3.0.tgz#67083dc48f9027a0024e6d92994f3c83a4778feb"
auth0-js@^9.3.3:
version "9.3.3"
resolved "https://registry.yarnpkg.com/auth0-js/-/auth0-js-9.3.3.tgz#c4573ffefba102171982d4a2044eade73baa1b8d"
dependencies:
base64-js "^1.2.0"
idtoken-verifier "^1.1.1"
idtoken-verifier "^1.1.2"
qs "^6.4.0"
superagent "^3.8.2"
url-join "^1.1.0"
Expand Down Expand Up @@ -2193,10 +2193,6 @@ [email protected]:
version "1.3.0"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-1.3.0.tgz#dd00b35679021e99cbd4e855b9ad041913474765"

cookiejar@^2.0.6:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.0.tgz#86549689539b6d0e269b6637a304be508194d898"

cookiejar@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.1.tgz#41ad57b1b555951ec171412a81942b1e8200d34a"
Expand Down Expand Up @@ -3439,14 +3435,6 @@ forever-agent@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"

form-data@^2.1.1, form-data@~2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.2.tgz#89c3534008b97eada4cbb157d58f6f5df025eae4"
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.5"
mime-types "^2.1.12"

form-data@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.1.tgz#6fb94fbd71885306d73d15cc497fe4cc4ecd44bf"
Expand All @@ -3471,6 +3459,14 @@ form-data@~0.1.0:
combined-stream "~0.0.4"
mime "~1.2.11"

form-data@~2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.2.tgz#89c3534008b97eada4cbb157d58f6f5df025eae4"
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.5"
mime-types "^2.1.12"

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/formatio/-/formatio-1.1.1.tgz#5ed3ccd636551097383465d996199100e86161e9"
Expand Down Expand Up @@ -4153,19 +4149,9 @@ icss-replace-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/icss-replace-symbols/-/icss-replace-symbols-1.0.2.tgz#cb0b6054eb3af6edc9ab1d62d01933e2d4c8bfa5"

idtoken-verifier@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/idtoken-verifier/-/idtoken-verifier-1.0.1.tgz#7563af238dfbc5aa2995744c37bf01dea3ad08ab"
dependencies:
base64-js "^1.2.0"
crypto-js "^3.1.9-1"
jsbn "^0.1.0"
superagent "^3.3.1"
url-join "^1.1.0"

idtoken-verifier@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/idtoken-verifier/-/idtoken-verifier-1.1.1.tgz#bc6eb46e6a153bb2058aed1cac2c27ac6751b5e5"
idtoken-verifier@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/idtoken-verifier/-/idtoken-verifier-1.1.2.tgz#bd5125aaccc221c1e0c57c9393dc68c0f7134b69"
dependencies:
base64-js "^1.2.0"
crypto-js "^3.1.9-1"
Expand Down Expand Up @@ -6799,7 +6785,7 @@ [email protected]:
version "2.4.2"
resolved "https://registry.yarnpkg.com/qs/-/qs-2.4.2.tgz#f7ce788e5777df0b5010da7f7c4e73ba32470f5a"

[email protected], qs@^6.1.0, qs@^6.4.0, qs@~6.4.0:
[email protected], qs@^6.4.0, qs@~6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233"

Expand Down Expand Up @@ -7948,21 +7934,6 @@ [email protected]:
qs "0.6.5"
reduce-component "1.0.1"

superagent@^3.3.1:
version "3.5.0"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.5.0.tgz#56872b8e1ee6de994035ada2e53266899af95a6d"
dependencies:
component-emitter "^1.2.0"
cookiejar "^2.0.6"
debug "^2.2.0"
extend "^3.0.0"
form-data "^2.1.1"
formidable "^1.1.1"
methods "^1.1.1"
mime "^1.3.4"
qs "^6.1.0"
readable-stream "^2.0.5"

superagent@^3.8.2:
version "3.8.2"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-3.8.2.tgz#e4a11b9d047f7d3efeb3bbe536d9ec0021d16403"
Expand Down