【问题标题】:thinktecture identity server 3 authentication works correctly in iis express, but keeps on throwing 401 unatuhorized when hosted in iisthinktecture 身份服务器 3 身份验证在 iis express 中正常工作,但在 iis 中托管时继续抛出 401 untuhorized
【发布时间】:2015-03-05 01:33:41
【问题描述】:

好的,所以我尝试在 iis 上托管最简单的 oauth 示例和身份服务器,我在最简单的 oauth 示例上启用了 cors。因此,当我使用 javascript 隐式客户端测试 api 时,在 iis express 上它可以完美运行,它会获取令牌,然后在发送令牌时,web api 检查令牌并授权 javascript 客户端。当我移动 javascript 隐式客户端、身份服务器和简单的 oath web api 托管在 iis 上时,就会出现问题,javascript 正确地带回了令牌,但是当令牌被发送到 web api 时,它总是返回 401 未经授权。那么是否有任何配置我必须添加才能在 iis 上运行它。我已确保匿名身份验证是唯一启用的身份验证模式。任何帮助或指针都非常感谢。

我正在尝试实现 iis 上给出的示例。感谢您的帮助

【问题讨论】:

    标签: thinktecture-ident-server thinktecture


    【解决方案1】:

    我遇到了同样的问题。它来自我的自签名证书。

    尝试添加到您的 IdentityServerOptions

    RequireSsl = false
    

    并切换 WebApi 权限以使用 http。

    编辑

    服务器端配置

       public void ConfigureIdentityServer(IAppBuilder app)
            {
                //Configure logging
                LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());
                //This is using a Factory Class that generates the client, user & scopes. Can be seen using the exmaples
                var IdentityFactory = Factory.Configure("DefaultConnection");
    
                app.Map("/identity", idsrvApp =>
                {
                    idsrvApp.UseIdentityServer(new IdentityServerOptions
                    {
                        SiteName = "Security Proof of Concept",
                        SigningCertificate = LoadCertificate(),
                        Factory = IdentityFactory,
                        CorsPolicy = CorsPolicy.AllowAll,
                        RequireSsl = false
                    });
                });
            }
    

    JavaScript

    收到令牌后,确保将其插入到授权标头中..

    JQuery 示例

        $.ajax({
        url: 'http://your.url',
        type: GET,     
        beforeSend: function (xhr) {
                      xhr.withCredentials = true;
                      xhr.setRequestHeader("Authorization", " Bearer " + apiToken);
                  }
    });
    

    WebApi 资源

      app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
            {
                //Location of identity server make full url & port
                Authority = "http://localhost/identity",
                RequiredScopes = new[] { "WebApiResource" }
                //Determines if the Api Pings the Identity Server for validation or will decrypt token by it's self 
                //ValidationMode = ValidationMode.Local
            });
    

    确定正在发生的事情的最佳方法是启用日志记录。

    【讨论】:

    • 我的资源服务器和身份服务器都在 http 上运行,但我得到了相同的结果,你能不能给我一步一步的详细信息
    • 谢谢 Derek,它现在可以工作了
    猜你喜欢
    • 1970-01-01
    • 2020-04-01
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-05
    • 2017-05-01
    • 2020-12-26
    相关资源
    最近更新 更多