Verifying OAuth tokens with Clerk
If you are building an application that uses Clerk and would like to incorporate OAuth, you'll want to ensure that, after the client gets an OAuth access token, they can use it to make authenticated requests into your app (the resource service) using the token.
Clerk’s SDKs support this through the acceptsToken
parameter that can be used in Clerk's route protection functions, such as auth()
, auth.protect()
and authenticateRequest()
.
For detailed examples and best practices on accepting and verifying OAuth tokens with Clerk SDKs, see the following guides:
- Accepting and verifying an OAuth Token with Next.js.
- Accepting and verifying an OAuth Token with React Router.
- Accepting and verifying an OAuth Token with Tanstack React Start.
You can also verify tokens manually via the Clerk REST API. Ensure you have your Clerk Secret Key on hand as you’ll need to include it in the Authorization
header - it can be retrieved from the API keys page in the Clerk Dashboard.
curl https://api.clerk.com/oauth_applications/access_tokens/verify \
-X POST \
-H 'Authorization: Bearer your-clerk-secret-key-here' \
-H 'Content-Type: application/json' \
-d '{ "access_token": "your-oauth-token-here" }'
Feedback
Last updated on