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



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

当我在本地开发计算机上运行 IdentityServer3 时,它工作正常,但是当我在共享服务器上托管它时,我收到 401 错误。我正在尝试使用端点连接\令牌访问令牌。下面是身份服务器3的配置

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 的人。

最新更新