【问题标题】:Set ADFS Redirect Uri for dev and test environments为开发和测试环境设置 ADFS 重定向 Uri
【发布时间】:2017-04-25 16:48:44
【问题描述】:

我有一个正在运行的 ADFS 服务器 (3.0) 和一个带有请求的 api,这些请求通过 ADFS 服务器提供的不记名令牌进行身份验证。作为使用 ADFS 授权的请求的一部分,我必须指定重定向 uri:

https://MyAdfsServer.com/adfs/oauth2/authorize?response_type=code&client_id=my-client-id&resource=https://my-web-api.com&redirect_uri=https://my-redirect-uri.com

这对于生产环境来说很好,但对于开发和测试环境,我不想通过 adfs 进行身份验证(如果我不需要的话)

有什么方法可以实现吗?我不想为每个环境创建多个 adfs 客户端,只是为了拥有单独的重定向 uri。对于其他本地开发人员,他们可能将网站设置在不同的位置,我可能使用https://localhost/my-app,但其他开发人员使用https://localhost/workspace2/my-app 等。

有没有一种干净的方法可以让我在开发和测试环境中不必去 ADFS 获取不记名令牌,或者在没有多个 adfs 客户端的情况下拥有单独的重定向 uri?

谢谢

【问题讨论】:

  • 看来,如果我在 IIS 上启用了 Windows 身份验证,那么它将验证我对 API 的请求,然后我可以有一个配置设置或类似的设置,如果我在开发/测试中我可以绕过通过adfs。然后在 prod 服务器上,我可以禁用 windows 身份验证并确保请求由 adfs 进行身份验证。这对我有用,但很高兴听到其他人对此问题的解决方案

标签: .net oauth-2.0 adfs bearer-token


【解决方案1】:

为了将来参考,我遇到了类似的问题。我最终所做的只是,在 web.config 和 web.config 转换之间切换

<authentication mode="Windows" />

&lt;authentication mode="None" /&gt;&lt;authentication mode="Windows" xdt:Transform="Replace" /&gt; 用于 web.config 转换 取决于环境所需的配置

然后在启动文件上添加一个快速检查

        public void ConfigureAuth(IAppBuilder app)
        {
            if (AuthenticationMode == System.Web.Configuration.AuthenticationMode.Windows)
            {
                return;
            }
          //rest of your authentication logic
         } 



private static System.Web.Configuration.AuthenticationMode AuthenticationMode
        {
            get
            {
                // gets a config file from the root of the system
                var configuration = WebConfigurationManager.OpenWebConfiguration("~");

                // gets the web.config part related with authentication
                var authenticationSection = (AuthenticationSection)configuration.GetSection("system.web/authentication");
                return authenticationSection.Mode;
            }
        }

有了这个,我能够在不同环境(测试/暂存/产品)中的身份验证类型之间无缝切换。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    相关资源
    最近更新 更多