(req, res, next)
| 21 | |
| 22 | // Extract and verify Id Token from header |
| 23 | const authenticateJWT = (req, res, next) => { |
| 24 | const authHeader = req.headers.authorization; |
| 25 | if (authHeader) { |
| 26 | const token = authHeader.split(' ')[1]; |
| 27 | // If the provided ID token has the correct format, is not expired, and is |
| 28 | // properly signed, the method returns the decoded ID token |
| 29 | firebase |
| 30 | .auth() |
| 31 | .verifyIdToken(token) |
| 32 | .then(decodedToken => { |
| 33 | const uid = decodedToken.uid; |
| 34 | req.uid = uid; |
| 35 | next(); |
| 36 | }) |
| 37 | .catch(err => { |
| 38 | req.logger.error(`Error with authentication: ${err}`); |
| 39 | return res.sendStatus(403); |
| 40 | }); |
| 41 | } else { |
| 42 | return res.sendStatus(401); |
| 43 | } |
| 44 | }; |
| 45 | // [END cloudrun_user_auth_jwt] |
| 46 | |
| 47 | let project; |
nothing calls this directly
no outgoing calls
no test coverage detected