![](/img/trans.png)
[英]IdentityServer4 always return 401 Unauthorized or 403 Forbidden
[英]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.