Our application consists of an Angular App with a ServiceStack API (.net Framework 4.7.2.). For authentication, we are using an identityserver4.
The workflow for an authentication is as follows:
User opens angular app
User clicks “login button”, angular application is redirecting the user to an identityserver4
Identityserver validates user credentials and issues access_token
Angular App calls ServiceStack API with access_token (JWT) issued by identityserver
We now have the issue that under some mysterious circumstances, the API is refusing to accept the access_token. After a refresh of the angular App, exactly the same access_token is being accepted.
We believe that this has to do with the access_token not yet being valid (nbf time of jwt token). This can happen, if the time is not 100% in sync between the identityserver and the API Server.
Do you know, if there is a possibility to add a leeway into the validation of the nbf time on the API side?
This is our current Configuration:
Plugins.Add(new AuthFeature(() => new AuthUserSession(),
new IAuthProvider[]
{
new JwtAuthProviderReader(AppSettings)
{
PopulateSessionFilter = (session, payload, req) =>
{
session.Roles = new List<string>() { payload["role"] };
},
AuthRealm = xxx
Audience ="api1",
RequireSecureConnection = false,
HashAlgorithm = "RS256",
PrivateKey = xx
PublicKey = xx
}
})
{
IncludeAssignRoleServices = false,
IncludeRegistrationService = false
}
);
Hi,
Please excuse me, I may have been a bit short in explaining our system architecture. I have added the workflow of an authorization in the original post.
Regarding your question: We are validating an identityserver4 issued JWT token on a ServiceStack API
Ok though using IdentityServer4 tokens in ServiceStack JWT isn’t a supported or tested scenario. Why aren’t you validating IdentityServer4 tokens with Identity Server as per IdentityServer + ServiceStack docs? You’d generally always want to use the same library for issuing + validating tokens.
What’s the full HTTP Response Headers of an invalid request?
Ok, thanks for your answers and the hint that this is a not supported case.
I read the documentation prior the implementation, but the examples are for dotnet core and unfortunately we are still using .net framework. The NetCoreIdentityAuthProvider is not available there.
What is the supported way for validating identityserver generated jwt tokens for .net framework 4.7.2?
Failing that you’d need to create a custom JWT AuthProvider that validates IdentityServer tokens, I’ve no experience with that but ServiceStack.Authentication.IdentityServer has an IdentityServerAuthFeature plugin that encapsulates registering different Auth Providers for different IdentityServer Auth flows. It hasn’t been updated in a couple of years so you’d need to download the source to get it working with a recent version of ServiceStack.