MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / authenticateJWT

Function authenticateJWT

run/idp-sql/middleware.js:23–44  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

21
22// Extract and verify Id Token from header
23const 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
47let project;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected