【问题标题】:UseOpenIdConnectAuthentication middleware not working when self hosted自托管时 UseOpenIdConnectAuthentication 中间件不起作用
【发布时间】:2021-04-19 23:25:50
【问题描述】:

我有一个托管在 IIS 上的 WebAPI,我正在尝试将其移至 Service Fabric。一切正常,除了我的 OpenIdConnect 中间件。重定向到身份验证提供程序永远不会发生。我将其设置为仅在用户使用 MapWhen 到达某些路线时重定向用户

 app.MapWhen(owinContext =>
        {
            if (owinContext.Request.Path.Value.ToLower().StartsWith("/someroute))
            {
                return true;
            }
            return false;
        }, adApp => adApp.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions

我可以调试 MapWhen 并且我看到它返回 true,但没有发生任何重定向,而不是重定向。有什么想法可能导致重定向失败?该中间件是否与自托管应用兼容?

【问题讨论】:

    标签: openid-connect middleware global-asax webapi


    【解决方案1】:

    如果你正在做一个新项目,你应该避免使用 UseOpenIdConnectAuthentication 而使用 AddAuthentication().AddOpenIdConnect。

    你可以看到像here这样提到:

    [过时(“UseOpenIdConnectAuthentication 已过时。在 ConfigureServices 中使用 AddAuthentication().AddOpenIdConnect 配置 OpenIdConnect 身份验证。有关详细信息,请参阅 https://go.microsoft.com/fwlink/?linkid=845470。”,错误:true) ]

    另外,我怀疑你应该把它放在 MapWhen 中。

    【讨论】:

    • 我最终删除了中间件并使用 Thinktecture.IdentityModel.Client.OAuth2Client 来启动重定向服务器端。问题的核心是我正在从服务器为我的 Angular 应用程序进行 oauth 握手,而服务器端中间件是用来保护 MVC 路由的,而 maphwhen 是一种黑客方式。
    【解决方案2】:

    我最终删除了中间件并使用 Thinktecture.IdentityModel.Client.OAuth2Client 来启动重定向服务器端。

    OpenIdConnect Owin 中间件旨在用于保护 MVC 页面。当我从我的应用程序中删除 MVC 路由以进行自托管时,我相信这就是破坏它的原因。

    【讨论】:

      猜你喜欢
      • 2019-08-09
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      • 2013-03-10
      • 1970-01-01
      • 2012-09-04
      • 2017-07-25
      • 2018-07-14
      相关资源
      最近更新 更多