简体   繁体   English

Azure b2c 错误:IDX10501:签名验证失败。 无法匹配密钥:孩子:'gLv****************'

[英]Azure b2c error: IDX10501: Signature validation failed. Unable to match key: kid: 'gLv****************'

I am authenticating asp.net mvc app against azure b2c, following startup.cs file code details:我正在针对 azure b2c 验证 asp.net mvc 应用程序,遵循 startup.cs 文件代码详细信息:

public void ConfigureAuth(IAppBuilder app)
        {
            IdentityModelEventSource.ShowPII = true;
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    // Generate the metadata address using the tenant and policy information
                    MetadataAddress = String.Format(Globals.WellKnownMetadata, Globals.Tenant, Globals.DefaultPolicy),

                    // These are standard OpenID Connect parameters, with values pulled from web.config
                    ClientId = Globals.ClientId,
                    RedirectUri = Globals.RedirectUri,
                    PostLogoutRedirectUri = Globals.RedirectUri,

                    // Specify the callbacks for each type of notifications
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {
                        RedirectToIdentityProvider = OnRedirectToIdentityProvider,
                        AuthorizationCodeReceived = OnAuthorizationCodeReceived,
                        AuthenticationFailed = OnAuthenticationFailed,
                    },

                    // Specify the claim type that specifies the Name property.
                    TokenValidationParameters = new TokenValidationParameters
                    {
                        NameClaimType = "name",
                        ValidateIssuer = false

                    },

                    // Specify the scope by appending all of the scopes requested into one string (separated by a blank space)
                    Scope = $"openid profile offline_access {Globals.ReadTasksScope} {Globals.WriteTasksScope}"
                });
}

Its giving below error when using custom policy: IDX10501: Signature validation failed.使用自定义策略时出现以下错误:IDX10501:签名验证失败。 Unable to match key: kid: 'gL****************'.无法匹配密钥:kid:'gL****************'。 Exceptions caught: ''.捕获的异常:''。 token: typ":"JWT","alg":"RS256","kid":"gL****************"}. {"exp":1599625561,"nbf":1599621961,"ver":"1.0","iss":......................}令牌:typ":"JWT","alg":"RS256","kid":"gL****************"}。{"exp":1599625561," nbf":1599621961,"ver":"1.0","iss":................................}

I have verified this key and token exactly same as I am getting from https://jwt.ms .我已验证此密钥和令牌与我从https://jwt.ms获得的完全相同。 Its only throwing error while I am using custom policy, if I use built in policy its working as expected.当我使用自定义策略时,它唯一的抛出错误,如果我使用内置策略,它会按预期工作。

Any help what is missing here?任何帮助这里缺少什么?

Thanks.谢谢。

As confirmed, it was problem with Signing key and Encryption key in your custom policy.经确认,您的自定义策略中的签名密钥和加密密钥存在问题。 Creating both correctly fixed the issue. 创建两者都正确解决了问题。

Create the signing key创建签名密钥

  1. Select Policy Keys and then select Add.选择策略密钥,然后选择添加。
  2. For Options, choose Generate.对于选项,选择生成。
  3. In Name, enter TokenSigningKeyContainer.在名称中,输入 TokenSigningKeyContainer。 The prefix B2C_1A_ might be added automatically.前缀 B2C_1A_ 可能会自动添加。
  4. For Key type, select RSA.对于密钥类型,选择 RSA。
  5. For Key usage, select Signature.对于密钥用法,选择签名。
  6. Select Create.选择创建。

Create the encryption key创建加密密钥

  1. Select Policy Keys and then select Add.选择策略密钥,然后选择添加。
  2. For Options, choose Generate.对于选项,选择生成。
  3. In Name, enter TokenEncryptionKeyContainer.在名称中,输入 TokenEncryptionKeyContainer。 The prefix B2C_1A_ might be added automatically.前缀 B2C_1A_ 可能会自动添加。
  4. For Key type, select RSA.对于密钥类型,选择 RSA。
  5. For Key usage, select Encryption.对于密钥使用,选择加密。
  6. Select Create.选择创建。

我不得不重新创建我的签名密钥,出于某种原因,现有的密钥不适用于新政策(它仍然适用于现有政策)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AuthenticationFailed 的 Azure AD 授权错误:IDX10501:签名验证失败。 无法匹配“孩子” - Azure AD Authorize Error of AuthenticationFailed: IDX10501: Signature validation failed. Unable to match 'kid' IDX10501:签名验证失败。小孩:'[PII隐藏]',令牌:'[PII隐藏]' - Azure B2C - IDX10501: Signature validation failed. kid: '[PII is hidden]', token: '[PII is hidden]' - Azure B2C Azure AD B2C 错误 - IDX10501:签名验证失败 - Azure AD B2C error - IDX10501: Signature validation failed IDX10501:签名验证失败。 无法匹配键 - IDX10501: Signature validation failed. Unable to match keys 带有Azure B2C的ASP.NET Core 2 Jwt身份验证// IDX10500:签名验证失败。 没有提供安全密钥来验证签名 - ASP.NET Core 2 Jwt Auth with Azure B2C // IDX10500: Signature validation failed. No security keys were provided to validate the signature IDX10500:签名验证失败。 无法解析 SecurityKeyIdentifier - IDX10500: Signature validation failed. Unable to resolve SecurityKeyIdentifier 每隔一个请求 JWT 验证失败,'idx10503 签名验证失败。 令牌没有孩子' - Every other request JWT validation fails with 'idx10503 signature validation failed. token does not have a kid' IDX10503:签名验证失败。 令牌没有孩子。 键尝试:'System.Text.StringBuilder' - IDX10503: Signature validation failed. Token does not have a kid. Keys tried: 'System.Text.StringBuilder' Asp.NET 核心 3 - Azure Active Directory - 令牌验证失败 - 签名验证失败。 无法匹配密钥 - Asp.NET Core 3 - Azure Active Directory - Token Validation fails - Signature validation failed. Unable to match key IDX10500:签名验证失败。 没有提供安全密钥来验证签名 - IDX10500: Signature validation failed. No security keys were provided to validate the signature
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM