Skip to content

Commit

Permalink
Allow redirect_uri override in loginWithRedirect (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
luisrudge authored Jul 12, 2019
1 parent 051ad6d commit 1933b00
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
25 changes: 24 additions & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,13 @@ describe('Auth0', () => {
});
it('creates correct query params when providing a default redirect_uri', async () => {
const redirect_uri = 'https://custom-redirect-uri/callback';
const { redirect_uri: _ignore, ...options } = REDIRECT_OPTIONS;
const { auth0, utils } = await setup({
redirect_uri
});

await auth0.loginWithRedirect(REDIRECT_OPTIONS);
await auth0.loginWithRedirect(options);

expect(utils.createQueryParams).toHaveBeenCalledWith({
client_id: TEST_CLIENT_ID,
scope: TEST_SCOPES,
Expand All @@ -311,6 +313,27 @@ describe('Auth0', () => {
connection: 'test-connection'
});
});
it('creates correct query params when overriding redirect_uri', async () => {
const redirect_uri = 'https://custom-redirect-uri/callback';
const { auth0, utils } = await setup({
redirect_uri
});

await auth0.loginWithRedirect(REDIRECT_OPTIONS);

expect(utils.createQueryParams).toHaveBeenCalledWith({
client_id: TEST_CLIENT_ID,
scope: TEST_SCOPES,
response_type: TEST_CODE,
response_mode: 'query',
state: TEST_ENCODED_STATE,
nonce: TEST_RANDOM_STRING,
redirect_uri: REDIRECT_OPTIONS.redirect_uri,
code_challenge: TEST_BASE64_ENCODED_STRING,
code_challenge_method: 'S256',
connection: 'test-connection'
});
});
it('creates correct query params with custom params', async () => {
const { auth0, utils } = await setup();

Expand Down
6 changes: 3 additions & 3 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class Auth0Client {
response_mode: 'query',
state,
nonce,
redirect_uri: this.options.redirect_uri || redirect_uri,
redirect_uri: redirect_uri || this.options.redirect_uri,
code_challenge,
code_challenge_method: 'S256'
};
Expand Down Expand Up @@ -111,7 +111,7 @@ export default class Auth0Client {
stateIn,
nonceIn,
code_challenge,
window.location.origin
this.options.redirect_uri || window.location.origin
);
const url = this._authorizeUrl({
...params,
Expand Down Expand Up @@ -311,7 +311,7 @@ export default class Auth0Client {
stateIn,
nonceIn,
code_challenge,
window.location.origin
this.options.redirect_uri || window.location.origin
);
const url = this._authorizeUrl({
...params,
Expand Down

0 comments on commit 1933b00

Please sign in to comment.