IdentityServer3.AccessTokenValidation API和IdentityServer4
我从IdSrv4获得访问令牌,当我尝试打电话给我的API与该令牌IdentityServer3.AccessTokenValidation API和IdentityServer4
var client = new HttpClient();
client.SetBearerToken(token.AccessToken);
var response = await client.GetAsync("http://localhost:60602/api/users");
我收到此错误信息:
Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationMiddleware Error: 0 : Authentication failed System.InvalidOperationException: Sequence contains no elements at System.Linq.Enumerable.First[TSource](IEnumerable
1 source) at IdentityServer3.AccessTokenValidation.DiscoveryDocumentIssuerSecurityTokenProvider.<RetrieveMetadata>b__1(JsonWebKey key) in c:\local\identity\server3\AccessTokenValidation\source\AccessTokenValidation\Plumbing\DiscoveryDocumentIssuerSecurityTokenProvider.cs:line 152 at System.Linq.Enumerable.WhereSelectListIterator
2.MoveNext() at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ResolveIssuerSigningKey(String token, SecurityToken securityToken, SecurityKeyIdentifier keyIdentifier, TokenValidationParameters validationParameters) at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateSignature(String token, TokenValidationParameters validationParameters) at System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateToken(String securityToken, TokenValidationParameters validationParameters, SecurityToken& validatedToken) at Microsoft.Owin.Security.Jwt.JwtFormat.Unprotect(String protectedText) at Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationHandler.d__0.MoveNext()
我读此问题并添加由此代码生成的证书 https://github.com/ElemarJR/LearningIdentityServer4/tree/master/LearningIdentityServer.OAuth
但没有成功。
的WebAPI代码 ...
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = "http://localhost:5000",//Constants.BaseAddress,
RequiredScopes = new[] { "api1" },
});
...
有什么建议?
我有同样的问题;阅读以下链接 [此处输入链接的描述] [1]
Identity server 4 token not validate in .NetFramework Api that use Identity Server 3
和
在格兰夏日https://github.com/IdentityServer/IdentityServer3.AccessTokenValidation/issues/124
您必须升级到identityserver3.accesstokenvalidation “v2.13.0”
看看https://github.com/IdentityServer/IdentityServer3.AccessTokenValidation/issues/108似乎有一个解决方案。 –