-
Notifications
You must be signed in to change notification settings - Fork 47
feat(javascript-sdk): ping one signout, flag for iframe skip, remove session call #535
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a5daf4c
feat(javascript-sdk): ping one signout, flag for iframe skip, remove …
cerebrl 2530651
chore(javascript-sdk): improve skip flag logic, improve e2e tests
cerebrl c6bf301
chore: remove-sessions-test-request
ryanbas21 bac2177
chore(javascript-sdk): improve skip flag logic, improve e2e tests
cerebrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@forgerock/javascript-sdk': minor | ||
| --- | ||
|
|
||
| Add new PingOne signoff, remove unneeded /session call, add flag for iframe |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
e2e/autoscript-apps/src/authn-central-login-no-iframe/autoscript.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * @forgerock/javascript-sdk | ||
| * | ||
| * autoscript.ts | ||
| * | ||
| * Copyright (c) 2020 ForgeRock. All rights reserved. | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
| // @ts-nocheck | ||
| import * as forgerock from '@forgerock/javascript-sdk'; | ||
| import { delay as rxDelay, map, mergeMap } from 'rxjs/operators'; | ||
| import { from } from 'rxjs'; | ||
|
|
||
| function autoscript() { | ||
| const delay = 0; | ||
|
|
||
| const url = new URL(window.location.href); | ||
| const amUrl = url.searchParams.get('amUrl') || 'http://localhost:9443/am'; | ||
| const preAuthenticated = url.searchParams.get('preAuthenticated') || 'false'; | ||
| const code = url.searchParams.get('code') || ''; | ||
| const clientId = url.searchParams.get('clientId'); | ||
| const client_id = url.searchParams.get('client_id'); | ||
| const error = url.searchParams.get('error_description') || false; | ||
| const realmPath = url.searchParams.get('realmPath') || 'root'; | ||
| const scope = url.searchParams.get('scope') || 'openid profile me.read'; | ||
| const state = url.searchParams.get('state') || ''; | ||
| const acr_values = url.searchParams.get('acr') || 'skipBackgroundRequest'; | ||
| // in central login we use an auth query param for the return of our mock 401 request | ||
| // this is to prevent the evaluation of the page before we have technically authenticated | ||
| const auth = url.searchParams.get('auth') || false; | ||
|
|
||
| let tokenStore = url.searchParams.get('tokenStore') || 'localStorage'; | ||
|
|
||
| // Support full redirects by setting storage, rather than rely purely on URL | ||
| if (!localStorage.getItem('tokenStore')) { | ||
| localStorage.setItem('tokenStore', tokenStore); | ||
| } else { | ||
| tokenStore = localStorage.getItem('tokenStore'); | ||
| } | ||
|
|
||
| console.log('Configure the SDK'); | ||
| forgerock.Config.set({ | ||
| clientId: clientId || client_id || 'CentralLoginOAuthClient', | ||
| realmPath, | ||
| redirectUri: `${url.origin}/src/${ | ||
| preAuthenticated === 'false' ? 'authn-central-login' : '_callback' | ||
| }/`, | ||
| scope, | ||
| serverConfig: { | ||
| baseUrl: amUrl, | ||
| }, | ||
| tokenStore, | ||
| }); | ||
|
|
||
| if (!code && !state) { | ||
| try { | ||
| forgerock.SessionManager.logout(); | ||
| } catch (err) { | ||
| // Do nothing | ||
| } | ||
| } | ||
|
|
||
| console.log('Initiate first step with `undefined`'); | ||
|
|
||
| // Wrapping in setTimeout to give the test time to bind listener to console.log | ||
| setTimeout(() => { | ||
| from([1]) | ||
| .pipe( | ||
| map(() => { | ||
| if (preAuthenticated === 'true') { | ||
| console.log('Set mock cookie to represent existing session'); | ||
| document.cookie = 'iPlanetDirectoryPro=abcd1234; domain=localhost; path=/'; | ||
| if (code && state) { | ||
| window.sessionStorage.setItem( | ||
| `FR-SDK-${clientId}`, | ||
| JSON.stringify({ responseType: 'code', state, verifier: '1234' }), | ||
| ); | ||
| } | ||
| } | ||
| return; | ||
| }), | ||
| rxDelay(delay), | ||
| mergeMap((step) => { | ||
| let tokens; | ||
| // detect when in iframe, throw as error if so | ||
| if (window.self !== window.top) { | ||
| throw new Error('Loaded_In_Iframe'); | ||
| } else if (code && state) { | ||
| tokens = forgerock.TokenManager.getTokens({ | ||
| query: { code, state, acr_values }, | ||
| }); | ||
| } else { | ||
| tokens = forgerock.TokenManager.getTokens({ | ||
| skipBackgroundRequest: true, | ||
| login: 'redirect', | ||
| query: { acr_values }, | ||
| }); | ||
| } | ||
| return tokens; | ||
| }), | ||
| map((tokens) => { | ||
| if (tokens.accessToken) { | ||
| console.log('OAuth authorization successful'); | ||
| document.body.innerHTML = '<p class="Logged_In">Login successful</p>'; | ||
| } else { | ||
| throw new Error('Session_Error'); | ||
| } | ||
| }), | ||
| rxDelay(delay), | ||
| mergeMap(() => { | ||
| console.log('Remove cookie'); | ||
| document.cookie = ''; | ||
| console.log('Initiate logout'); | ||
| return forgerock.FRUser.logout(); | ||
| }), | ||
| ) | ||
| .subscribe({ | ||
| error: (err) => { | ||
| /* | ||
| * We added this because Playwright was too fast for the dom element. | ||
| * When we make a request to central login we have to force a 401 page to mimick the real life scenario of the page being requested | ||
| * If we do this, we append a query param of auth to make sure we don't complete the flow until we are redirected from that page | ||
| * By saying we have !auth query param value, we are essentially mimicking the idea that we are waiting for the central login redirect | ||
| * to complete the redirect. | ||
| */ | ||
| if (!auth) { | ||
| return; | ||
| } | ||
| console.log(`Error: ${err.message}`); | ||
| document.body.innerHTML = `<p class="Test_Complete">${err.message}</p>`; | ||
| localStorage.clear(); | ||
| }, | ||
| complete: () => { | ||
| console.log('Test script complete'); | ||
| document.body.innerHTML = `<p class="Test_Complete">Test script complete</p>`; | ||
| history.replaceState(null, null, window.location.origin + window.location.pathname); | ||
| localStorage.clear(); | ||
| }, | ||
| }); | ||
| }, 250); | ||
| } | ||
|
|
||
| autoscript(); | ||
| export default autoscript; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm concerned with this naming, i just fear another
modern|legacysituation where people will read this name and say yeah we want to skip this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned on Slack. I think this is okay, and unintentially using this option won't do any harm. I've added more information in the JSDoc to cover this option's intention.