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

Make cross origin authentication the default in OIDC mode #1124

Merged
merged 1 commit into from
Sep 27, 2017
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
14 changes: 2 additions & 12 deletions src/__tests__/core/web_api/__snapshots__/p2_api.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Auth0APIClient logIn with credentials should call client.client.login by default 1`] = `
exports[`Auth0APIClient logIn with credentials should call client.login 1`] = `
Object {
"nonce": undefined,
"realm": undefined,
Expand All @@ -10,17 +10,7 @@ Object {
}
`;

exports[`Auth0APIClient logIn with credentials when \`overrides._useCrossAuth\` is true should call client.login 1`] = `
Object {
"nonce": undefined,
"realm": undefined,
"sso": undefined,
"state": undefined,
"username": "foo",
}
`;

exports[`Auth0APIClient logIn with credentials when \`overrides._useCrossAuth\` is true should fail when in popup mode 1`] = `"Cross origin login is not supported in popup mode"`;
exports[`Auth0APIClient logIn with credentials should fail when in popup mode 1`] = `"Cross origin login is not supported in popup mode"`;

exports[`Auth0APIClient logIn with social/enterprise (without username and email) should call authorize when redirect===true 1`] = `
Object {
Expand Down
30 changes: 6 additions & 24 deletions src/__tests__/core/web_api/p2_api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,20 @@ describe('Auth0APIClient', () => {
});
});
describe('with credentials', () => {
describe('when `overrides._useCrossAuth` is true', () => {
it('should fail when in popup mode', () => {
const client = getClient({
redirect: false,
overrides: {
__useCrossAuth: true
}
});
expect(() => client.logIn({ username: 'foo' }, {})).toThrowErrorMatchingSnapshot();
});
it('should call client.login', () => {
const client = getClient({
redirect: true,
overrides: {
__useCrossAuth: true
}
});
const callback = jest.fn();
client.logIn({ username: 'foo' }, {}, callback);
const mock = getAuth0ClientMock();
const loginMock = mock.WebAuth.mock.instances[0].login.mock;
assertCallWithCallback(loginMock, callback);
it('should fail when in popup mode', () => {
const client = getClient({
redirect: false
});
expect(() => client.logIn({ username: 'foo' }, {})).toThrowErrorMatchingSnapshot();
});
it('should call client.client.login by default', () => {
it('should call client.login', () => {
const client = getClient({
redirect: true
});
const callback = jest.fn();
client.logIn({ username: 'foo' }, {}, callback);
const mock = getAuth0ClientMock();
const loginMock = mock.WebAuth.mock.instances[0].client.login.mock;
const loginMock = mock.WebAuth.mock.instances[0].login.mock;
assertCallWithCallback(loginMock, callback);
});
});
Expand Down
13 changes: 4 additions & 9 deletions src/core/web_api/p2_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Auth0APIClient {
version: __VERSION__,
lib_version: auth0.version
};
this._useCrossAuth = !!(opts.overrides && opts.overrides.__useCrossAuth);

this.client = new auth0.WebAuth({
clientID: clientID,
Expand Down Expand Up @@ -53,15 +52,11 @@ class Auth0APIClient {
this.client.authorize(loginOptions, f);
}
} else {
loginOptions.realm = options.connection;
if (this._useCrossAuth) {
if (this.authOpt.popup) {
throw new Error('Cross origin login is not supported in popup mode');
}
this.client.login(loginOptions, f);
} else {
this.client.client.login(loginOptions, f);
if (this.authOpt.popup) {
throw new Error('Cross origin login is not supported in popup mode');
}
loginOptions.realm = options.connection;
this.client.login(loginOptions, f);
}
}

Expand Down