Minting Custom Tokens with the Admin SDK for Node.js - Firecasts

By: Firebase

131   5   4747

Uploaded on 12/18/2017

Learn how to initialize the Admin SDK for Node.js and create custom JSON Web Tokens (JWTs). In this Firecast, Jen Person shows you how to generate auth tokens using the Firebase Admin SDK.

Links:
Setting up the Admin SDK: https://goo.gl/K6DXyZ
Create Custom Tokens documentation: https://goo.gl/MqtpvG
Initializing npm: https://goo.gl/Kg1YvQ

Add the Firecasts playlist! https://goo.gl/n2XqG1
Subscribe to the Firebase Channel: https://goo.gl/9giPHG

Comments (2):

By anonymous    2018-03-05

Try the following.

  1. Whenever a user signs up with your platform, be sure to save their basic information e.g. email, name, photoURL, signup/loginType, user-id etc to a database of your choice i.e Firebase Firestore or the Realtime Database(RTD).

So you could have the following Scheme in the RTD for instance:

my-app
  ----users
  --------user-id-1
  ------------name: User 1
  ------------email: user1@domain.com
  ------------loginType:facebook
  ------------id: user-id-1 
  --------user-id-2
  ------------name: User 2
  ------------email: user2@domain.com
  ------------loginType:email
  ------------id: user-id-2 
  ---etc

This way if a user claims to have forgotten their password, you can do a quick lookup via email and obtain the users id. For the Realtime Database I would recommend denormalize your data a bit more so that you can retrieve user id's by email. This is what I mean

my-app
  --users
  --------user-id-1
  ------------name: User 1
  ------------email: user1@domain.com
  ------------id: user-id-1
  --------user-id-2
  ------------name: User 2
  ------------email: user2@domain.com
  ------------loginType:email
  ------------id: user-id-2  
  --users-by-email
  --------user1@domain.com
  ------------user-id-1
  --------user2@domain.com
  ------------user-id-2

In this case you can easily find the users id based on their email if you search the users-by-email field and insert the users email as a key. It should return the userid.

In Firestore, I believe you can easily query for this without having to denormalize your data.

  1. Once you have access to the users-id and email, you can follow this guide by @JenPerson from the Firebase team on how to mint your own Authentication tokens, that will let Firebase know you are re-authenticating a specified user with different credentials

Original Thread

By anonymous    2018-03-12

So when you authenticate your user you create a custom token using firebase admin sdk, pass that token to client and use that to login with firebase. In order to create the token you also pass a uid that you want, this can be uid you use or something else, and you can use that to access firebase features. There is a relevant firecast you probably wanna checkout https://www.youtube.com/watch?v=WtYzHTXHBp0

Original Thread

Submit Your Video

If you have some great dev videos to share, please fill out this form.