Validate JWT in your application server
Authenticate the incoming HTTP requests by validating JWT in your application server
Last updated
Was this helpful?
Authenticate the incoming HTTP requests by validating JWT in your application server
Last updated
Was this helpful?
In this section, we will go through how to decode the JWT token to obtain the currently logged-in user.
Before we start, make sure the option Issue JWT as access token is enabled in your Application settings in the Portal.
With the Issue JWT as access token option turned on in your application, Authgear will issue JWT as access tokens. The incoming HTTP requests should include the access token in their Authorization
headers. Without setting the reverse proxy, your backend server can use your Authgear JWKS to verify the request and decode user information from the JWT access token.
This Discovery endpoint serves as a JSON document containing the OpenID Connect configuration of your app. It includes the authorization endpoint, the token endpoint, and the JWKS endpoint.
https://<YOUR_AUTHGEAR_ENDPOINT>/.well-known/openid-configuration
The JSON Web Key Sets (JWKS) endpoint can be found in jwk_url
in the configuration.
OpenID Connect Configuration JSON
Follow this step-by-step example to verify and decode the JWT token.
Define a function to find the JWKS endpoint from the OpenID Connect configuration. Use your Authgear endpoint as the base_address
Define a function to extract the access token from the Authorization header in the incoming request. It should look like Authorization: Bearer <access_token>
.
Here we show an example of using the Flask web framework to guard a path. You may need to adjust some of the codes to suit your technologies.
Validating JWT in your application server is currently only available for Token-based authentication.
Here is .
The auth_time
claim in an OIDC ID token represents the time when the user authentication occurred. Extract the auth_time
claim from the token, which should represent the time of the original authentication in seconds. If the difference between the current time and auth_time
exceeds your threshold (for example, 5 minutes), initiate the process.
See an example of how to verify the signature of the ID token, and then validate the claims auth_time
inside .
For Cookie-based authentication, JWT in cookies is not supported yet. .