【发布时间】:2016-12-08 19:28:21
【问题描述】:
我正在使用 IdSrv3 进行身份验证。我需要在我的 web api owin 客户端中获取 access_token 以在另一个 web api 客户端中通过承载身份验证。 我的 Startup.cs 代码:
public class Startup
{
public void Configuration(IAppBuilder app)
{
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();
var identityServerPath = ConfigurationManager.AppSettings["IdentityServerPath"];
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = $"{identityServerPath}/core",
RequiredScopes = new[] { "openid"},
AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active,
// client credentials for the introspection endpoint
ClientId = "someid"
});
}
}
我正在尝试通过这种方式获取访问令牌:
var claims = (User as ClaimsPrincipal).Claims;
var AccessToken = claims.First(x => x.Type == "access_token").Value;
如何获取access_token?声明变量为空。
【问题讨论】:
-
那里有问题吗? :)
-
@JohnKorsnes 已修复 :)
-
酷 :) 请为下一个开发者提供答案,如果它可以造福他人:)
标签: c# authentication asp.net-web-api openid-connect identityserver3