GoogleCloudPlatform / iap-gcip-web-toolkit

Apache License 2.0
50 stars 23 forks source link

Auth Blocking Function JWT Validation #61

Open tannerlinsley opened 3 years ago

tannerlinsley commented 3 years ago

When following the documentation for blocker functions here we noticed that there is quite a bit of internal JWT validation happening within this beforeCreateHandler abstraction:

const gcipCloudFunctions = require('gcip-cloud-functions');
const authClient = new gcipCloudFunctions.Auth();

exports.beforeCreate = authClient.functions().beforeCreateHandler((user, context) => {
  // ... We can assume the token is valid at this point? How?
})

cc: @derekperkins

prameshj commented 1 year ago

Yes, you can assume that JWT verification has happened at this step. beforeCreateHandler takes in a (user, context) => any function and returns an http handler (express.Request, express.Response) => Promise<void>.

the (user, context) => any function is invoked only after performing a token verification via jsonwebtoken verify(). You could do the same by accessing the id token using context.credential?.idToken?.