thinktecture 身份服务器 3 身份验证在 iis express 中正常工作,但在 iis 中托管时继续抛出 401 unatuhorized

thinktecture identity server 3 authentication works correctly in iis express, but keeps on throwing 401 unatuhorized when hosted in iis

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

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

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

尝试添加到您的 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

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

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
        });

确定发生了什么的最佳方法是启用日志记录。