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

Add a new property 'fragment' to be appended to the authorize URL on redirect #249

Merged
merged 2 commits into from
Oct 31, 2019
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
11 changes: 11 additions & 0 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,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 @@ -218,6 +218,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 @@ -233,7 +234,7 @@ export default class Auth0Client {
scope: params.scope,
audience: params.audience || 'default'
});
window.location.assign(url);
window.location.assign(url + fragment);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ interface RedirectLoginOptions 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