IdentityServer4 icon indicating copy to clipboard operation
IdentityServer4 copied to clipboard

Update documentation after removing AddTemporarySigningCredential - issue with SecurityTokenSignatureKeyNotFoundException

Open z-tc opened this issue 8 years ago • 7 comments

Is your feature request related to a problem? Please describe.

This request is related to documentation and connected to issue i am encountering currently. I am using test host for API tests, and i've updated IdentityServer4.AccessTokenValidation from 1.2.1 to latest 2.6.0 and IdentityServer4 from 1.2.1 to 2.2.0. I needed to change setup from:

services.AddIdentityServer() .AddTemporarySigningCredential() // <-- to change .AddInMemoryClients(Config.GetClients()) .AddInMemoryIdentityResources(Config.GetIdentityResources()) .AddInMemoryApiResources(Config.GetApiResources()) .AddTestUsers(new List<TestUser>... to services.AddIdentityServer() .AddDeveloperSigningCredential(); // <-- changed .AddInMemoryClients(Config.GetClients()); .AddInMemoryIdentityResources(Config.GetIdentityResources()); .AddInMemoryApiResources(Config.GetApiResources()); .AddTestUsers(new List<TestUser>...

and this is basically only thing i changed in Test Host setup...

I am hitting the API endpoint in Main project from tests with HTTP client. Main project is also updated with the newest versions. With previous test host setup and old versions, all works fine, but after update and change from AddTemporarySigningCredential() to AddDeveloperSigningCredential(), i am getting error:

Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler:Information: Failed to validate the token "my-token"

Microsoft.IdentityModel.Tokens.SecurityTokenSignatureKeyNotFoundException: IDX10501: Signature validation failed. Unable to match keys: 'f2084371f0983f0da5c341d6a2235754', token: '{"alg":"RS256","typ":"JWT","kid":"f2084371f0983f0da5c341d6a2235754"}.{"nbf":1538643011,"exp":1538646611,"iss":"http://localhost","aud":["http://localhost/resources","api"],"client_id":"app","sub":"1","auth_time":1538643011,"idp":"local","company":"companyA","role":"ADMIN","scope":["company","openid","profile","role","api"],"amr":["pwd"]}'. at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters) at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.ValidateToken(String token, TokenValidationParameters validationParameters, SecurityToken& validatedToken) at Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler.HandleAuthenticateAsync()

Also one more point: when i am hitting Main project endpoint from Postman with correct Bearer, it works fine(Authority in this case is my User Service with old versions implementation), and in another case when running tests, authority is Test Host with new versions. In both cases Main project uses all new versions.

I can't figure out what is going on for around 2 days...

Describe the solution you'd like I would like to have transparent documentation after every bigger update and to have clear working examples after breaking changes, so i can just update my working code and make it work with new versions.

Hope you can help me solving this issue, Thanks!

z-tc avatar Oct 04 '18 09:10 z-tc

I'm not sure about your kid issue.

Our QS docs will be getting a bit of a reworking soon once we release 2.3.

brockallen avatar Oct 04 '18 12:10 brockallen

When do you expect 2.3 release, maybe that will solve my problem?

z-tc avatar Oct 04 '18 12:10 z-tc

Check the milestones.

brockallen avatar Oct 04 '18 12:10 brockallen

And about error, what should cause it? Both kid keys in log are the same...?

z-tc avatar Oct 04 '18 13:10 z-tc

Not sure -- I've seen that when manually validating JWTs and the JwtSecurityTokenHandler doesn't match on kid for some reason (only x5c). I assumed that was done properly in the UseJwtBearer, which is what our AccessTokenValidation wraps. Can you try with just UseJwtBearer directly and see?

In short, we need a repo to help diagnose. If you can get our samples to exhibit the same problem, then it will be easy for us to sort it out and provide a fix if necessary.

brockallen avatar Oct 04 '18 13:10 brockallen

I managed to solve the issue: I needed to create HttpMessageHandler from TestServer (i am using test host), and then to pass it and register in Web API Startup so IdentityServer can use this particular handler when tests are running. So, in configuration, if test are running - use handler from test host, in all other cases use default. Seems to me it is not a bug in IdentityServer4, just some edge use case. I don't know if there is some kind of explanation of handler usage (test environment) in docs, i couldn't find it. In any case, thanks for support, good luck and keep going! :)

z-tc avatar Oct 05 '18 11:10 z-tc

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 12 '20 22:01 lock[bot]