Skip to content

Commit

Permalink
[SDK-3548] Introduce authorizationParams to hold properties sent to A…
Browse files Browse the repository at this point in the history
…uth0 (#959)
  • Loading branch information
ewanharris authored Aug 18, 2022
1 parent 380dd3f commit b0541c8
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 378 deletions.
52 changes: 36 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ import { createAuth0Client } from '@auth0/auth0-spa-js';
const auth0 = await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
clientId: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
authorizationParams: {
redirect_uri: '<MY_CALLBACK_URL>'
}
});

//with promises
createAuth0Client({
domain: '<AUTH0_DOMAIN>',
clientId: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
authorizationParams: {
redirect_uri: '<MY_CALLBACK_URL>'
}
}).then(auth0 => {
//...
});
Expand All @@ -99,7 +103,9 @@ import { Auth0Client } from '@auth0/auth0-spa-js';
const auth0 = new Auth0Client({
domain: '<AUTH0_DOMAIN>',
clientId: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
authorizationParams: {
redirect_uri: '<MY_CALLBACK_URL>'
}
});

//if you do this, you'll need to check the session yourself
Expand Down Expand Up @@ -224,9 +230,11 @@ To use the in-memory mode, no additional options need are required as this is th
```js
await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
clientId: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>',
cacheLocation: 'localstorage' // valid values are: 'memory' or 'localstorage'
clientId: '<AUTH0_CLIENT_ID>',,
cacheLocation: 'localstorage' // valid values are: 'memory' or 'localstorage',
authorizationParams: {
redirect_uri: '<MY_CALLBACK_URL>'
}
});
```

Expand Down Expand Up @@ -272,8 +280,10 @@ const sessionStorageCache = {
await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
clientId: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>',
cache: sessionStorageCache
cache: sessionStorageCache,
authorizationParams: {
redirect_uri: '<MY_CALLBACK_URL>'
}
});
```

Expand All @@ -291,8 +301,10 @@ To enable the use of refresh tokens, set the `useRefreshTokens` option to `true`
await createAuth0Client({
domain: '<AUTH0_DOMAIN>',
clientId: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>',
useRefreshTokens: true
useRefreshTokens: true,
authorizationParams: {
redirect_uri: '<MY_CALLBACK_URL>'
}
});
```

Expand Down Expand Up @@ -320,8 +332,10 @@ Log in to an organization by specifying the `organization` parameter when settin
createAuth0Client({
domain: '<AUTH0_DOMAIN>',
clientId: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>',
organization: '<MY_ORG_ID>'
authorizationParams: {
organization: '<MY_ORG_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
}
});
```

Expand All @@ -330,12 +344,16 @@ You can also specify the organization when logging in:
```js
// Using a redirect
client.loginWithRedirect({
organization: '<MY_ORG_ID>'
authorizationParams: {
organization: '<MY_ORG_ID>'
}
});

// Using a popup window
client.loginWithPopup({
organization: '<MY_ORG_ID>'
authorizationParams: {
organization: '<MY_ORG_ID>'
}
});
```

Expand All @@ -351,8 +369,10 @@ const invitation = params.get('invitation');

if (organization && invitation) {
client.loginWithRedirect({
organization,
invitation
authorizationParams: {
invitation,
organization
}
});
}
```
Expand Down
13 changes: 10 additions & 3 deletions __tests__/Auth0Client/buildLogoutUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ describe('Auth0Client', () => {
const auth0 = setup();

const url = auth0.buildLogoutUrl({
returnTo: 'https://return.to',
clientId: null
clientId: null,
logoutParams: {
returnTo: 'https://return.to'
}
});

assertUrlEquals(url, TEST_DOMAIN, '/v2/logout', {
Expand All @@ -110,7 +112,12 @@ describe('Auth0Client', () => {
it('creates correct query params when `options.federated` is true', async () => {
const auth0 = setup();

const url = auth0.buildLogoutUrl({ federated: true, clientId: null });
const url = auth0.buildLogoutUrl({
logoutParams: {
federated: true
},
clientId: null
});

assertUrlEquals(url, TEST_DOMAIN, '/v2/logout', {
federated: ''
Expand Down
15 changes: 12 additions & 3 deletions __tests__/Auth0Client/constructor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ describe('Auth0Client', () => {
it('automatically adds the offline_access scope during construction', () => {
const auth0 = setup({
useRefreshTokens: true,
scope: 'test-scope'
authorizationParams: {
scope: 'test-scope'
}
});

expect((<any>auth0).scope).toBe('test-scope offline_access');
Expand Down Expand Up @@ -197,7 +199,9 @@ describe('Auth0Client', () => {
const auth0 = setup();

const url = auth0.buildLogoutUrl({
returnTo: 'https://return.to',
logoutParams: {
returnTo: 'https://return.to'
},
clientId: null
});

Expand All @@ -209,7 +213,12 @@ describe('Auth0Client', () => {
it('creates correct query params when `options.federated` is true', async () => {
const auth0 = setup();

const url = auth0.buildLogoutUrl({ federated: true, clientId: null });
const url = auth0.buildLogoutUrl({
logoutParams: {
federated: true
},
clientId: null
});

assertUrlEquals(url, TEST_DOMAIN, '/v2/logout', {
federated: ''
Expand Down
19 changes: 13 additions & 6 deletions __tests__/Auth0Client/getIdTokenClaims.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('Auth0Client', () => {
}) => {
describe(`when ${name}`, () => {
it('returns the ID token claims', async () => {
const auth0 = setup({ scope: 'foo' });
const auth0 = setup({ authorizationParams: { scope: 'foo' } });
await login(auth0);

expect(await auth0.getIdTokenClaims()).toHaveProperty('exp');
Expand All @@ -121,12 +121,14 @@ describe('Auth0Client', () => {

it('returns the ID token claims with custom scope', async () => {
const auth0 = setup({
scope: 'scope1',
authorizationParams: {
scope: 'scope1'
},
advancedOptions: {
defaultScope: 'scope2'
}
});
await login(auth0, { scope: 'scope3' });
await login(auth0, { authorizationParams: { scope: 'scope3' } });

expect(
await auth0.getIdTokenClaims({ scope: 'scope1 scope2 scope3' })
Expand All @@ -135,7 +137,10 @@ describe('Auth0Client', () => {

describe('when using refresh tokens', () => {
it('returns the ID token claims with offline_access', async () => {
const auth0 = setup({ scope: 'foo', useRefreshTokens: true });
const auth0 = setup({
authorizationParams: { scope: 'foo' },
useRefreshTokens: true
});
await login(auth0);

expect(
Expand All @@ -145,13 +150,15 @@ describe('Auth0Client', () => {

it('returns the ID token claims with custom scope and offline_access', async () => {
const auth0 = setup({
scope: 'scope1',
authorizationParams: {
scope: 'scope1'
},
advancedOptions: {
defaultScope: 'scope2'
},
useRefreshTokens: true
});
await login(auth0, { scope: 'scope3' });
await login(auth0, { authorizationParams: { scope: 'scope3' } });

expect(
await auth0.getIdTokenClaims({
Expand Down
Loading

0 comments on commit b0541c8

Please sign in to comment.