@@ -17,50 +17,87 @@ import * as validator from '../utils/validator';
17
17
import { AuthClientErrorCode , FirebaseAuthError } from '../utils/error' ;
18
18
import { deepCopy } from '../utils/deep-copy' ;
19
19
20
+ /**
21
+ * Interface representing the properties to update in the provided passkey config.
22
+ */
20
23
export 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
+ */
21
28
expectedOrigins ?: string [ ] ;
22
29
}
23
30
31
+ /**
32
+ * Response received from the server when retrieving, creating, or updating the passkey config.
33
+ */
24
34
export interface PasskeyConfigServerResponse {
25
35
name ?: string ;
26
36
rpId ?: string ;
27
37
expectedOrigins ?: string [ ] ;
28
38
}
29
39
40
+ /**
41
+ * Request for creating or updating the passkey config on the server.
42
+ */
30
43
export interface PasskeyConfigClientRequest {
31
44
rpId ?: string ;
32
45
expectedOrigins ?: string [ ] ;
33
46
}
34
47
35
-
48
+ /**
49
+ * Configuration for signing in users using passkeys.
50
+ */
36
51
export class PasskeyConfig {
52
+ /**
53
+ * The name of the PasskeyConfig resource.
54
+ */
37
55
public readonly name ?: string ;
56
+ /**
57
+ * The relying party ID for passkey verifications.
58
+ * This cannot be changed once created.
59
+ */
38
60
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
+ */
39
65
public readonly expectedOrigins ?: string [ ] ;
40
66
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
+ */
41
76
private static validate ( isCreateRequest : boolean , passkeyConfigRequest ?: PasskeyConfigRequest , rpId ?: string ) : void {
77
+ // Validation for creating a new PasskeyConfig.
42
78
if ( isCreateRequest && ! validator . isNonEmptyString ( rpId ) ) {
43
79
throw new FirebaseAuthError (
44
80
AuthClientErrorCode . INVALID_ARGUMENT ,
45
- '\' rpId\ ' must be a valid non-empty string\'' ,
81
+ "' rpId' must be a valid non-empty string." ,
46
82
) ;
47
83
}
84
+ // Validation for updating an existing PasskeyConfig.
48
85
if ( ! isCreateRequest && typeof rpId !== 'undefined' ) {
49
86
throw new FirebaseAuthError (
50
87
AuthClientErrorCode . INVALID_ARGUMENT ,
51
- '\' rpId\ ' cannot be changed once created.\'' ,
88
+ "' rpId' cannot be changed once created." ,
52
89
) ;
53
90
}
54
91
if ( ! validator . isNonNullObject ( passkeyConfigRequest ) ) {
55
92
throw new FirebaseAuthError (
56
93
AuthClientErrorCode . INVALID_ARGUMENT ,
57
- '\' passkeyConfigRequest\ ' must be a valid non-empty object.\'' ,
94
+ "' passkeyConfigRequest' must be a valid non-empty object." ,
58
95
) ;
59
96
}
60
97
const validKeys = {
61
98
expectedOrigins : true ,
62
99
} ;
63
- // Check for unsupported top level attributes.
100
+ // Check for unsupported top- level attributes.
64
101
for ( const key in passkeyConfigRequest ) {
65
102
if ( ! ( key in validKeys ) ) {
66
103
throw new FirebaseAuthError (
@@ -72,19 +109,29 @@ export class PasskeyConfig {
72
109
if ( ! validator . isNonEmptyArray ( passkeyConfigRequest . expectedOrigins ) ) {
73
110
throw new FirebaseAuthError (
74
111
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." ,
76
113
) ;
77
114
}
78
115
for ( const origin of passkeyConfigRequest . expectedOrigins ) {
79
116
if ( ! validator . isNonEmptyString ( origin ) ) {
80
117
throw new FirebaseAuthError (
81
118
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." ,
83
120
) ;
84
121
}
85
122
}
86
123
}
87
124
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
+ */
88
135
public static buildServerRequest ( isCreateRequest : boolean , passkeyConfigRequest ?: PasskeyConfigRequest ,
89
136
rpId ?: string ) : PasskeyConfigClientRequest {
90
137
PasskeyConfig . validate ( isCreateRequest , passkeyConfigRequest , rpId ) ;
@@ -98,6 +145,13 @@ export class PasskeyConfig {
98
145
return request ;
99
146
}
100
147
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
+ */
101
155
constructor ( response : PasskeyConfigServerResponse ) {
102
156
if ( typeof response . name !== 'undefined' ) {
103
157
this . name = response . name ;
@@ -110,6 +164,10 @@ export class PasskeyConfig {
110
164
}
111
165
}
112
166
167
+ /**
168
+ * Returns a JSON-serializable representation of this object.
169
+ * @returns A JSON-serializable representation of this object.
170
+ */
113
171
public toJSON ( ) : object {
114
172
const json = {
115
173
name : deepCopy ( this . name ) ,
@@ -127,6 +185,4 @@ export class PasskeyConfig {
127
185
}
128
186
return json ;
129
187
}
130
-
131
188
}
132
-
0 commit comments