Skip to content

Commit b40b1ab

Browse files
committedOct 18, 2023
adding comments
1 parent ac9a82f commit b40b1ab

File tree

4 files changed

+112
-40
lines changed

4 files changed

+112
-40
lines changed
 

‎etc/firebase-admin.auth.api.md

+3-18
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/auth-api-request.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -2071,51 +2071,51 @@ const CREATE_TENANT = new ApiSettings('/tenants', 'POST')
20712071
}
20722072
});
20732073

2074-
/** Instantiates the getPasskeyConfig endpoint settings. */
2074+
/** Instantiates the GET_PASSKEY_CONFIG endpoint settings. */
20752075
const GET_PASSKEY_CONFIG = new ApiSettings('/passkeyConfig', 'GET')
20762076
.setResponseValidator((response: any) => {
2077-
// Response should always contain at least the config name.
2077+
// Validate the response for GET_PASSKEY_CONFIG.
20782078
if (!validator.isNonEmptyString(response.name)) {
20792079
throw new FirebaseAuthError(
20802080
AuthClientErrorCode.INTERNAL_ERROR,
2081-
'INTERNAL ASSERT FAILED: Unable to get project config',
2081+
'INTERNAL ASSERT FAILED: Unable to get passkey config',
20822082
);
20832083
}
20842084
});
20852085

2086-
/** Instantiates the getPasskeyConfig endpoint settings. */
2086+
/** Instantiates the GET_TENANT_PASSKEY_CONFIG endpoint settings. */
20872087
const GET_TENANT_PASSKEY_CONFIG = new ApiSettings('/tenants/{tenantId}/passkeyConfig', 'GET')
20882088
.setResponseValidator((response: any) => {
2089-
// Response should always contain at least the config name.
2089+
// Validate the response for GET_TENANT_PASSKEY_CONFIG.
20902090
if (!validator.isNonEmptyString(response.name)) {
20912091
throw new FirebaseAuthError(
20922092
AuthClientErrorCode.INTERNAL_ERROR,
2093-
'INTERNAL ASSERT FAILED: Unable to get project config',
2093+
'INTERNAL ASSERT FAILED: Unable to get tenant passkey config',
20942094
);
20952095
}
20962096
});
20972097

2098-
/** Instantiates the getPasskeyConfig endpoint settings. */
2098+
/** Instantiates the UPDATE_PASSKEY_CONFIG endpoint settings. */
20992099
const UPDATE_PASSKEY_CONFIG = new ApiSettings('/passkeyConfig?updateMask={updateMask}', 'PATCH')
21002100
.setResponseValidator((response: any) => {
2101-
// Response should always contain at least the config name.
2101+
// Validate the response for UPDATE_PASSKEY_CONFIG.
21022102
if (!validator.isNonEmptyString(response.name)) {
21032103
throw new FirebaseAuthError(
21042104
AuthClientErrorCode.INTERNAL_ERROR,
2105-
'INTERNAL ASSERT FAILED: Unable to get project config',
2105+
'INTERNAL ASSERT FAILED: Unable to update passkey config',
21062106
);
21072107
}
21082108
});
21092109

2110-
/** Instantiates the getPasskeyConfig endpoint settings. */
2110+
/** Instantiates the UPDATE_TENANT_PASSKEY_CONFIG endpoint settings. */
21112111
const UPDATE_TENANT_PASSKEY_CONFIG = new ApiSettings(
21122112
'/tenant/{tenantId}/passkeyConfig?updateMask={updateMask}', 'PATCH')
21132113
.setResponseValidator((response: any) => {
2114-
// Response should always contain at least the config name.
2114+
// Validate the response for UPDATE_TENANT_PASSKEY_CONFIG.
21152115
if (!validator.isNonEmptyString(response.name)) {
21162116
throw new FirebaseAuthError(
21172117
AuthClientErrorCode.INTERNAL_ERROR,
2118-
'INTERNAL ASSERT FAILED: Unable to get project config',
2118+
'INTERNAL ASSERT FAILED: Unable to update tenant passkey config',
21192119
);
21202120
}
21212121
});

‎src/auth/passkey-config-manager.ts

+32-1
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

+65-9
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)
Please sign in to comment.