-
Hello everyone, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello @kotyara85 Yes, it is possible to dynamically set the expiration time of tokens in Ory Hydra, overwriting the default per token configuration. This can be done for various tokens including access tokens, ID tokens, auth codes, and refresh tokens.
For specific clients, you can modify the access, ID, and refresh token lifespan for each grant type individually per client using the SDK. This way, you can have tokens with the same client_id but different expiration times: (import { Configuration, OAuth2Api } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function setClientLifespans(clientId: string) {
await ory.setOAuth2ClientLifespans({
id: clientId,
oAuth2ClientTokenLifespans: {
authorization_code_grant_access_token_lifespan: "1h",
authorization_code_grant_id_token_lifespan: "12h",
authorization_code_grant_refresh_token_lifespan: "24h",
client_credentials_grant_access_token_lifespan: "1h",
implicit_grant_access_token_lifespan: "1h",
implicit_grant_id_token_lifespan: "12h",
jwt_bearer_grant_access_token_lifespan: "1h",
refresh_token_grant_access_token_lifespan: "1h",
refresh_token_grant_id_token_lifespan: "12h",
refresh_token_grant_refresh_token_lifespan: "24h",
},
})
}) (see also: Ory Documentation - Configure token expiration time |
Beta Was this translation helpful? Give feedback.
Hello @kotyara85
Sorry for the late reply!
Yes, it is possible to dynamically set the expiration time of tokens in Ory Hydra, overwriting the default per token configuration. This can be done for various tokens including access tokens, ID tokens, auth codes, and refresh tokens.
For global configuration in Ory Network, you can use the Ory CLI to set the lifespan of the access token and refresh token. Here are the commands: