【问题标题】:IdentityServer3.AccessTokenValidation API and IdentityServer4IdentityServer3.AccessTokenValidation API 和 IdentityServer4
【发布时间】:2016-11-05 21:02:49
【问题描述】:

我从 IdSrv4 获取访问令牌,当我尝试使用该令牌调用我的 api 时

var client = new HttpClient();
client.SetBearerToken(token.AccessToken);
var response = await client.GetAsync("http://localhost:60602/api/users");

我收到此错误消息:

Microsoft.Owin.Security.OAuth.OAuthBearerAuthenticationMiddleware 错误:0:身份验证失败 System.InvalidOperationException: 序列不包含元素 System.Linq.Enumerable.First[TSource](IEnumerable1 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.WhereSelectListIterator2.MoveNext() 在 System.IdentityModel.Tokens.JwtSecurityTokenHandler.ResolveIssuerSigningKey(字符串 令牌、SecurityToken securityToken、SecurityKeyIdentifier keyIdentifier,TokenValidationParameters 验证参数)在 System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateSignature(字符串 令牌,令牌验证参数验证参数)在 System.IdentityModel.Tokens.JwtSecurityTokenHandler.ValidateToken(字符串 securityToken, TokenValidationParameters 验证参数, 安全令牌和验证令牌)在 Microsoft.Owin.Security.Jwt.JwtFormat.Unprotect(字符串受保护文本) 在 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" },
 });

...

有什么建议吗?

【问题讨论】:

标签: asp.net-web-api identityserver3 identityserver4


【解决方案1】:

我有同样的问题;阅读以下链接 [在此处输入链接描述][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”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-16
    • 2021-07-21
    • 2021-12-03
    • 2019-04-27
    • 1970-01-01
    • 2018-05-17
    • 2018-11-10
    • 2015-07-12
    相关资源
    最近更新 更多