-
Notifications
You must be signed in to change notification settings - Fork 3
feat(davinci-client): implement phone number field support #270
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
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/davinci-client': patch | ||
| --- | ||
|
|
||
| Fixed bugs related to device auth and registration |
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/davinci-client': minor | ||
| --- | ||
|
|
||
| Implemented phone number collector to support phone number field |
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,15 @@ | ||
| /* | ||
| * Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| * | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
| import type { ReadOnlyCollector } from '@forgerock/davinci-client/types'; | ||
|
|
||
| export default function (formEl: HTMLFormElement, collector: ReadOnlyCollector) { | ||
| // create paragraph element with text of "Loading ... " | ||
| const p = document.createElement('p'); | ||
|
|
||
| p.innerText = collector.output.label; | ||
| formEl?.appendChild(p); | ||
| } |
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,90 @@ | ||
| /* | ||
| * Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| * | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
| import type { | ||
| DeviceAuthenticationCollector, | ||
| DeviceRegistrationCollector, | ||
| PhoneNumberCollector, | ||
| Updater, | ||
| } from '@forgerock/davinci-client/types'; | ||
|
|
||
| /** | ||
| * Creates a dropdown component based on the provided data and attaches it to the form | ||
| * @param {HTMLFormElement} formEl - The form element to attach the dropdown to | ||
| * @param {SingleSelectCollector} collector - Contains the dropdown options and configuration | ||
| * @param {Updater} updater - Function to call when selection changes | ||
| */ | ||
| export default function objectValueComponent( | ||
| formEl: HTMLFormElement, | ||
| collector: DeviceRegistrationCollector | DeviceAuthenticationCollector | PhoneNumberCollector, | ||
| updater: Updater, | ||
| submitForm: () => void, | ||
| ) { | ||
| if ( | ||
| collector.type === 'DeviceAuthenticationCollector' || | ||
| collector.type === 'DeviceRegistrationCollector' | ||
| ) { | ||
| // Create the label element | ||
| const paragraphEl = document.createElement('p'); | ||
| paragraphEl.textContent = collector.output.label || 'Select an option'; | ||
| paragraphEl.className = 'object-options-title'; | ||
|
|
||
| // Append elements to the form | ||
| formEl.appendChild(paragraphEl); | ||
|
|
||
| // Add all options from the data | ||
| for (const option of collector.output.options) { | ||
| const buttonEl = document.createElement('button'); | ||
| buttonEl.setAttribute('type', 'button'); | ||
|
|
||
| // Add change event listener | ||
| buttonEl.addEventListener('click', (event) => { | ||
| // Properly type the event target | ||
| const target = event.target as HTMLButtonElement; | ||
| const selectedValue = target.getAttribute('data-id'); | ||
|
|
||
| if (!selectedValue) { | ||
| console.error('No value found for the selected option'); | ||
| return; | ||
| } | ||
| updater(selectedValue); | ||
| submitForm(); | ||
| }); | ||
|
|
||
| buttonEl.setAttribute('data-id', option.value); | ||
| buttonEl.textContent = option.label; | ||
| formEl.appendChild(buttonEl); | ||
| } | ||
| } else { | ||
| const phoneLabel = document.createElement('label'); | ||
| phoneLabel.textContent = collector.output.label || 'Phone Number'; | ||
| phoneLabel.className = 'object-options-title'; | ||
| phoneLabel.setAttribute('for', 'phone-number-input'); | ||
|
|
||
| const phoneInput = document.createElement('input'); | ||
| phoneInput.setAttribute('type', 'tel'); | ||
| phoneInput.setAttribute('id', 'phone-number-input'); | ||
| phoneInput.setAttribute('name', 'phone-number-input'); | ||
| phoneInput.setAttribute('placeholder', 'Enter phone number'); | ||
|
|
||
| // Add change event listener | ||
| phoneInput.addEventListener('change', (event) => { | ||
| // Properly type the event target | ||
| const target = event.target as HTMLInputElement; | ||
| const selectedValue = target.value; | ||
|
|
||
| if (!selectedValue) { | ||
| console.error('No value found for the selected option'); | ||
| return; | ||
| } | ||
|
|
||
| updater({ phoneNumber: selectedValue, countryCode: collector.input.value.countryCode }); | ||
| }); | ||
|
|
||
| formEl.appendChild(phoneLabel); | ||
| formEl.appendChild(phoneInput); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| * | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { asyncEvents } from './utils/async-events.js'; | ||
| import { password } from './utils/demo-user.js'; | ||
|
|
||
| test('Using ACR Values, lets render an OTP form and submit the request', async ({ page }) => { | ||
| const { navigate } = asyncEvents(page); | ||
| await navigate( | ||
| '/?clientId=20dd0ed0-bb9b-4c8f-9a60-9ebeb4b348e0&acr_value=22eb75b5d31d371afe089d6e4a824f5c', | ||
| ); | ||
|
|
||
| expect(page.url()).toBe( | ||
| 'http://localhost:5829/?clientId=20dd0ed0-bb9b-4c8f-9a60-9ebeb4b348e0&acr_value=22eb75b5d31d371afe089d6e4a824f5c', | ||
| ); | ||
|
|
||
| await page.getByLabel('Email Address').fill('mfauser+' + Date.now() + '@user.com'); | ||
| await page.getByLabel('Password').fill(password); | ||
| await page.getByLabel('Placeholder').fill('12345678901'); | ||
| await page.getByRole('button', { name: 'Submit' }).click(); | ||
|
|
||
| await page.getByRole('button', { name: 'Text Message' }).click(); | ||
|
|
||
| await page.waitForEvent('requestfinished'); | ||
|
|
||
| await page.getByText('MFA - Enter Phone Number'); | ||
|
|
||
| await page.getByLabel('Country Code').selectOption('United States (1)'); | ||
| await page.getByLabel('Enter Phone Number').fill('12345678901'); | ||
|
|
||
| const request = page.waitForRequest((request) => | ||
| request.url().endsWith('/capabilities/customForm?next=true'), | ||
| ); | ||
| await page.getByRole('button', { name: 'Submit' }).click(); | ||
| const posted = await request; | ||
| const postedData = JSON.parse(posted.postData()); | ||
| const data = postedData.parameters.data; | ||
| expect(data).toEqual({ | ||
| actionKey: 'submit', | ||
| formData: { | ||
| countryCode: '1', | ||
| phoneNumber: '12345678901', | ||
| }, | ||
| }); | ||
| }); |
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,43 @@ | ||
| /* | ||
| * Copyright (c) 2025 Ping Identity Corporation. All rights reserved. | ||
| * | ||
| * This software may be modified and distributed under the terms | ||
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
| import { expect, test } from '@playwright/test'; | ||
| import { asyncEvents } from './utils/async-events.js'; | ||
|
|
||
| test('Test happy paths on test page', async ({ page }) => { | ||
| const { navigate } = asyncEvents(page); | ||
| await navigate('/?clientId=20dd0ed0-bb9b-4c8f-9a60-9ebeb4b348e0'); | ||
|
|
||
| expect(page.url()).toBe('http://localhost:5829/?clientId=20dd0ed0-bb9b-4c8f-9a60-9ebeb4b348e0'); | ||
|
|
||
| await expect(page.getByText('Create Your Profile')).toBeVisible(); | ||
|
|
||
| await page.getByLabel('Email Address').fill('test@test.com'); | ||
| await page.getByLabel('Password').fill('apassword'); | ||
| await page.getByLabel('Placeholder').fill('12345678901'); | ||
|
|
||
| const requestPromise = page.waitForRequest((request) => | ||
| request | ||
| .url() | ||
| .includes( | ||
| 'https://auth.pingone.ca/02fb4743-189a-4bc7-9d6c-a919edfe6447/davinci/connections/8209285e0d2f3fc76bfd23fd10d45e6f/capabilities/customForm?next=true', | ||
| ), | ||
| ); | ||
|
|
||
| await page.getByRole('button', { name: 'Submit' }).click(); | ||
|
|
||
| const request = await requestPromise; | ||
| const postedData = JSON.parse(request.postData()); | ||
| const data = postedData.parameters.data; | ||
| expect(data).toEqual({ | ||
| actionKey: 'submit', | ||
| formData: { | ||
| 'user.email': 'test@test.com', | ||
| 'user.password': 'apassword', | ||
| 'phone-field': { phoneNumber: '12345678901', countryCode: 'CA' }, | ||
| }, | ||
| }); | ||
| }); |
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 know this doesn't have to be separated so we can remove this and add the if condition above but i just separated it for reading