Backend Integration
Integrate Stack Auth with your own server with the REST APIs
To authenticate your endpoints, you need to send the user’s access token in the headers of the request to your server, and then make a request to Stack’s server API to verify the user’s identity.
Sending requests to your server endpoints
To authenticate your own server endpoints using Stack’s server API, you need to protect your endpoints by sending the user’s access token in the headers of the request.
On the client side, you can retrieve the access token from the user
object by calling user.getAuthJson()
. This will return an object containing accessToken
.
Then, you can call your server endpoint with these two tokens in the headers, like this:
Authenticating the user on the server endpoints
Stack Auth provides two methods for authenticating users on your server endpoints:
- JWT Verification: A fast, lightweight approach that validates the user’s token locally without making external requests. While efficient, it provides only essential user information encoded in the JWT.
- REST API Verification: Makes a request to Stack Auth’s servers to validate the token and retrieve comprehensive user information. This method provides access to the complete, up-to-date user profile.