将 IdentityServer4.AccessTokenValidation 和引用令牌与 ASP.NET Core Identity 连接起来

Jas*_*son 5 asp.net-web-api asp.net-identity bearer-token identityserver4 asp.net-core-2.0

我尝试构建一个由ASP.NET Web API后端支持的Angular 6应用程序。该应用程序根据联合 Azure AD 的单独Identity Server 4对用户进行身份验证,最终返回不记名引用令牌。

从登录然后验证(令牌)的角度来看,一切正常。用户访问该站点,被重定向到 Azure AD,登录,然后被重定向回 Angular 6 应用程序。对于 API 调用,令牌被注入标头,ASP.NET Core 身份验证中间件验证令牌并返回数据。

services
    .AddAuthentication(options => {
        options.DefaultScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
        options.DefaultAuthenticateScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
        options.DefaultChallengeScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
        options.DefaultSignInScheme = IdentityServerAuthenticationDefaults.AuthenticationScheme;
    })
    .AddIdentityServerAuthentication(options => {
        options.Authority = AuthClient.SsoBaseUrl;
        options.RequireHttpsMetadata = false;
        options.ApiName = AuthClient.SsoClientName;
        options.ApiSecret = AuthClient.SsoClientSecret;
    });
Run Code Online (Sandbox Code Playgroud)

我的问题是,我正在尝试合并 ASP.NET Core Identity,但我不确定在哪里/如何将claims principal通过AddIdentityServerAuthentication.

在此应用程序的早期版本 (ASP.NET Framework 4.7) 中,我们使用了Ws-Federationwhich 重定向回ExternalCallbackLogin()其中AccountController执行通常的AuthenticationManager.GetExternalLoginInfoAsync()thenSignInManager.ExternalSignInAsync()和 then (如果需要AppUserManager.CreateAsync()AppUserManager.AddLoginAsync()

该代码基本上检查了[AspNetUserLogins]表中提供者特定的键(来自声明)以映射到表中的用户[AspNetUsers]

随着更改,IdentityServer4.AccessTokenValidation我无法弄清楚该逻辑该放在哪里。由于我使用的是引用令牌,因此看起来JwtBearerEvents(特别是OnTokenValidated事件)没有被引发。事实上,看起来好像没有什么Introspection事件……?

我尝试在调用上述“管理器”方法的测试端点中测试逻辑(从技术上讲,它是ASP.NET Core Identity等效方法的更新),但这也不起作用。

例如,第一次调用SignInManager.GetExternalLoginInfoAsync()returns null

我究竟做错了什么?