Jwt IDX20803:无法从获取配置
我知道这个问题已经得到了回答,但我不明白人们到底在做什么(关于证书、ssl),他们都使用本地主机,而不是我 我以这个例子为例 我正在使用:Jwt IDX20803:无法从获取配置,jwt,azure-active-directory,asp.net-core-2.1,Jwt,Azure Active Directory,Asp.net Core 2.1,我知道这个问题已经得到了回答,但我不明白人们到底在做什么(关于证书、ssl),他们都使用本地主机,而不是我 我以这个例子为例 我正在使用: 网络应用程序 web API 两者都在使用.NETCore2.1。Web应用程序正在使用Azure AD连接获取发送到API的JwtBearer令牌 看到api中的路由/api/information,Web应用程序向api发送请求,api返回上述错误 确切的错误是: System.InvalidOperationException: IDX20803:
- 网络应用程序
- web API
/api/information
,Web应用程序向api发送请求,api返回上述错误
确切的错误是:
System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://<mycompany>.onmicrosoft.com/<big Guid of 72 chars>/.well-known/openid-configuration'.
System.InvalidOperationException:IDX20803:无法从以下位置获取配置:'https://.onmicrosoft.com//.well-known/openid-configuration'.
所以我试图解决这个错误,通过添加证书,添加必要的库(System.Net.Http
v4.3.3),检查Azure AD中的每个权限,但这些都不起作用
如果您需要更多信息,我可以通过在本文中添加它们来提供这些信息。通过在
appsettings.json中替换来解决此问题:
"AzureAd": {
"Instance": "<APP_Uri_from_Azure_Portal>",
...
}
如果任何人有此问题并且正在使用Azure B2C,则该实例是您的Azure B2C租户的根url。例如。域应为:myroot.onmicrosoft.com/
确保域中没有https
这对我有用
{
"AzureADB2C": {
"CallbackPath": "/signin-oidc",
"ClientId": "<app-registration-app-client-id>",
"ClientSecret": "<secret-value>",
"Domain": "<domain-name>.onmicrosoft.com/",
"EditProfilePolicyId": "B2C_1_profile",
"Instance": "https://<domain-name>.b2clogin.com/",
"ResetPasswordPolicyId": "B2C_1_reset",
"SignUpSignInPolicyId": "B2C_1_signupsignin"
}
}
{
“AzureADB2C”:{
“回调路径”:“/登录oidc”,
“ClientId”:“,
“客户机密”:“,
“域”:“.onmicrosoft.com/”,
“EditProfilePolicyId”:“B2C_1_配置文件”,
“实例”:https://.b2clogin.com/",
“ResetPasswordPolicyId”:“B2C\u 1\u reset”,
“SignupSigningPolicyId”:“B2C\u 1\u signupsignin”
}
}
正如@juunas在上面的一条评论中提到的,身份验证处理程序在启动时加载此配置文件,以加载其用于验证身份提供程序提供的令牌的配置
文件路径终点也可以在应用程序注册部分找到。如果转到应用程序注册=>Overview=>Endpoints,则查找OpenID连接配置端点(v2)
B2C身份验证处理程序的Startup.cs代码如下所示,我在appsettings中提供了这些值
services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions =>
{
jwtOptions.Authority = $"{Configuration["AzureAdB2C:Instance"]}/{Configuration["AzureAdB2C:Tenant"]}/{Configuration["AzureAdB2C:Policy"]}/v2.0/";
jwtOptions.Audience = Configuration["AzureAdB2C:ClientId"];
jwtOptions.Events = new JwtBearerEvents
{
OnAuthenticationFailed = AuthenticationFailed
};
});
"AzureAdB2C": {
"Tenant": "xxxxxxxxxb2c.onmicrosoft.com",
"Instance": "xxxxxxxxxxxb2c.b2clogin.com",
"ClientId": "xxxxxx-764c-4e4a-b0ec-xxxxxxf",
"Policy": "B2C_1_signin1",
"ScopeRead": "demo.read",
},
通过在启动-->配置中添加以下代码解决了此问题
对我来说,问题是与防火墙/网络相关的-当我在浏览器中键入/.well/openid配置URL时,我可以访问它,但API本身不能(API和Identity Server托管在同一个应用程序中)。API托管在Azure中,我创建了一个出站安全规则(用于与集成到API所属的我的应用服务计划中的子网关联的网络安全组),该规则阻止API调用其应用服务计划中的任何其他应用服务,包括其自身。添加一个新的出站安全规则以允许修复我的问题(我意识到这导致了与提交者非常相似的错误,但原因不同,更像是边缘案例-很可能没有设置此类限制)。作为解释,出现错误的原因是它试图从{instance}{tenantid}/.well-known/OpenId-configuration
下载OpenId配置文档,就像https://login.microsoftonline.com/common/.well-known/openid-configuration
。此文档包含可以从中获取令牌签名公钥的URL。身份验证处理程序在启动时加载它的配置,以验证身份提供程序提供的令牌。因此,对于Azure AD,您必须使用Azure AD实例的URL+您的租户id(或多租户的“通用”)。但由于您提供了另一个URL/URI,它当然无法找到元数据文档并崩溃。请提供您的整个AppSettings.json这似乎是正确的路径,但我想我可能还缺少其他设置。谢谢我能让它工作。使用示例appsettings.json更新。
services.AddAuthentication(options =>
{
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(jwtOptions =>
{
jwtOptions.Authority = $"{Configuration["AzureAdB2C:Instance"]}/{Configuration["AzureAdB2C:Tenant"]}/{Configuration["AzureAdB2C:Policy"]}/v2.0/";
jwtOptions.Audience = Configuration["AzureAdB2C:ClientId"];
jwtOptions.Events = new JwtBearerEvents
{
OnAuthenticationFailed = AuthenticationFailed
};
});
"AzureAdB2C": {
"Tenant": "xxxxxxxxxb2c.onmicrosoft.com",
"Instance": "xxxxxxxxxxxb2c.b2clogin.com",
"ClientId": "xxxxxx-764c-4e4a-b0ec-xxxxxxf",
"Policy": "B2C_1_signin1",
"ScopeRead": "demo.read",
},
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Ssl3;