[SOLVED] Accessing principalid or claim from authorizer function

Hi guys,
Sorry for being a complete noob in serverless+lambda here :frowning:

I am hitting a wall and cannot work out if it’s possible to access the claim or principalid from the authorizer.
I am using AWS +Nodejs combo, the auth function example works flawlessly and now i am trying to get the Userid back from the Auth0 token (which should have already be verified and parsed through auth function).

Isn’t that suppose to be as simple as using context.authorizer.principalId in AWS?

Of course, I suppose I could use jwt function to parse the header again but it feels yucky to have to do that for every function accessing the db which use the userid as look up value. :-/

Many thanks,
San

Hi @santrancisco,
It is as easy as that :wink:
So you are talking about this example: aws-node-auth0-custom-authorizers-api?

In the handler’s privateEndpoint function you should be able to access the sub claim or rather principalId as follows:

// => it's part of the request object (event) and not the lambda context
event.requestContext.authorizer.principalId

(edit: it’s requestContext and not context)
(In case of doubt, just dump/log the event object)

2 Likes

@bbilger mate, you are a f***** legend! Thank you very much! :slight_smile: