Skip to content

Instantly share code, notes, and snippets.

@fredriccliver
Created November 6, 2020 17:18
Show Gist options
  • Save fredriccliver/7cc24a4a02bc3375ea16a20560897508 to your computer and use it in GitHub Desktop.
Save fredriccliver/7cc24a4a02bc3375ea16a20560897508 to your computer and use it in GitHub Desktop.
// do this before your work needs an authentication
if (req.headers.authorization && req.headers.authorization.startsWith('Bearer ')) {
console.log('Found "Authorization" header');
// Read the ID Token from the Authorization header.
idToken = req.headers.authorization.split('Bearer ')[1]
const decodedIdToken = await admin.auth().verifyIdToken(idToken)
console.log('ID Token correctly decoded', decodedIdToken)
req.user = decodedIdToken
}else{
// If this called without correct authentication, it will return 401 response.
console.log(req.auth)
res.status(401).send({error: `You don't have a permission to request.`})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment