我正在创建一个 ASP.NET Core MVC 应用程序,它使用 Okta 进行身份验证。我遇到了一个非常奇怪的问题。我的 Okta 沙箱运行良好,但当我切换到 Okta Production 时,出现以下错误:
IOException:IDX20807:无法从以下位置检索文档:“[‘System.String’类型的 PII 已隐藏。有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII。]'。 HttpResponseMessage:“[‘System.Net.Http.HttpResponseMessage’类型的 PII 已隐藏。有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII。]', HttpResponseMessage.Content: '['System.String' 类型的 PII 已隐藏。有关更多详细信息,请参阅 https://aka.ms/IdentityModel/PII。]'。
我在 Okta 生产中设置的应用程序完全相同,但它会导致问题。请注意,当我切换到不同的 Okta 集成时,我仅更改
appSettings.json
中的 Okta 值(颁发者、clientId、clientSecret 和权限)。
//appsettings.json
"Okta": {
"Issuer": "https://Domain/oauth2/default",
"ClientId": "hidden",
"ClientSecret": "hidden",
"CallbackPath": "/okta-auth",
"Authority": "https://Domain/oauth2/default"
}
Startup.cs
- ConfigureServices
方法:
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddAuthorization();
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "okta";
})
.AddCookie(options =>
{
})
// let users sign in with okta account
.AddOpenIdConnect("okta", options =>
{
options.Authority = Configuration["Okta:Authority"];
options.ClientId = Configuration["Okta:ClientId"];
options.ClientSecret = Configuration["Okta:ClientSecret"];
options.CallbackPath = Configuration["Okta:CallbackPath"];
options.ResponseType = OpenIdConnectResponseType.Code;
});
}
注意:我的
Program.cs
也使用app.UseAuthorization();
,app.UseAuthorization();
。
我真的不明白是什么原因造成的。
我明白了!!
所以这是因为我已将 /oauth2/default 附加到权限,并且我没有为此付费的功能。删除它解决了我的问题。