orange-manchester-16482
04/11/2024, 5:02 AMchilly-king-10285
04/11/2024, 5:02 AMchilly-king-10285
04/11/2024, 5:03 AMjavascript import { Configuration, OAuth2Api } from "@ory/client" const ory = new OAuth2Api( new Configuration({ basePath: `https://${process.env.ORY_PROJECT_SLUG}.<http://projects.oryapis.com|projects.oryapis.com>`, accessToken: process.env.ORY_API_KEY, }), ) export async function introspectToken(accessToken: string) { const { data } = await ory.introspectOAuth2Token({ token: accessToken }) data.active // true or false }
In this example, the introspectToken
function sends a request to the introspection endpoint with the access token as a parameter. The endpoint responds with information about the token, including its validity and other metadata. If the token is valid and active, data.active
will be true
. Remember, OAuth2 tokens are like money. They allow you to perform actions, but they don't necessarily prove the identity of the user. For authentication purposes, you should use OpenID Connect ID Tokens. Sources: - [OAuth2 token introspection](https://www.ory.sh/docs/hydra/guides/oauth2-token-introspection) - [Revoking JSON Web Tokens](https://www.ory.sh/docs/oauth2-oidc/jwt-access-token#revoking-json-web-tokens) - [Should I use OAuth2 tokens for authentication?](https://www.ory.sh/docs/hydra/faq#should-i-use-oauth2-tokens-for-authentication)