-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add-optional-query-params-to-start #7
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@forgerock/davinci-client': minor | ||
| --- | ||
|
|
||
| adds the ability to call start with query parameters which are appended to the /authorize call |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import './style.css'; | |
|
|
||
| import { Config, FRUser, TokenManager } from '@forgerock/javascript-sdk'; | ||
| import { davinci } from '@forgerock/davinci-client'; | ||
| import type { DaVinciConfig } from '@forgerock/davinci-client/types'; | ||
|
|
||
| import usernameComponent from './components/text.js'; | ||
| import passwordComponent from './components/password.js'; | ||
|
|
@@ -10,9 +11,9 @@ import protect from './components/protect.js'; | |
| import flowLinkComponent from './components/flow-link.js'; | ||
| import socialLoginButtonComponent from './components/social-login-button.js'; | ||
|
|
||
| const config = { | ||
| const config: DaVinciConfig = { | ||
| clientId: '724ec718-c41c-4d51-98b0-84a583f450f9', | ||
| redirectUri: window.location.href, | ||
| redirectUri: window.location.origin + '/', | ||
| scope: 'openid profile email name revoke', | ||
| serverConfig: { | ||
| wellknown: | ||
|
|
@@ -178,7 +179,21 @@ const config = { | |
| console.log('Event emitted from store:', node); | ||
| }); | ||
|
|
||
| const node = await davinciClient.start(); | ||
| const qs = window.location.search; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic so that we can pull query params dynamically in tests |
||
| const searchParams = new URLSearchParams(qs); | ||
|
|
||
| const query: Record<string, string | string[]> = {}; | ||
|
|
||
| // Get all unique keys from the searchParams | ||
| const uniqueKeys = new Set(searchParams.keys()); | ||
|
|
||
| // Iterate over the unique keys | ||
| for (const key of uniqueKeys) { | ||
| const values = searchParams.getAll(key); | ||
| query[key] = values.length > 1 ? values : values[0]; | ||
| } | ||
| console.log('query', query); | ||
| const node = await davinciClient.start({ query }); | ||
|
|
||
| formEl.addEventListener('submit', async (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "moduleResolution": "NodeNext", | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this was me debugging but should be a noop since this affects test files. |
||
| "composite": true, | ||
| "outDir": "../../dist/out-tsc", | ||
| "types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,3 +26,45 @@ test('Test happy paths on test page', async ({ page }) => { | |
| const accessToken = await page.locator('#accessTokenValue').innerText(); | ||
| await expect(accessToken).toBeTruthy(); | ||
| }); | ||
| test('ensure query params passed to start are sent off in authorize call', async ({ page }) => { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. copy pasted above test, passed in a query param and then also added a few other query params from authorize specifically to make sure thats what we are testing |
||
| const { navigate } = asyncEvents(page); | ||
| // Wait for the request to a URL containing '/authorize' | ||
| const requestPromise = page.waitForRequest((request) => { | ||
| return request | ||
| .url() | ||
| .includes('https://auth.pingone.ca/02fb4743-189a-4bc7-9d6c-a919edfe6447/as/authorize'); | ||
| }); | ||
| await navigate('/?testParam=123'); | ||
|
|
||
| // Wait for the request to be made to authorize | ||
| const request = await requestPromise; | ||
|
|
||
| // Extract and verify the query parameters from authorize | ||
| const url = new URL(request.url()); | ||
| const queryParams = Object.fromEntries(url.searchParams.entries()); | ||
|
|
||
| expect(queryParams['testParam']).toBe('123'); | ||
| expect(queryParams['client_id']).toBe('724ec718-c41c-4d51-98b0-84a583f450f9'); | ||
| expect(queryParams['response_mode']).toBe('pi.flow'); | ||
|
|
||
| expect(page.url()).toBe('http://localhost:5829/?testParam=123'); | ||
|
|
||
| await expect(page.getByText('Username/Password Form')).toBeVisible(); | ||
|
|
||
| await page.getByLabel('Username').fill('demouser'); | ||
| await page.getByLabel('Password').fill('U.CDmhGLK*nrQPDWEN47ZMyJh'); | ||
|
|
||
| await page.getByText('Sign On').click(); | ||
|
|
||
| await expect(page.getByText('Complete')).toBeVisible(); | ||
|
|
||
| const sessionToken = await page.locator('#sessionToken').innerText(); | ||
| const authCode = await page.locator('#authCode').innerText(); | ||
| expect(sessionToken).toBeTruthy(); | ||
| expect(authCode).toBeTruthy(); | ||
|
|
||
| await page.getByText('Get Tokens').click(); | ||
|
|
||
| const accessToken = await page.locator('#accessTokenValue').innerText(); | ||
| expect(accessToken).toBeTruthy(); | ||
| }); | ||
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.
because i added query params to the testing, i just appended the '/' since it's stripped when using
origin.