Search code examples
javasecurityjwtmicronaut

Custom JWT expiration in micronaut security


The expiration time of a JWT can be set by configuring micronaut.security.token.jwt.generator.access-token-expiration.

Is it possible to have a custom value for individually issued JWT tokens? Searching the documentation I haven't found any useful information except you can replace the BearerTokenRenderer and return a custom response.

    public AccessRefreshToken render(Integer expiresIn, String accessToken, @Nullable String refreshToken) {
    return new AccessRefreshToken(accessToken, refreshToken, BEARER_TOKEN_TYPE, ***customValue**);
}

Will returning a different value for expires_in work in this case?


Solution

  • According to micronaut documentation - pt 9.3.5

    You can replace ClaimGenerator with your own: ClaimGenerator

    Which has a method with parameter Integer expiration

    You can replace classes by using @Replaces annotation like described here:

    https://micronaut-projects.github.io/micronaut-core/latest/guide/#replaces

    I hope that solves your issue