Search code examples
identityserver4access-tokenjwt

How to customize Access Token Lifetime Validator using AddIdentityServerAuthentication in WebAPI startup


I have a Web API protected with IdentityServer4. I want to use AddIdentityServerAuthentication extension method to setup protection because I know that it has some features like discovery document caching and so on. But I can't figure out how to customize TokenValidationOptions object to rewrite my custom LifetimeValidator just like the way you do using AddJwtBearer method.


Solution

  • You can't customize your tokens in a API protected by IdentityServer, you can only customize them in the IdentityServer project it's self. Here is the documentation part on tokens. Hope it helps and that i didn't misunderstand you.
    EDIT: Maybe this will help:

    services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
        .AddIdentityServerAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme,
            jwtOptions =>
            {
                // jwt bearer options
            },
            referenceOptions =>
            {
                // oauth2 introspection options
            });
    

    Found here