Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ node_modules
keyfile.json
service-account.json

tsconfig.json

.firebaserc
firebase-debug.log

*-debug.log

.DS_Store
7 changes: 4 additions & 3 deletions auth/custom_claims.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const admin = require('firebase-admin');
admin.initializeApp();

const uid = 'firebaseUserId123';
let idToken;
const idToken = 'some-invalid-token';

// [START set_custom_user_claims]
// Set admin privilege on the user corresponding to uid.

Expand All @@ -27,7 +28,7 @@ admin.auth().verifyIdToken(idToken).then((claims) => {
// Lookup the user associated with the specified uid.
admin.auth().getUser(uid).then((userRecord) => {
// The claims can be accessed on the user record.
console.log(userRecord.customClaims.admin);
console.log(userRecord.customClaims['admin']);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this switched from customClaims.admin to customClaims['admin'] here and below to make the compiler happy? I think the original .admin syntax is nicer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it was ... do you have a suggestion for how we can have the . syntax? I actually don't mind this because it shows a division between types parts userRecord.customClaims and the any Danger Zone

});
// [END read_custom_user_claims]

Expand All @@ -51,7 +52,7 @@ admin.auth().getUserByEmail('user@admin.example.com').then((user) => {
admin.auth().getUserByEmail('user@admin.example.com').then((user) => {
// Add incremental custom claim without overwriting existing claims.
const currentCustomClaims = user.customClaims;
if (currentCustomClaims.admin) {
if (currentCustomClaims['admin']) {
// Add level.
currentCustomClaims['accessLevel'] = 10;
// Add custom claims for additional privileges.
Expand Down
12 changes: 9 additions & 3 deletions auth/email_action_links.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ admin.auth().generateSignInWithEmailLink(usremail, actionCodeSettings)
// [END sign_in_with_email_link]

let displayName;
function sendSignInEmail() {}
function sendCustomVerificationEmail() {}
function sendCustomPasswordResetEmail() {}
function sendSignInEmail(...args) {
// TODO: this function is just here to make the code "compile"
}
function sendCustomVerificationEmail(...args) {
// TODO: this function is just here to make the code "compile"
}
function sendCustomPasswordResetEmail(...args) {
// TODO: this function is just here to make the code "compile"
}

2 changes: 1 addition & 1 deletion auth/get_service_account_tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// [START get_service_account_tokens]
const admin = require('firebase-admin');

const serviceAccount = require('path/to/serviceAccountKey.json');
const serviceAccount = require('./path/to/serviceAccountKey.json');
const credential = admin.credential.cert(serviceAccount);

credential.getAccessToken().then((accessTokenInfo) => {
Expand Down
25 changes: 11 additions & 14 deletions auth/import_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,20 @@ let userImportRecords = [
];
//[END build_user_list]

let userImportOptions = {
hash: {
algorithm: 'HMAC_SHA256',
key: Buffer.from('secretKey')
}
};

// [START import_users]
admin.auth().importUsers(userImportRecords, userImportOptions)
admin.auth().importUsers(userImportRecords, {
hash: {
algorithm: 'HMAC_SHA256',
key: Buffer.from('secretKey')
}
})
.then(function(userImportResult) {
// The number of successful imports is determined via: userImportResult.successCount.
// The number of failed imports is determined via: userImportResult.failureCount.
// To get the error details.
userImportResult.forEach(function(indexedError) {
// The corresponding user that failed to upload.
console.log(userImportRecords[indexedError.index].uid +' failed to import',
indexedError.error);
userImportResult.errors.forEach(function(indexedError) {
// The corresponding user that failed to upload.
console.log('Error ' + indexedError.index, ' failed to import: ' ,indexedError.error);
});
})
.catch(function(error) {
Expand Down Expand Up @@ -150,14 +147,14 @@ admin.auth().importUsers([{
// Must be provided in a byte buffer.
passwordHash: Buffer.from('base64-password-hash', 'base64'),
// Must be provided in a byte buffer.
passwordSalt: Buffer.from('base64-salt', 'base64')
passwordSalt: Buffer.from('base64-salt', 'base64'),
}], {
hash: {
algorithm: 'SCRYPT',
// All the parameters below can be obtained from the Firebase Console's users section.
// Must be provided in a byte buffer.
key: Buffer.from('base64-secret', 'base64'),
saltSeparator: Buffer.from('base64SaltSeparator', 'base64'),
saltSeparator: Buffer.from('base64SaltSeparator', 'base64').toString(),
rounds: 8,
memoryCost: 14
}
Expand Down
8 changes: 6 additions & 2 deletions auth/manage_cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,9 @@ app.post('/sessionLogout', (req, res) => {
});
// [END session_clear_and_revoke]

function serveContentForAdmin(){}
function serveContentForUser(){}
function serveContentForAdmin(...args){
// TODO: this function is just here to make the code "compile"
}
function serveContentForUser(...args){
// TODO: this function is just here to make the code "compile"
}
8 changes: 5 additions & 3 deletions auth/manage_sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
const admin = require('firebase-admin');
admin.initializeApp();

const uid = 'some_uid_1234';
const idToken = 'some_id_token';
const utcRevocationTimeSecs = 60 * 60;

// [START revoke_tokens]
// Revoke all refresh tokens for a specified user for whatever reason.
// Retrieve the timestamp of the revocation, in seconds since the epoch.
Expand Down Expand Up @@ -40,6 +44,4 @@ admin.auth().verifyIdToken(idToken, checkRevoked)
// Token is invalid.
}
});
// [END verify_id_token_check_revoked]

let uid, idToken, utcRevocationTimeSecs;
// [END verify_id_token_check_revoked]
11 changes: 8 additions & 3 deletions auth/manage_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
const admin = require('firebase-admin');
admin.initializeApp();

const uid = 'some_uid_1234';
const uid1 = 'some_uid_1';
const uid2 = 'some_uid_2';
const uid3 = 'some_uid_3';
const email = 'someone@example.com';
const phoneNumber = '+15558675309';

// [START get_user_by_id]
admin.auth().getUser(uid)
.then(function(userRecord) {
Expand Down Expand Up @@ -154,6 +161,4 @@ function listAllUsers(nextPageToken) {
}
// Start listing users from the beginning, 1000 at a time.
listAllUsers();
// [END list_all_users]

let uid, uid1, uid2, uid3, email, phoneNumber;
// [END list_all_users]
Loading