Creating and verifying custom token

The Firebase Admin SDK provides us an ability to authenticate the user with an external mechanism such as LDAP server, or third-party OAuth provider, which Firebase doesn't support, such as Instagram or LinkedIn. We can do all these things with Firebase custom tokens method, which is built-in Admin SDK, or we can use any third-party JWT libraries.

Let's see how we can create and validate token with Admin SDK.

For creating a custom token, we must have a valid uid, which we need to pass in the createCustomToken() method:

function createCustomToken(req,res){ const userId = req.body.uid "guest_user" admin.auth().createCustomToken(userId) .then(function(customToken) { res.send(customToken.toJSON()); }) .catch(function(error) ...

Get Serverless Web Applications with React and Firebase now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.