-
Notifications
You must be signed in to change notification settings - Fork 3
SDKS-4377: Implement FIDO module in DaVinci client #468
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
Open
ancheetah
wants to merge
1
commit into
main
Choose a base branch
from
SDKS-4377-dv-mfa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
Some comments aren't visible on the classic Files Changed page.
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,6 @@ | ||
| --- | ||
| '@forgerock/davinci-client': minor | ||
| '@forgerock/sdk-types': minor | ||
| --- | ||
|
|
||
| Adds FIDO feature module to `@forgerock/davinci-client` package |
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
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 |
|---|---|---|
|
|
@@ -5,6 +5,8 @@ | |
| * of the MIT license. See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import type { FidoAuthenticationOptions, FidoRegistrationOptions } from './davinci.types.js'; | ||
|
|
||
| /** ********************************************************************* | ||
| * SINGLE-VALUE COLLECTORS | ||
| */ | ||
|
|
@@ -302,14 +304,6 @@ export interface PhoneNumberOutputValue { | |
| phoneNumber?: string; | ||
| } | ||
|
|
||
| export interface FidoRegistrationInputValue { | ||
| attestationValue?: PublicKeyCredential; | ||
| } | ||
|
|
||
| export interface FidoAuthenticationInputValue { | ||
| assertionValue?: PublicKeyCredential; | ||
| } | ||
|
|
||
| export interface ObjectOptionsCollectorWithStringValue< | ||
| T extends ObjectValueCollectorTypes, | ||
| V = string, | ||
|
|
@@ -544,6 +538,51 @@ export type UnknownCollector = { | |
| * @interface AutoCollector - Represents a collector that collects a value programmatically without user intervention. | ||
| */ | ||
|
|
||
| export interface ProtectOutputValue { | ||
| behavioralDataCollection: boolean; | ||
| universalDeviceIdentification: boolean; | ||
| } | ||
|
|
||
| export interface AttestationValue | ||
| extends Omit<PublicKeyCredential, 'rawId' | 'response' | 'getClientExtensionResults' | 'toJSON'> { | ||
| rawId: string; | ||
| response: { | ||
| // https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAttestationResponse | ||
| clientDataJSON: string; | ||
| attestationObject: string; | ||
| }; | ||
| } | ||
| export interface FidoRegistrationInputValue { | ||
| attestationValue?: AttestationValue; | ||
| } | ||
|
|
||
| export interface FidoRegistrationOutputValue { | ||
| publicKeyCredentialCreationOptions: FidoRegistrationOptions; | ||
| action: 'REGISTER'; | ||
| trigger: string; | ||
| } | ||
|
|
||
| export interface AssertionValue | ||
| extends Omit<PublicKeyCredential, 'rawId' | 'response' | 'getClientExtensionResults' | 'toJSON'> { | ||
|
Collaborator
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 suppose same question, maybe i'm not understanding something regarding this |
||
| rawId: string; | ||
| response: { | ||
| // https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorAssertionResponse | ||
| clientDataJSON: string; | ||
| authenticatorData: string; | ||
| signature: string; | ||
| userHandle: string | null; | ||
| }; | ||
| } | ||
| export interface FidoAuthenticationInputValue { | ||
| assertionValue?: AssertionValue; | ||
| } | ||
|
|
||
| export interface FidoAuthenticationOutputValue { | ||
| publicKeyCredentialRequestOptions: FidoAuthenticationOptions; | ||
| action: 'AUTHENTICATE'; | ||
| trigger: string; | ||
| } | ||
|
|
||
| export type AutoCollectorCategories = 'SingleValueAutoCollector' | 'ObjectValueAutoCollector'; | ||
| export type SingleValueAutoCollectorTypes = 'SingleValueAutoCollector' | 'ProtectCollector'; | ||
| export type ObjectValueAutoCollectorTypes = | ||
|
|
@@ -556,6 +595,7 @@ export interface AutoCollector< | |
| C extends AutoCollectorCategories, | ||
| T extends AutoCollectorTypes, | ||
| IV = string, | ||
| OV = Record<string, unknown>, | ||
| > { | ||
| category: C; | ||
| error: string | null; | ||
|
|
@@ -571,24 +611,27 @@ export interface AutoCollector< | |
| output: { | ||
| key: string; | ||
| type: string; | ||
| config: Record<string, unknown>; | ||
| config: OV; | ||
| }; | ||
| } | ||
|
|
||
| export type ProtectCollector = AutoCollector< | ||
| 'SingleValueAutoCollector', | ||
| 'ProtectCollector', | ||
| string | ||
| string, | ||
| ProtectOutputValue | ||
| >; | ||
| export type FidoRegistrationCollector = AutoCollector< | ||
| 'ObjectValueAutoCollector', | ||
| 'FidoRegistrationCollector', | ||
| FidoRegistrationInputValue | ||
| FidoRegistrationInputValue, | ||
| FidoRegistrationOutputValue | ||
| >; | ||
| export type FidoAuthenticationCollector = AutoCollector< | ||
| 'ObjectValueAutoCollector', | ||
| 'FidoAuthenticationCollector', | ||
| FidoAuthenticationInputValue | ||
| FidoAuthenticationInputValue, | ||
| FidoAuthenticationOutputValue | ||
| >; | ||
| export type SingleValueAutoCollector = AutoCollector< | ||
| 'SingleValueAutoCollector', | ||
|
|
||
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,70 @@ | ||
| # FIDO Module for DaVinci | ||
|
|
||
| ## Overview | ||
|
|
||
| The `fido` API provides an interface for registering and authenticating with the WebAuthn API and transforming data to and from DaVinci. These methods transform options from DaVinci into WebAuthn compatible options, then call `navigator.credentials.create` or `navigator.credentials.get`, and finally transform the output of the WebAuthn API into a valid payload to send back to DaVinci. | ||
|
|
||
| ## Installation and Initialization | ||
|
|
||
| The `fido` module is exported as a member of the `@forgerock/davinci-client` package and is intended to be used alongside the `davinciClient` to progress through a flow. To install the necessary dependencies, run: | ||
|
|
||
| ```bash | ||
| npm install @forgerock/davinci-client --save | ||
| ``` | ||
|
|
||
| After installing, import and initialize the clients: | ||
|
|
||
| ```typescript | ||
| import { davinci, fido } from '@forgerock/davinci-client'; | ||
|
|
||
| const davinciClient = await davinci({ config }); | ||
| const fidoApi = fido(); | ||
| ``` | ||
|
|
||
| ## API methods | ||
|
|
||
| ### Registration | ||
|
|
||
| **register(options: FidoRegistrationOptions) => Promise<FidoRegistrationInputValue | GenericError>** | ||
|
|
||
| Creates a keypair and returns a public key credential formatted for DaVinci or an error | ||
|
|
||
| ### Authentication | ||
|
|
||
| **authenticate: (options: FidoAuthenticationOptions) => Promise<FidoAuthenticationInputValue | GenericError>** | ||
|
|
||
| Creates an assertion to send to DaVinci for authentication | ||
|
|
||
| ## Example Usage | ||
|
|
||
| ### Registration Example | ||
|
|
||
| ```typescript | ||
| if (collector.type === 'FidoRegistrationCollector') { | ||
| const credentialOptions = collector.output.config.publicKeyCredentialCreationOptions; | ||
| const publicKeyCredential = await fidoApi.register(credentialOptions); | ||
| if ('error' in publicKeyCredential) { | ||
| // Handle error | ||
| } else { | ||
| // Update the FidoRegistrationCollector with the credential | ||
| const updater = davinciClient.update(collector); | ||
| updater(publicKeyCredential); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Authentication Example | ||
|
|
||
| ```typescript | ||
| if (collector.type === 'FidoAuthenticationCollector') { | ||
| const credentialOptions = collector.output.config.publicKeyCredentialRequestOptions; | ||
| const assertion = await fidoApi.authenticate(credentialOptions); | ||
| if ('error' in assertion) { | ||
| // Handle error | ||
| } else { | ||
| // Update the FidoAuthenticationCollector with the credential | ||
| const updater = davinciClient.update(collector); | ||
| updater(assertion); | ||
| } | ||
| } | ||
| ``` |
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.
So are we omitting them because we want a complete override below? it seems odd to omit them but then redefine many of the same fields?
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.
Honestly, I wasn't sure what the best way was to do this. This was the only way I could get the properties to override. Open to other suggestions.