我们使用 IdentityServer4 作为 IdentityServer,使用 IdentityServer3 作为客户端 (ASP.NET MVC 5)。
一切正常(用户/声明原则通过 OWIN 正确设置),但我无法从用户那里获取访问令牌。
我们使用的隐式客户端可以访问这些范围:openid, profile, testapi
启动.cs:
app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
{
Authority = identityServerUrl,
RequiredScopes = new[] { "testapi" },
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = identityServerUrl,
ClientId = "testclient",
Scope = "openid profile testapi",
RedirectUri = "http://localhost:49000/signin-oidc",
ResponseType = "id_token token",
SignInAsAuthenticationType = "Cookies",
});
检索访问令牌的代码(在控制器之一内):
var user = User as ClaimsPrincipal;
var token = user.FindFirst("access_token");
用户设置正确,但令牌为空。我猜这是我在startup.cs中缺少的某种选项,但是哪个?