繁体   English   中英

IdentityServer3连接/令牌端点始终返回401:未授权

[英]IdentityServer3 connect/token endpoint always return 401: unauthorized

我正在尝试为我的项目设置IdentityServer3。

当我在本地开发计算机上运行IdentityServer3时,一切正常,但是将其托管在共享服务器上时,出现401错误。 我正在尝试使用端点connect \\ token访问令牌。 这是Identityserver3的配置

IdentityServerOptions identityServerOptions = new IdentityServerOptions
{
    SiteName = "Ripple IdentityServer",
    SigningCertificate = LoadCertificate(),
    AuthenticationOptions = new IdentityServer3.Core.Configuration.AuthenticationOptions
    {
        EnablePostSignOutAutoRedirect = true,
    },
    LoggingOptions = new LoggingOptions
    {
        EnableWebApiDiagnostics = true,
        WebApiDiagnosticsIsVerbose = true,
        EnableHttpLogging = true,
        EnableKatanaLogging = true
    },

    Factory = factory,
};

奇怪的是我没有收到任何日志。 我知道日志正在工作,因为当我访问连接/授权端点时,我可以看到日志信息。 这是我的客户注册

client = new Client
{
    ClientId = app.Id,
    ClientName = app.Name,
    Flow = Flows.ResourceOwner,
    AllowedScopes = app.AllowedScopes.Split(';').ToList(),
    AllowedCorsOrigins = new List<string> { "*" }
};
if (app.Secret != null && app.Secret != "")
{
    client.ClientSecrets = new System.Collections.Generic.List<Secret>();
    app.Secret = app.Secret.Replace("{", "").Replace("}", "");

    string[] secrets = app.Secret.Split(',');
    foreach (var s in secrets)
    {
        client.ClientSecrets.Add(new Secret(s.Sha256()));
    }
}

这是获取访问令牌的客户端代码

var data = new StringContent(string.Format("grant_type=password&username={0}&password={1}&Domain={2}&scope={3}",
HttpUtility.UrlEncode(username),
HttpUtility.UrlEncode(password),
HttpUtility.UrlEncode(domainId),
HttpUtility.UrlEncode(requiredScope)), Encoding.UTF8, "application/x-www-form-urlencoded");

client.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue(
                "Basic",
                Convert.ToBase64String(
                System.Text.ASCIIEncoding.ASCII.GetBytes(
                string.Format("{0}:{1}", applicationId, appSecretKey))));

HttpResponseMessage response = client.PostAsync("connect/token", data).Result;

没有日志,我完全迷路了。 我应该在哪里寻找更多信息进行调试?

找到解决方案。 像godaddy这样的共享主机不支持基本身份验证。 因此,访问令牌的请求在服务器级别被拒绝。 这就是为什么没有生成日志文件的原因。

要变通解决此问题,我必须在ISecretParser上实现自己的版本。 在此实现中,我解析了自己的身份验证标头

例如,身份验证MyAuth ClientID:ClientSecret

然后向IdentityServerServiceFactory注册该解析器,它的工作原理就像魅力。

我希望该解决方案能够帮助其他尝试在共享服务器上托管IdentiyServer3的人。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM