From 81241ae9acb35683f289ee212b0720ae91abfd9a Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Thu, 2 Apr 2020 13:12:03 -0700 Subject: [PATCH 1/4] fix(auth): Fixing UserImportRecord typings declaration --- docgen/content-sources/node/toc.yaml | 4 ++ src/auth.d.ts | 66 ++++++++++++++++++++++++++-- test/integration/auth.spec.ts | 40 +++++++++-------- 3 files changed, 88 insertions(+), 22 deletions(-) diff --git a/docgen/content-sources/node/toc.yaml b/docgen/content-sources/node/toc.yaml index 4466e2559f..bba7cf4f64 100644 --- a/docgen/content-sources/node/toc.yaml +++ b/docgen/content-sources/node/toc.yaml @@ -86,6 +86,10 @@ toc: path: /docs/reference/admin/node/admin.auth.UserInfo - title: "UserMetadata" path: /docs/reference/admin/node/admin.auth.UserMetadata + - title: "UserMetadataRequest" + path: /docs/reference/admin/node/admin.auth.UserMetadataRequest + - title: "UserProviderRequest" + path: /docs/reference/admin/node/admin.auth.UserProviderRequest - title: "UserRecord" path: /docs/reference/admin/node/admin.auth.UserRecord - title: "SessionCookieOptions" diff --git a/src/auth.d.ts b/src/auth.d.ts index eedb08786b..5a1b81ce7a 100644 --- a/src/auth.d.ts +++ b/src/auth.d.ts @@ -624,6 +624,59 @@ export namespace admin.auth { errors: _admin.FirebaseArrayIndexError[]; } + /** + * User metadata to include when importing a user. + */ + interface UserMetadataRequest { + + /** + * The date the user last signed in, formatted as a UTC string. + */ + lastSignInTime?: string; + + /** + * The date the user was created, formatted as a UTC string. + * + */ + creationTime?: string; + } + + /** + * User provider data to include when importing a user. + */ + interface UserProviderRequest { + + /** + * The user identifier for the linked provider. + */ + uid: string; + + /** + * The display name for the linked provider. + */ + displayName?: string; + + /** + * The email for the linked provider. + */ + email?: string; + + /** + * The phone number for the linked provider. + */ + phoneNumber?: string; + + /** + * The photo URL for the linked provider. + */ + photoURL?: string; + + /** + * The linked provider ID (for example, "google.com" for the Google provider). + */ + providerId: string; + } + /** * Interface representing a user to import to Firebase Auth via the * {@link https://firebase.google.com/docs/reference/admin/node/admin.auth.Auth#importUsers `importUsers()`} method. @@ -643,7 +696,7 @@ export namespace admin.auth { /** * Whether or not the user's primary email is verified. */ - emailVerified: boolean; + emailVerified?: boolean; /** * The user's display name. @@ -664,17 +717,17 @@ export namespace admin.auth { * Whether or not the user is disabled: `true` for disabled; `false` for * enabled. */ - disabled: boolean; + disabled?: boolean; /** * Additional metadata about the user. */ - metadata: admin.auth.UserMetadata; + metadata?: admin.auth.UserMetadataRequest; /** * An array of providers (for example, Google, Facebook) linked to the user. */ - providerData?: admin.auth.UserInfo[]; + providerData?: admin.auth.UserProviderRequest[]; /** * The user's custom claims object if available, typically used to define @@ -703,6 +756,11 @@ export namespace admin.auth { * to the tenant corresponding to that `TenantAwareAuth` instance's tenant ID. */ tenantId?: string | null; + + /** + * The user's multi-factor related properties. + */ + multiFactor?: admin.auth.MultiFactorUpdateSettings; } /** diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index 209b24ec14..68d61c6389 100755 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1421,7 +1421,7 @@ describe('admin.auth', () => { describe('importUsers()', () => { const randomUid = 'import_' + generateRandomString(20).toLowerCase(); - let importUserRecord: any; + let importUserRecord: admin.auth.UserImportRecord; const rawPassword = 'password'; const rawSalt = 'NaCl'; // Simulate a user stored using SCRYPT being migrated to Firebase Auth via importUsers. @@ -1652,6 +1652,23 @@ describe('admin.auth', () => { const uid = generateRandomString(20).toLowerCase(); const email = uid + '@example.com'; const now = new Date(1476235905000).toUTCString(); + const enrolledFactors: admin.auth.UpdatePhoneMultiFactorInfoRequest[] = [ + { + uid: 'mfaUid1', + phoneNumber: '+16505550001', + displayName: 'Work phone number', + factorId: 'phone', + enrollmentTime: now, + } , + { + uid: 'mfaUid2', + phoneNumber: '+16505550002', + displayName: 'Personal phone number', + factorId: 'phone', + enrollmentTime: now, + }, + ]; + importUserRecord = { uid, email, @@ -1671,22 +1688,7 @@ describe('admin.auth', () => { }, ], multiFactor: { - enrolledFactors: [ - { - uid: 'mfaUid1', - phoneNumber: '+16505550001', - displayName: 'Work phone number', - factorId: 'phone', - enrollmentTime: now, - }, - { - uid: 'mfaUid2', - phoneNumber: '+16505550002', - displayName: 'Personal phone number', - factorId: 'phone', - enrollmentTime: now, - }, - ], + enrolledFactors, }, }; uids.push(importUserRecord.uid); @@ -1741,7 +1743,9 @@ describe('admin.auth', () => { * @retunr {Promise} A promise that resolved on success. */ function testImportAndSignInUser( - importUserRecord: any, importOptions: any, rawPassword: string): Promise { + importUserRecord: admin.auth.UserImportRecord, + importOptions: any, + rawPassword: string): Promise { const users = [importUserRecord]; // Import the user record. return admin.auth().importUsers(users, importOptions) From ed3ea00fd5181fb41a2195e2db9488e6e981a32a Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Thu, 2 Apr 2020 13:33:00 -0700 Subject: [PATCH 2/4] Fixing more integration test compilation errors --- test/integration/auth.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index 68d61c6389..19f33b1d05 100755 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1635,15 +1635,15 @@ describe('admin.auth', () => { return admin.auth().getUser(uid); }).then((userRecord) => { // The phone number provider will be appended to the list of accounts. - importUserRecord.providerData.push({ - uid: importUserRecord.phoneNumber, + importUserRecord.providerData?.push({ + uid: importUserRecord.phoneNumber!, providerId: 'phone', - phoneNumber: importUserRecord.phoneNumber, + phoneNumber: importUserRecord.phoneNumber!, }); const actualUserRecord: {[key: string]: any} = userRecord.toJSON(); for (const key of Object.keys(importUserRecord)) { expect(JSON.stringify(actualUserRecord[key])) - .to.be.equal(JSON.stringify(importUserRecord[key])); + .to.be.equal(JSON.stringify((importUserRecord as any)[key])); } }).should.eventually.be.fulfilled; }); @@ -1704,7 +1704,7 @@ describe('admin.auth', () => { const actualUserRecord: {[key: string]: any} = userRecord.toJSON(); expect(actualUserRecord.multiFactor.enrolledFactors.length).to.equal(2); expect(actualUserRecord.multiFactor.enrolledFactors) - .to.deep.equal(importUserRecord.multiFactor.enrolledFactors); + .to.deep.equal(importUserRecord.multiFactor?.enrolledFactors); }).should.eventually.be.fulfilled; }); @@ -1755,7 +1755,7 @@ function testImportAndSignInUser( expect(result.successCount).to.equal(1); expect(result.errors.length).to.equal(0); // Sign in with an email and password to the imported account. - return clientAuth().signInWithEmailAndPassword(users[0].email, rawPassword); + return clientAuth().signInWithEmailAndPassword(users[0].email!, rawPassword); }) .then(({user}) => { // Confirm successful sign-in. From 7f3a0a68a32019f6fa2ef6b94fc45bbc3bf3d452 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Thu, 2 Apr 2020 15:05:56 -0700 Subject: [PATCH 3/4] Trigger CI From 845038bf10994a4a736d33128b924a8514cbff83 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Fri, 3 Apr 2020 11:15:52 -0700 Subject: [PATCH 4/4] Removed redundant line --- src/auth.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/auth.d.ts b/src/auth.d.ts index 5a1b81ce7a..cfc2c1fd9c 100644 --- a/src/auth.d.ts +++ b/src/auth.d.ts @@ -636,7 +636,6 @@ export namespace admin.auth { /** * The date the user was created, formatted as a UTC string. - * */ creationTime?: string; }