Skip to content

Commit

Permalink
feat(Fragment Param): added fragment parameter to redirect options
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Hackett committed Oct 30, 2019
1 parent da5ea40 commit d02f378
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
11 changes: 11 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,17 @@ describe('Auth0', () => {
`https://test.auth0.com/authorize?query=params${TEST_TELEMETRY_QUERY_STRING}`
);
});
it('calls `window.location.assign` with the correct url and fragment if provided', async () => {
const { auth0 } = await setup();

await auth0.loginWithRedirect({
...REDIRECT_OPTIONS,
fragment: '/reset'
});
expect(window.location.assign).toHaveBeenCalledWith(
`https://test.auth0.com/authorize?query=params${TEST_TELEMETRY_QUERY_STRING}#/reset`
);
});
it('can be called with no arguments', async () => {
const { auth0 } = await setup();

Expand Down
3 changes: 2 additions & 1 deletion src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export default class Auth0Client {
const code_verifier = createRandomString();
const code_challengeBuffer = await sha256(code_verifier);
const code_challenge = bufferToBase64UrlEncoded(code_challengeBuffer);
const fragment = options.fragment ? `#${options.fragment}` : '';
const params = this._getParams(
authorizeOptions,
stateIn,
Expand All @@ -243,7 +244,7 @@ export default class Auth0Client {
scope: params.scope,
audience: params.audience || 'default'
});
return url;
window.location.assign(url + fragment);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ interface Auth0ClientOptions extends BaseLoginOptions {
redirect_uri?: string;
/**
* The value in seconds used to account for clock skew in JWT expirations.
* Typically, this value is no more than a minute or two at maximum.
* Typically, this value is no more than a minute or two at maximum.
* Defaults to 60s.
*/
leeway?: number;
Expand Down Expand Up @@ -118,6 +118,10 @@ interface LoginUrlOptions extends BaseLoginOptions {
* Used to store state before doing the redirect
*/
appState?: any;
/**
* Used to add to the URL fragment before redirecting
*/
fragment?: string;
}

interface RedirectLoginResult {
Expand Down

0 comments on commit d02f378

Please sign in to comment.