【问题标题】:Identity Server 3 Authentication/Authorization, with ASP.NET CORE 1.0Identity Server 3 身份验证/授权,带有 ASP.NET CORE 1.0
【发布时间】:2019-03-14 03:17:57
【问题描述】:

我目前正在开发一个基于 ASP.NET Core 1.0 的 RESTful 项目,该项目连接到 Identity Server 3。我在 Startup.cs 的 ConfigureServices 方法中为所有控制器设置了一个全局 [Authorize] 过滤器。

我现在尝试在 CORE 1.0 项目的 Startup.cs 中针对我的身份服务器 3 验证来自 AJAX 请求的承载令牌,从而授权我的控制器资源。

与(经典)ASP.NET 4.5 相比,ASP.NET CORE 1.0 似乎发生了很大变化。

您对如何实现这一点有一些想法吗?如何在 ASP.NET Core 1.0 中验证我的令牌?

非常感谢!

更新

在 Asp.net 4.5 中,我能够使用 app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions(){...}) 但这在 ASP.NET Core 1.0 中不存在。

相反,我尝试使用以下内容:

var connectOptions = new OpenIdConnectOptions
            {      
                Authority = Configuration["IdentityServerSettings:CoreUrl"],
                ClientId = Configuration["IdentityServerSettings:ClientId"],
                ClientSecret = Configuration["IdentityServerSettings:ClientSecret"],
                PostLogoutRedirectUri = Configuration["IdentityServerSettings:PostLogoutRedirectUri"],
                ResponseType = OpenIdConnectResponseType.Code
            };
            app.UseOpenIdConnectAuthentication(connectOptions);

不幸的是,我得到的只是 HTTP 302...

【问题讨论】:

    标签: c# asp.net jwt identityserver3 asp.net-core-1.0


    【解决方案1】:

    可以使用 IdentityServer4.AccessTokenValidation 来解决这个问题 :)

    app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions()
                {
                    ScopeName = Configuration["IdentityServerSettings:ApiScopes"],
                    Authority = Configuration["IdentityServerSettings:CoreUrl"]
                });
    

    【讨论】:

      【解决方案2】:

      我认为您要求的是您想要使用承载令牌身份验证中间件。

      你要找的包是"Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0"

      【讨论】:

      • 感谢 Lutando,虽然我不太确定 JwtBearer Middleware 是否可以解决我的 Identiy Server 3 问题...嗯
      猜你喜欢
      • 2016-08-31
      • 1970-01-01
      • 2022-06-13
      • 2021-04-16
      • 2018-12-30
      • 2017-06-26
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多