Skip to content

Commit 9796c56

Browse files
committed
Merge branch 'master' into ss-admin-auth-features
2 parents f6b7fb2 + 468dc88 commit 9796c56

38 files changed

+8538
-3455
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ node_modules
22
keyfile.json
33
service-account.json
44

5+
tsconfig.json
6+
57
.firebaserc
68
firebase-debug.log
79

810
*-debug.log
11+
12+
.DS_Store

auth/custom_claims.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const admin = require('firebase-admin');
33
admin.initializeApp();
44

55
const uid = 'firebaseUserId123';
6-
let idToken;
6+
const idToken = 'some-invalid-token';
7+
78
// [START set_custom_user_claims]
89
// Set admin privilege on the user corresponding to uid.
910

@@ -27,7 +28,7 @@ admin.auth().verifyIdToken(idToken).then((claims) => {
2728
// Lookup the user associated with the specified uid.
2829
admin.auth().getUser(uid).then((userRecord) => {
2930
// The claims can be accessed on the user record.
30-
console.log(userRecord.customClaims.admin);
31+
console.log(userRecord.customClaims['admin']);
3132
});
3233
// [END read_custom_user_claims]
3334

@@ -51,7 +52,7 @@ admin.auth().getUserByEmail('[email protected]').then((user) => {
5152
admin.auth().getUserByEmail('[email protected]').then((user) => {
5253
// Add incremental custom claim without overwriting existing claims.
5354
const currentCustomClaims = user.customClaims;
54-
if (currentCustomClaims.admin) {
55+
if (currentCustomClaims['admin']) {
5556
// Add level.
5657
currentCustomClaims['accessLevel'] = 10;
5758
// Add custom claims for additional privileges.

auth/email_action_links.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ admin.auth().generateSignInWithEmailLink(usremail, actionCodeSettings)
7878
// [END sign_in_with_email_link]
7979

8080
let displayName;
81-
function sendSignInEmail() {}
82-
function sendCustomVerificationEmail() {}
83-
function sendCustomPasswordResetEmail() {}
81+
function sendSignInEmail(...args) {
82+
// TODO: this function is just here to make the code "compile"
83+
}
84+
function sendCustomVerificationEmail(...args) {
85+
// TODO: this function is just here to make the code "compile"
86+
}
87+
function sendCustomPasswordResetEmail(...args) {
88+
// TODO: this function is just here to make the code "compile"
89+
}
8490

auth/get_service_account_tokens.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// [START get_service_account_tokens]
1818
const admin = require('firebase-admin');
1919

20-
const serviceAccount = require('path/to/serviceAccountKey.json');
20+
const serviceAccount = require('./path/to/serviceAccountKey.json');
2121
const credential = admin.credential.cert(serviceAccount);
2222

2323
credential.getAccessToken().then((accessTokenInfo) => {

auth/import_users.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,20 @@ let userImportRecords = [
2121
];
2222
//[END build_user_list]
2323

24-
let userImportOptions = {
25-
hash: {
26-
algorithm: 'HMAC_SHA256',
27-
key: Buffer.from('secretKey')
28-
}
29-
};
30-
3124
// [START import_users]
32-
admin.auth().importUsers(userImportRecords, userImportOptions)
25+
admin.auth().importUsers(userImportRecords, {
26+
hash: {
27+
algorithm: 'HMAC_SHA256',
28+
key: Buffer.from('secretKey')
29+
}
30+
})
3331
.then(function(userImportResult) {
3432
// The number of successful imports is determined via: userImportResult.successCount.
3533
// The number of failed imports is determined via: userImportResult.failureCount.
3634
// To get the error details.
37-
userImportResult.forEach(function(indexedError) {
38-
// The corresponding user that failed to upload.
39-
console.log(userImportRecords[indexedError.index].uid +' failed to import',
40-
indexedError.error);
35+
userImportResult.errors.forEach(function(indexedError) {
36+
// The corresponding user that failed to upload.
37+
console.log('Error ' + indexedError.index, ' failed to import: ' ,indexedError.error);
4138
});
4239
})
4340
.catch(function(error) {
@@ -150,14 +147,14 @@ admin.auth().importUsers([{
150147
// Must be provided in a byte buffer.
151148
passwordHash: Buffer.from('base64-password-hash', 'base64'),
152149
// Must be provided in a byte buffer.
153-
passwordSalt: Buffer.from('base64-salt', 'base64')
150+
passwordSalt: Buffer.from('base64-salt', 'base64'),
154151
}], {
155152
hash: {
156153
algorithm: 'SCRYPT',
157154
// All the parameters below can be obtained from the Firebase Console's users section.
158155
// Must be provided in a byte buffer.
159156
key: Buffer.from('base64-secret', 'base64'),
160-
saltSeparator: Buffer.from('base64SaltSeparator', 'base64'),
157+
saltSeparator: Buffer.from('base64SaltSeparator', 'base64').toString(),
161158
rounds: 8,
162159
memoryCost: 14
163160
}

auth/manage_cookies.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,9 @@ app.post('/sessionLogout', (req, res) => {
113113
});
114114
// [END session_clear_and_revoke]
115115

116-
function serveContentForAdmin(){}
117-
function serveContentForUser(){}
116+
function serveContentForAdmin(...args){
117+
// TODO: this function is just here to make the code "compile"
118+
}
119+
function serveContentForUser(...args){
120+
// TODO: this function is just here to make the code "compile"
121+
}

auth/manage_sessions.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
const admin = require('firebase-admin');
33
admin.initializeApp();
44

5+
const uid = 'some_uid_1234';
6+
const idToken = 'some_id_token';
7+
const utcRevocationTimeSecs = 60 * 60;
8+
59
// [START revoke_tokens]
610
// Revoke all refresh tokens for a specified user for whatever reason.
711
// Retrieve the timestamp of the revocation, in seconds since the epoch.
@@ -40,6 +44,4 @@ admin.auth().verifyIdToken(idToken, checkRevoked)
4044
// Token is invalid.
4145
}
4246
});
43-
// [END verify_id_token_check_revoked]
44-
45-
let uid, idToken, utcRevocationTimeSecs;
47+
// [END verify_id_token_check_revoked]

auth/manage_users.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
const admin = require('firebase-admin');
33
admin.initializeApp();
44

5+
const uid = 'some_uid_1234';
6+
const uid1 = 'some_uid_1';
7+
const uid2 = 'some_uid_2';
8+
const uid3 = 'some_uid_3';
9+
const email = '[email protected]';
10+
const phoneNumber = '+15558675309';
11+
512
// [START get_user_by_id]
613
admin.auth().getUser(uid)
714
.then(function(userRecord) {
@@ -196,6 +203,4 @@ function listAllUsers(nextPageToken) {
196203
}
197204
// Start listing users from the beginning, 1000 at a time.
198205
listAllUsers();
199-
// [END list_all_users]
200-
201-
let uid, uid1, uid2, uid3, email, phoneNumber;
206+
// [END list_all_users]

0 commit comments

Comments
 (0)