Search code examples
vue.jslambdaauth0

Auth0: Managing authentication on Lambda functions


Current Implementation

My current application utilizes Vue.js + Auth0 on the frontend.

Vue.js utilizes AWS API Gateway, POST/GET methods are sent via:

https://xxxx.execute-api.us-east-1.amazonaws.com/dev/

On the API Endpoints that require authentication I have a "jwtRsaCustomAuthorizer" Authorizer. Which is documented here.

Remaining Concern

However is validating IF the token is valid enough? In this scenario I want to make a POST function that will do two things:

  • Update the users app_metadata
  • Save data associated to user

How do I KNOW User id auth0|123456 is who they say they are?

With the JWT being validated by the Authorizor, do I know the token hasn't been manipulated? E.g. if I just decode the passed data, can I assume the userID is valid?


Solution

  • The short answer is: You do not really care in the frontend. Validation of the token normally happens via the backend, which is in your case through the jwtRsaCustomAuthorizer you were talking about. If the backend trusts the token it returns data, and if it does not it returns an authorisation error.

    Your backend, and in particular jwtRsaCustomAuthorizer, does validate that the content of your JWT token is valid and trusted. A JWT token consists of three parts. The first part describes the algorithm used. The second part is the payload, which contains the claims, a nonce, an issuer and an expiration date. The third part is used to verify if the JWT token is issued by a trusted party by using a secret and generating a signature with it. In your case you are using RS256 with a private and public key pair.

    Since the first two parts of the JWT token are used to generate the signature, you cannot change the algorithm or the payload without invalidating the signature. Since RS256 uses assymetric encryption using a public and private key pair, you can either verify the JWT token by performing the same steps using the private key and comparing the newly generated signature against the signature in the JWT token, or in case of your api endpoint, using the public key to decrypt the signature and checking that against the first two parts of the JWT token.

    jwtRsaCustomAuthorizer ensures that the JWT token was created by auth0 by checking the JWT token against the public key that is provided by auth0. If the signature matches the payload, it means that the issuer must have had access to the private key, which is only available to the issuer. This allows you to trust the payload.

    You can find more information via jwt.io and this stackoverflow question on the difference between hs256 and rs256.