@@ -17,50 +17,87 @@ import * as validator from '../utils/validator';
1717import { AuthClientErrorCode , FirebaseAuthError } from '../utils/error' ;
1818import { deepCopy } from '../utils/deep-copy' ;
1919
20+ /**
21+ * Interface representing the properties to update in the provided passkey config.
22+ */
2023export interface PasskeyConfigRequest {
24+ /**
25+ * An array of website or app origins associated with the customer's sites or apps.
26+ * Only challenges signed from these origins will be allowed for signing in with passkeys.
27+ */
2128 expectedOrigins ?: string [ ] ;
2229}
2330
31+ /**
32+ * Response received from the server when retrieving, creating, or updating the passkey config.
33+ */
2434export interface PasskeyConfigServerResponse {
2535 name ?: string ;
2636 rpId ?: string ;
2737 expectedOrigins ?: string [ ] ;
2838}
2939
40+ /**
41+ * Request for creating or updating the passkey config on the server.
42+ */
3043export interface PasskeyConfigClientRequest {
3144 rpId ?: string ;
3245 expectedOrigins ?: string [ ] ;
3346}
3447
35-
48+ /**
49+ * Configuration for signing in users using passkeys.
50+ */
3651export class PasskeyConfig {
52+ /**
53+ * The name of the PasskeyConfig resource.
54+ */
3755 public readonly name ?: string ;
56+ /**
57+ * The relying party ID for passkey verifications.
58+ * This cannot be changed once created.
59+ */
3860 public readonly rpId ?: string ;
61+ /**
62+ * The website or app origins associated with the customer's sites or apps.
63+ * Only challenges signed from these origins will be allowed for signing in with passkeys.
64+ */
3965 public readonly expectedOrigins ?: string [ ] ;
4066
67+ /**
68+ * Validates a passkey config request object and throws an error on failure.
69+ * @param isCreateRequest - A boolean indicating if it's a create request or not.
70+ * @param passkeyConfigRequest - Passkey config to be set.
71+ * @param rpId - (optional) Relying party ID if it's a create request.
72+ * @throws FirebaseAuthError - If validation fails.
73+ *
74+ * @internal
75+ */
4176 private static validate ( isCreateRequest : boolean , passkeyConfigRequest ?: PasskeyConfigRequest , rpId ?: string ) : void {
77+ // Validation for creating a new PasskeyConfig.
4278 if ( isCreateRequest && ! validator . isNonEmptyString ( rpId ) ) {
4379 throw new FirebaseAuthError (
4480 AuthClientErrorCode . INVALID_ARGUMENT ,
45- '\' rpId\ ' must be a valid non-empty string\'' ,
81+ "' rpId' must be a valid non-empty string." ,
4682 ) ;
4783 }
84+ // Validation for updating an existing PasskeyConfig.
4885 if ( ! isCreateRequest && typeof rpId !== 'undefined' ) {
4986 throw new FirebaseAuthError (
5087 AuthClientErrorCode . INVALID_ARGUMENT ,
51- '\' rpId\ ' cannot be changed once created.\'' ,
88+ "' rpId' cannot be changed once created." ,
5289 ) ;
5390 }
5491 if ( ! validator . isNonNullObject ( passkeyConfigRequest ) ) {
5592 throw new FirebaseAuthError (
5693 AuthClientErrorCode . INVALID_ARGUMENT ,
57- '\' passkeyConfigRequest\ ' must be a valid non-empty object.\'' ,
94+ "' passkeyConfigRequest' must be a valid non-empty object." ,
5895 ) ;
5996 }
6097 const validKeys = {
6198 expectedOrigins : true ,
6299 } ;
63- // Check for unsupported top level attributes.
100+ // Check for unsupported top- level attributes.
64101 for ( const key in passkeyConfigRequest ) {
65102 if ( ! ( key in validKeys ) ) {
66103 throw new FirebaseAuthError (
@@ -72,19 +109,29 @@ export class PasskeyConfig {
72109 if ( ! validator . isNonEmptyArray ( passkeyConfigRequest . expectedOrigins ) ) {
73110 throw new FirebaseAuthError (
74111 AuthClientErrorCode . INVALID_ARGUMENT ,
75- '\' passkeyConfigRequest.expectedOrigins\ ' must be a valid non-empty array of strings.\'' ,
112+ "' passkeyConfigRequest.expectedOrigins' must be a valid non-empty array of strings." ,
76113 ) ;
77114 }
78115 for ( const origin of passkeyConfigRequest . expectedOrigins ) {
79116 if ( ! validator . isNonEmptyString ( origin ) ) {
80117 throw new FirebaseAuthError (
81118 AuthClientErrorCode . INVALID_ARGUMENT ,
82- '\' passkeyConfigRequest.expectedOrigins\ ' must be a valid non-empty array of strings.\'' ,
119+ "' passkeyConfigRequest.expectedOrigins' must be a valid non-empty array of strings." ,
83120 ) ;
84121 }
85122 }
86123 }
87124
125+ /**
126+ * Build the corresponding server request for a Passkey Config object.
127+ * @param isCreateRequest - A boolean stating if it's a create request.
128+ * @param passkeyConfigRequest - Passkey config to be updated.
129+ * @param rpId - (optional) Relying party ID for the request if it's a create request.
130+ * @returns The equivalent server request.
131+ * @throws FirebaseAuthError - If validation fails.
132+ *
133+ * @internal
134+ */
88135 public static buildServerRequest ( isCreateRequest : boolean , passkeyConfigRequest ?: PasskeyConfigRequest ,
89136 rpId ?: string ) : PasskeyConfigClientRequest {
90137 PasskeyConfig . validate ( isCreateRequest , passkeyConfigRequest , rpId ) ;
@@ -98,6 +145,13 @@ export class PasskeyConfig {
98145 return request ;
99146 }
100147
148+ /**
149+ * The Passkey Config object constructor.
150+ * @param response - The server-side response used to initialize the Passkey Config object.
151+ * @constructor
152+ *
153+ * @internal
154+ */
101155 constructor ( response : PasskeyConfigServerResponse ) {
102156 if ( typeof response . name !== 'undefined' ) {
103157 this . name = response . name ;
@@ -110,6 +164,10 @@ export class PasskeyConfig {
110164 }
111165 }
112166
167+ /**
168+ * Returns a JSON-serializable representation of this object.
169+ * @returns A JSON-serializable representation of this object.
170+ */
113171 public toJSON ( ) : object {
114172 const json = {
115173 name : deepCopy ( this . name ) ,
@@ -127,6 +185,4 @@ export class PasskeyConfig {
127185 }
128186 return json ;
129187 }
130-
131188}
132-
0 commit comments