Created
November 6, 2020 17:18
-
-
Save fredriccliver/7cc24a4a02bc3375ea16a20560897508 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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