From 663a94876af3612c80d3f8cf778f623b68c0cfc2 Mon Sep 17 00:00:00 2001 From: Bassam Ojeil Date: Fri, 17 Jan 2020 01:06:40 -0800 Subject: [PATCH 1/4] Defines the d.ts multi-factor related comments for reference generation. Adds missing multi-factor related claims to the `DecodedIdToken` interface. --- src/auth/auth.ts | 2 + src/index.d.ts | 172 ++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 148 insertions(+), 26 deletions(-) diff --git a/src/auth/auth.ts b/src/auth/auth.ts index 032f955fdd..77d8290e03 100755 --- a/src/auth/auth.ts +++ b/src/auth/auth.ts @@ -70,6 +70,8 @@ export interface DecodedIdToken { [key: string]: any; }; sign_in_provider: string; + sign_in_second_factor?: string; + second_factor_identifier?: string; [key: string]: any; }; iat: number; diff --git a/src/index.d.ts b/src/index.d.ts index 151f787466..361659fa90 100755 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -544,6 +544,43 @@ declare namespace admin.auth { toJSON(): Object; } + /** + * Interface representing the common properties of a user enrolled second factor. + */ + interface MultiFactorInfo { + /** + * The unique identifier of the enrolled second factor. + */ + uid: string; + /** + * The optional display name for an enrolled second factor. + */ + displayName?: string; + /** + * The date the second factor was enrolled, formatted as a UTC string. + */ + enrollmentTime?: string; + /** + * The second factor type identifier. For SMS second factor, this is `"phone"`. + */ + factorId: string; + + /** + * @return A JSON-serializable representation of this object. + */ + toJSON(): Object; + } + + /** + * Interface representing a phone specific user enrolled second factor. + */ + interface PhoneMultiFactorInfo extends MultiFactorInfo { + /** + * The phone number associated with a phone second factor. + */ + phoneNumber: string; + } + /** * Interface representing a user. */ @@ -639,14 +676,20 @@ declare namespace admin.auth { */ tenantId?: string | null; + /** + * The multi-factor related properties for the current user if available. + */ multiFactor?: { - enrolledFactors: Array<{ - uid: string; - phoneNumber: string; - displayName?: string; - enrollmentTime?: string; - factorId: string; - }>; + /** + * List of enrolled second factors on the current user record. + * Currently only phone second factors are supported. + */ + enrolledFactors: PhoneMultiFactorInfo[]; + + /** + * @return A JSON-serializable representation of this multi-factor object. + */ + toJSON(): Object; }; /** @@ -655,6 +698,40 @@ declare namespace admin.auth { toJSON(): Object; } + /** + * Interface representing base properties of a user enrolled second factor + * for an `UpdateRequest`. + */ + interface UpdateMultiFactorInfoRequest { + /** + * The unique identifier of the enrolled second factor. + */ + uid?: string; + /** + * The optional display name for an enrolled second factor. + */ + displayName?: string; + /** + * The optional date the second factor was enrolled, formatted as a UTC string. + */ + enrollmentTime?: string; + /** + * The second factor type identifier. For SMS second factor, this is `"phone"`. + */ + factorId: string; + } + + /** + * Interface representing a phone specific user enrolled second factor + * for an `UpdateRequest`. + */ + interface UpdatePhoneMultiFactorInfoRequest extends UpdateMultiFactorInfoRequest { + /** + * The phone number associated with a phone second factor. + */ + phoneNumber: string; + } + /** * Interface representing the properties to update on the provided user. */ @@ -696,17 +773,45 @@ declare namespace admin.auth { */ photoURL?: string | null; + /** + * The user's updated multi-factor related properties. + */ multiFactor?: { - enrolledFactors: Array<{ - uid?: string; - phoneNumber: string; - displayName?: string; - enrollmentTime?: string; - factorId: string; - }> | null; + /** + * The user's updated list of enrolled second factors. The provided list will always + * overwrite any existing list of enrolled second factors on the user. + * When null is passed, all existing enrolled second factors on the user will be removed. + */ + enrolledFactors: UpdatePhoneMultiFactorInfoRequest[] | null; }; } + /** + * Interface representing base properties of a user enrolled second factor for a + * `CreateRequest`. + */ + interface CreateMultiFactorInfoRequest { + /** + * The optional display name for an enrolled second factor. + */ + displayName?: string; + /** + * The second factor type identifier. For SMS second factor, this is `"phone"`. + */ + factorId: string; + } + + /** + * Interface representing a phone specific user enrolled second factor for a + * `CreateRequest`. + */ + interface CreatePhoneMultiFactorInfoRequest extends CreateMultiFactorInfoRequest { + /** + * The phone number associated with a phone second factor. + */ + phoneNumber: string; + } + /** * Interface representing the properties to set on a new user record to be * created. @@ -718,12 +823,14 @@ declare namespace admin.auth { */ uid?: string; + /** + * The user's multi-factor related properties. + */ multiFactor?: { - enrolledFactors: Array<{ - phoneNumber: string; - displayName?: string; - factorId: string; - }>; + /** + * The user's list of enrolled second factors. + */ + enrolledFactors: CreatePhoneMultiFactorInfoRequest[]; }; } @@ -791,6 +898,19 @@ declare namespace admin.auth { */ sign_in_provider: string; + /** + * This is the type identifier or `factorId` of the second factor, provided the + * ID token was obtained from a multi-factor authenticated user. + * For phone, this is `“phone”`. + */ + sign_in_second_factor?: string; + + /** + * This is the `uid` of the second factor used to sign in, provided the + * ID token was obtained from a multi-factor authenticated user. + */ + second_factor_identifier?: string; + /** * The ID of the tenant the user belongs to, if available. */ @@ -1029,14 +1149,14 @@ declare namespace admin.auth { */ tenantId?: string | null; + /** + * The multi-factor related properties for the imported user if available. + */ multiFactor?: { - enrolledFactors: Array<{ - uid: string; - phoneNumber: string; - displayName?: string; - enrollmentTime?: string; - factorId: string; - }>; + /** + * List of enrolled second factors on the user to import. + */ + enrolledFactors: PhoneMultiFactorInfo[]; }; } From f09497c48ad006dc057b22decf1d7b01cd956116 Mon Sep 17 00:00:00 2001 From: Bassam Ojeil Date: Fri, 17 Jan 2020 10:52:27 -0800 Subject: [PATCH 2/4] Added new lines to newly defined types comments. --- src/index.d.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 361659fa90..a4ba374e91 100755 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -548,18 +548,22 @@ declare namespace admin.auth { * Interface representing the common properties of a user enrolled second factor. */ interface MultiFactorInfo { + /** * The unique identifier of the enrolled second factor. */ uid: string; + /** * The optional display name for an enrolled second factor. */ displayName?: string; + /** - * The date the second factor was enrolled, formatted as a UTC string. + * The optional date the second factor was enrolled, formatted as a UTC string. */ enrollmentTime?: string; + /** * The second factor type identifier. For SMS second factor, this is `"phone"`. */ @@ -575,6 +579,7 @@ declare namespace admin.auth { * Interface representing a phone specific user enrolled second factor. */ interface PhoneMultiFactorInfo extends MultiFactorInfo { + /** * The phone number associated with a phone second factor. */ @@ -680,6 +685,7 @@ declare namespace admin.auth { * The multi-factor related properties for the current user if available. */ multiFactor?: { + /** * List of enrolled second factors on the current user record. * Currently only phone second factors are supported. @@ -699,22 +705,26 @@ declare namespace admin.auth { } /** - * Interface representing base properties of a user enrolled second factor + * Interface representing common properties of a user enrolled second factor * for an `UpdateRequest`. */ interface UpdateMultiFactorInfoRequest { + /** * The unique identifier of the enrolled second factor. */ uid?: string; + /** * The optional display name for an enrolled second factor. */ displayName?: string; + /** * The optional date the second factor was enrolled, formatted as a UTC string. */ enrollmentTime?: string; + /** * The second factor type identifier. For SMS second factor, this is `"phone"`. */ @@ -726,6 +736,7 @@ declare namespace admin.auth { * for an `UpdateRequest`. */ interface UpdatePhoneMultiFactorInfoRequest extends UpdateMultiFactorInfoRequest { + /** * The phone number associated with a phone second factor. */ @@ -777,6 +788,7 @@ declare namespace admin.auth { * The user's updated multi-factor related properties. */ multiFactor?: { + /** * The user's updated list of enrolled second factors. The provided list will always * overwrite any existing list of enrolled second factors on the user. @@ -791,10 +803,12 @@ declare namespace admin.auth { * `CreateRequest`. */ interface CreateMultiFactorInfoRequest { + /** * The optional display name for an enrolled second factor. */ displayName?: string; + /** * The second factor type identifier. For SMS second factor, this is `"phone"`. */ @@ -806,6 +820,7 @@ declare namespace admin.auth { * `CreateRequest`. */ interface CreatePhoneMultiFactorInfoRequest extends CreateMultiFactorInfoRequest { + /** * The phone number associated with a phone second factor. */ @@ -827,6 +842,7 @@ declare namespace admin.auth { * The user's multi-factor related properties. */ multiFactor?: { + /** * The user's list of enrolled second factors. */ @@ -1153,6 +1169,7 @@ declare namespace admin.auth { * The multi-factor related properties for the imported user if available. */ multiFactor?: { + /** * List of enrolled second factors on the user to import. */ From bbaf1a8a64ede1992a7f6a35e16c51eea80d8056 Mon Sep 17 00:00:00 2001 From: Bassam Ojeil Date: Fri, 17 Jan 2020 13:36:20 -0800 Subject: [PATCH 3/4] Address review comments. --- src/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index a4ba374e91..8ae5a91298 100755 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -550,7 +550,7 @@ declare namespace admin.auth { interface MultiFactorInfo { /** - * The unique identifier of the enrolled second factor. + * The user's unique ID of the enrolled second factor. */ uid: string; @@ -711,7 +711,8 @@ declare namespace admin.auth { interface UpdateMultiFactorInfoRequest { /** - * The unique identifier of the enrolled second factor. + * The user's unique ID of the enrolled second factor. When not provided, + * a new one is provisioned by the Auth server. */ uid?: string; From d2ece275a376a709025ec7899bbec8b1a3fdf84c Mon Sep 17 00:00:00 2001 From: Bassam Ojeil Date: Tue, 21 Jan 2020 17:52:20 -0800 Subject: [PATCH 4/4] Addresses additional review comments. --- src/index.d.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 8ae5a91298..17aa17db0a 100755 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -550,12 +550,12 @@ declare namespace admin.auth { interface MultiFactorInfo { /** - * The user's unique ID of the enrolled second factor. + * The ID of the enrolled second factor. This ID is unique to the user. */ uid: string; /** - * The optional display name for an enrolled second factor. + * The optional display name of the enrolled second factor. */ displayName?: string; @@ -565,7 +565,7 @@ declare namespace admin.auth { enrollmentTime?: string; /** - * The second factor type identifier. For SMS second factor, this is `"phone"`. + * The type identifier of the second factor. For SMS second factors, this is `phone`. */ factorId: string; @@ -682,12 +682,12 @@ declare namespace admin.auth { tenantId?: string | null; /** - * The multi-factor related properties for the current user if available. + * The multi-factor related properties for the current user, if available. */ multiFactor?: { /** - * List of enrolled second factors on the current user record. + * List of second factors enrolled with the current user. * Currently only phone second factors are supported. */ enrolledFactors: PhoneMultiFactorInfo[]; @@ -711,7 +711,7 @@ declare namespace admin.auth { interface UpdateMultiFactorInfoRequest { /** - * The user's unique ID of the enrolled second factor. When not provided, + * The ID of the enrolled second factor. This ID is unique to the user. When not provided, * a new one is provisioned by the Auth server. */ uid?: string; @@ -727,7 +727,7 @@ declare namespace admin.auth { enrollmentTime?: string; /** - * The second factor type identifier. For SMS second factor, this is `"phone"`. + * The type identifier of the second factor. For SMS second factors, this is `phone`. */ factorId: string; } @@ -791,9 +791,9 @@ declare namespace admin.auth { multiFactor?: { /** - * The user's updated list of enrolled second factors. The provided list will always - * overwrite any existing list of enrolled second factors on the user. - * When null is passed, all existing enrolled second factors on the user will be removed. + * The updated list of enrolled second factors. The provided list overwrites the user's + * existing list of second factors. + * When null is passed, all of the user's existing second factors are removed. */ enrolledFactors: UpdatePhoneMultiFactorInfoRequest[] | null; }; @@ -811,7 +811,7 @@ declare namespace admin.auth { displayName?: string; /** - * The second factor type identifier. For SMS second factor, this is `"phone"`. + * The type identifier of the second factor. For SMS second factors, this is `phone`. */ factorId: string; } @@ -916,14 +916,14 @@ declare namespace admin.auth { sign_in_provider: string; /** - * This is the type identifier or `factorId` of the second factor, provided the + * The type identifier or `factorId` of the second factor, provided the * ID token was obtained from a multi-factor authenticated user. * For phone, this is `“phone”`. */ sign_in_second_factor?: string; /** - * This is the `uid` of the second factor used to sign in, provided the + * The `uid` of the second factor used to sign in, provided the * ID token was obtained from a multi-factor authenticated user. */ second_factor_identifier?: string;