Integrate Hanko with Rust backend
Get the Hanko API URL
Retrieve the API URL from the Hanko console.
Hanko Authentication with JWT
Upon a successful login, Hanko sends a cookie containing a JSON Web Token (JWT). You can use this JWT to authenticate requests on your backend.
Steps to Authenticate Requests
-
Recover the kid from the user JWT The kid tells us which key was used to sign the JWT.
-
Retrieve the JSON Web Key Set (JWKS): The JWKS has the public keys to verify the JWT. Fetch it from the Hanko API’s
.well-known/jwks.json
endpoint. -
Find the matching JWK from the JWKS retrieved at step 2 The matching JWK is the one that has the same kid found at step 1.
-
Verify the JWT: Use the matching JWK to verify the JWT.
The JWKS should be cached in the backend to avoid querying the endpoint every time a token needs to be validated. It is recommended to retrieve the JWKS when no JWK matches the JWT kid (step 3).
Rust-based Backend Example
Below is a sample code in rust validating the user JWT using reqwest and jsonwebtoken packages:
Was this page helpful?