Skip to content

Commit 54f318d

Browse files
committed
adding comments
1 parent 23d0349 commit 54f318d

File tree

3 files changed

+100
-28
lines changed

3 files changed

+100
-28
lines changed

etc/firebase-admin.auth.api.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,38 +345,23 @@ export interface OIDCUpdateAuthProviderRequest {
345345
responseType?: OAuthResponseType;
346346
}
347347

348-
// @public (undocumented)
348+
// @public
349349
export class PasskeyConfig {
350-
// Warning: (ae-forgotten-export) The symbol "PasskeyConfigServerResponse" needs to be exported by the entry point index.d.ts
351-
constructor(response: PasskeyConfigServerResponse);
352-
// Warning: (ae-forgotten-export) The symbol "PasskeyConfigClientRequest" needs to be exported by the entry point index.d.ts
353-
//
354-
// (undocumented)
355-
static buildServerRequest(isCreateRequest: boolean, passkeyConfigRequest?: PasskeyConfigRequest, rpId?: string): PasskeyConfigClientRequest;
356-
// (undocumented)
357350
readonly expectedOrigins?: string[];
358-
// (undocumented)
359351
readonly name?: string;
360-
// (undocumented)
361352
readonly rpId?: string;
362-
// (undocumented)
363353
toJSON(): object;
364354
}
365355

366-
// @public (undocumented)
356+
// @public
367357
export class PasskeyConfigManager {
368-
constructor(app: App);
369-
// (undocumented)
370358
createPasskeyConfig(rpId: string, passkeyConfigRequest: PasskeyConfigRequest, tenantId?: string): Promise<PasskeyConfig>;
371-
// (undocumented)
372359
getPasskeyConfig(tenantId?: string): Promise<PasskeyConfig>;
373-
// (undocumented)
374360
updatePasskeyConfig(passkeyConfigRequest: PasskeyConfigRequest, tenantId?: string): Promise<PasskeyConfig>;
375361
}
376362

377-
// @public (undocumented)
363+
// @public
378364
export interface PasskeyConfigRequest {
379-
// (undocumented)
380365
expectedOrigins?: string[];
381366
}
382367

src/auth/passkey-config-manager.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,45 @@ import {
2424
PasskeyConfigServerResponse
2525
} from './passkey-config';
2626

27-
27+
/**
28+
* Manages Passkey Configuration for a Firebase app.
29+
*/
2830
export class PasskeyConfigManager {
2931
private readonly authRequestHandler: AuthRequestHandler;
3032

33+
/**
34+
* Initializes a PasskeyConfigManager instance for a specified FirebaseApp.
35+
*
36+
* @param app - The Firebase app associated with this PasskeyConfigManager instance.
37+
*
38+
* @constructor
39+
* @internal
40+
*/
3141
constructor(app: App) {
3242
this.authRequestHandler = new AuthRequestHandler(app);
3343
}
3444

45+
/**
46+
* Retrieves the Passkey Configuration.
47+
*
48+
* @param tenantId - (optional) The tenant ID if querying passkeys on a specific tenant.
49+
* @returns A promise fulfilled with the passkey configuration.
50+
*/
3551
public getPasskeyConfig(tenantId?: string): Promise<PasskeyConfig> {
3652
return this.authRequestHandler.getPasskeyConfig(tenantId)
3753
.then((response: PasskeyConfigServerResponse) => {
3854
return new PasskeyConfig(response);
3955
});
4056
}
4157

58+
/**
59+
* Creates a new passkey configuration.
60+
*
61+
* @param rpId - The relying party ID.
62+
* @param passkeyConfigRequest - Configuration details for the passkey.
63+
* @param tenantId - (optional) The tenant ID for which the passkey config is created.
64+
* @returns A promise fulfilled with the newly created passkey configuration.
65+
*/
4266
public createPasskeyConfig(rpId: string, passkeyConfigRequest: PasskeyConfigRequest,
4367
tenantId?: string): Promise<PasskeyConfig> {
4468
return this.authRequestHandler.updatePasskeyConfig(true, tenantId, passkeyConfigRequest, rpId)
@@ -47,6 +71,13 @@ export class PasskeyConfigManager {
4771
});
4872
}
4973

74+
/**
75+
* Updates an existing passkey configuration.
76+
*
77+
* @param passkeyConfigRequest - Updated configuration details for the passkey.
78+
* @param tenantId - (optional) The tenant ID for which the passkey config is updated.
79+
* @returns A promise fulfilled with the updated passkey configuration.
80+
*/
5081
public updatePasskeyConfig(passkeyConfigRequest: PasskeyConfigRequest, tenantId?: string): Promise<PasskeyConfig> {
5182
return this.authRequestHandler.updatePasskeyConfig(false, tenantId, passkeyConfigRequest)
5283
.then((response: PasskeyConfigClientRequest) => {

src/auth/passkey-config.ts

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,87 @@ import * as validator from '../utils/validator';
1717
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
1818
import { deepCopy } from '../utils/deep-copy';
1919

20+
/**
21+
* Interface representing the properties to update in the provided passkey config.
22+
*/
2023
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+
*/
2128
expectedOrigins?: string[];
2229
}
2330

31+
/**
32+
* Response received from the server when retrieving, creating, or updating the passkey config.
33+
*/
2434
export 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+
*/
3043
export interface PasskeyConfigClientRequest {
3144
rpId?: string;
3245
expectedOrigins?: string[];
3346
}
3447

35-
48+
/**
49+
* Configuration for signing in users using passkeys.
50+
*/
3651
export 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

Comments
 (0)