20

我知道这个问题已经得到解答,但我不明白人们到底在做什么(关于证书,ssl),他们都使用本地主机,但不是我。

我将此示例用作我的示例OpenIdConnect

我在用着:

  • 一个网络应用
  • 一个网络 API

两者都使用 .Net Core 2.1。Web 应用正在使用 Azure AD 连接来获取 JwtBearer 令牌,该令牌将发送到 API。

在 API 中看到路由/api/information,从 Web App 向 API 发送请求,API 正在返回上述错误。

确切的错误是:

System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://<mycompany>.onmicrosoft.com/<big Guid of 72 chars>/.well-known/openid-configuration'.

因此,我尝试通过添加证书、添加必要的库(System.Net.Httpv4.3.3)、检查 Azure AD 中的每个权限来解决此错误,但这些都不起作用。

如果您需要更多信息,我可以通过在这篇文章中添加它们来提供它们。

4

8 回答 8

9

如果有人遇到此问题并且正在使用 Azure B2C,则该实例是您的 azure b2c 租户的根 URL。例如https://myroot.b2clogin.com/。域应该是: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"
    }
}
于 2020-06-02T22:48:02.917 回答
7

通过替换解决它,在appsettings.json

"AzureAd": {
     "Instance": "<APP_Uri_from_Azure_Portal>",
...
}

"AzureAd": {
     "Instance": "https://login.microsoftonline.com/",
...
}
于 2018-06-07T14:44:22.337 回答
1

正如@juunas 上述评论之一所述,身份验证处理程序在启动时加载此配置文件以加载其配置以验证身份提供者提供的令牌。

文件路径端点也可以在应用注册部分找到。如果您转到应用注册 => 概述 => 端点,则查找 OpenID Connect 配置端点 (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",

               },
于 2020-06-05T11:16:49.140 回答
1

通过在Startup-->Configure中添加以下代码解决了该问题

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls 
                                       | SecurityProtocolType.Tls11
                                       | SecurityProtocolType.Tls12
                                       | SecurityProtocolType.Ssl3;
于 2021-04-02T15:54:55.850 回答
1

对我来说,问题与防火墙/网络相关 - 当我在浏览器中键入 /.well-known/openid-configuration URL 时,我可以访问它,但 API 本身不能(API 和 Identity Server 托管在相同的应用程序)。API 托管在 Azure 中,我创建了一个出站安全规则(用于与子网关联的网络安全组,该子网已集成到我的 API 所属的应用程序服务计划中)阻止 API 调用任何其他应用程序其应用服务计划中的服务,包括其自身。添加一个新的出站安全规则以允许解决我的问题(我意识到这导致了与提交者非常相似的错误,但出于不同的原因,并且更像是一个边缘情况 - 很可能没有这样的限制设置)。

于 2021-04-27T02:34:48.230 回答
0

就我而言,我的 appSettings 中缺少授权密钥。

"AzureAdB2C": {
    "Instance": "https://login.microsoftonline.com",
    "Authority": "https://login.microsoftonline.com/<your tenant id>",
    "ClientId": "...",
    "TenantId": "...",
    "Domain": "https://<your name>.b2clogin.com",
    "SignedOutCallbackPath": "/signout/B2C_1_susi",
    "SignUpSignInPolicyId": "b2c_1_susi",
    "ResetPasswordPolicyId": "b2c_1_reset",
    "EditProfilePolicyId": "b2c_1_edit_profile",
    "CallbackPath": "/signin-oidc"
  }
于 2021-09-22T02:53:14.450 回答
0

添加到@AmirAli 的答案。

msidentity-app-sync tool在.NET 6中使用该工具后,我的错误如下所示:

https://github.com/AzureAD/microsoft-identity-web/blob/master/tools/app-provisioning-tool/vs2019-16.9-how-to-use.md

System.InvalidOperationException:IDX20803:无法从以下位置获取配置:“https://login.microsoftonline.com/<myAD>.onmicrosoft.com/B2C_1_signupsignin/v2.0/.well-known/openid-configuration”

从默认更改AzureAd:Instance为然后它工作。appsettings.jsonhttps://login.microsoftonline.com/https://<myAD>.b2clogin.com/

于 2022-01-31T11:22:14.293 回答
-1

在我的情况下,https://.b2clogin.com 被防火墙阻止了,并且错误消息完全相同,因此允许 URL(通过修改防火墙规则)允许服务器访问https://xxxx.b2clogin。 com解决了这个问题。我希望它有帮助

于 2021-11-25T08:09:27.507 回答