【问题标题】:allow anonymous access to .well-known directory允许匿名访问 .well-known 目录
【发布时间】:2016-08-31 19:44:07
【问题描述】:

请多多包涵:我对这一切都很陌生

我正在努力将 openid connect 与该公司开发的一对应用程序集成。

我们正在使用自定义/公司特定的 openid 连接库,我认为这些库本质上是围绕 Microsoft.Owin.Security.OpenIdConnect 和 Owin.Security.OpenIdConnect.Server 的包装器

在 idP 应用程序 web.config 中,我们有类似的内容:

<location path="." inheritInChildApplications="false">
    <authentication mode="Forms">
        <forms loginUrl="~/Login" name="{....}" protection="All" path="/" slidingExpiration="true" requireSSL="false" defaultUrl="~/Home" cookieless="UseCookies" />
    </authentication>
    <authorization>
        <deny users="?" />
        <!-- denies anonymous users to all pages, except those defined under location nodes -->
    </authorization>
</location>

加上一堆位置节点来允许/拒绝对特定页面/资源的访问

问题是,当用户未登录(或者,它似乎正在登录过程中)时,当 openid connect 东西尝试访问 /.well-known/openid-configuration 时, 响应是 302 重定向到登录页面

显然这会在预期 JSON 响应时导致问题

我已尝试将位置节点添加到 web.config:

<location path= "~/.well-known/openid-configuration">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

(我也尝试过使用 path = "~/.well-known")

但我仍然被重定向到登录页面

需要明确的是,idP 应用程序中没有实际的目录 /.well-known;该文件似乎是在 Owin.Security.OpenIdConnect.Server 的某处构建的。

【问题讨论】:

    标签: asp.net web-config openid-connect aspnet-contrib


    【解决方案1】:

    该文件似乎是在 Owin.Security.OpenIdConnect.Server 的某个地方构建的

    是的。

    尝试在注册 OIDC 服务器中间件后立即调用app.UseStageMarker(PipelineStage.Authenticate),以防止 ASP.NET 在有机会被调用之前应用授权策略:

    app.UseOpenIdConnectServer(options => {
        options.AllowInsecureHttp = true;
    });
    
    app.UseStageMarker(PipelineStage.Authenticate);
    

    请注意,使用app.UseStageMarker() 时,您的web.config 中的~/.well-known/openid-configuration 不需要例外。

    【讨论】:

    • 非常感谢!那行得通。顺便说一句:在注册充当 UseOpenIdConnectServer 的一种包装器的自定义中间件之后,我最终调用了 app.UseStageMarker(PipelineStage.Authenticate)
    • 太棒了!我很想了解更多关于您如何将 OIDC 服务器中间件与您的自定义中间件一起使用的信息。如果你愿意分享一些细节,请加入我的gitter.im/aspnet-contrib/AspNet.Security.OpenIdConnect.Serverjabbr.net/#/rooms/aspnet-contrib。谢谢!
    【解决方案2】:

    我也很新,但我认为您是该位置的 .aspx 页面的路径,其余部分是继承的。只需更改拒绝以允许使用 asterix 的用户。还要确保 web.config 在目录中。听起来像你,但众所周知的应该是允许所有用户的 web.config。

    <?xml version="1.0"?>
    <configuration>
    
      <location path="Manage.aspx">
        <system.web>
          <authorization>
            <deny users="?"/>
          </authorization>
        </system.web>
      </location>
    </configuration>
    

    【讨论】:

    • 感谢您的回复。我不能只是将拒绝更改为允许,因为我们实际上确实希望重定向大多数页面。此外,正如我所说,.well-known 目录实际上并不存在于应用程序中:据我所知,中间件应该“拦截”请求并为响应构造适当的 json
    猜你喜欢
    • 2017-07-08
    • 2017-09-13
    • 2018-10-23
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 2015-08-30
    • 2014-09-02
    相关资源
    最近更新 更多