【问题标题】:OpenIdConnectAuthenticationHandler: message.State is null or emptyOpenIdConnectAuthenticationHandler:message.State 为 null 或为空
【发布时间】:2016-11-30 19:08:55
【问题描述】:

我正在使用 ASP.Net Core 应用程序的 UseOpenIdConnectAuthentication 中间件来针对戴尔云访问管理器令牌提供程序进行身份验证(设置为提供 OpenId/OAuth2 身份验证)。以下是代码:

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AutomaticAuthenticate = true,
            AutomaticChallenge = true,
            AuthenticationScheme = "ClientCookie",
            CookieName = CookieAuthenticationDefaults.CookiePrefix + "ClientCookie",
            ExpireTimeSpan = TimeSpan.FromMinutes(5),
            LoginPath = new PathString("/signin"),
            LogoutPath = new PathString("/signout")
        });

        app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
        {
            RequireHttpsMetadata = false,
            SaveTokens = true,
            ClientId = "XYZClient_Id",
            ClientSecret = "XYZ_ClientSecret",
            ResponseType = OpenIdConnectResponseType.Code,
            PostLogoutRedirectUri = "https://example.com",
            Configuration = new OpenIdConnectConfiguration {
                AuthorizationEndpoint = "https://CAM.COM/CloudAccessManager/RPSTS/OAuth2/Default.aspx",
                TokenEndpoint = "https://CAM.COM/CloudAccessManager/RPSTS/OAuth2/Token.aspx",
                UserInfoEndpoint = "https://CAM.COM/CloudAccessManager/RPSTS/OAuth2/User.aspx",
                Issuer= "urn:CAM.COM/CloudAccessManager/RPSTS",
            }
        });

但我现在被困在一个点上几个小时。我收到以下错误:

SecurityTokenInvalidSignatureException:IDX10500:签名验证失败。没有用于验证签名的安全密钥

我在 url 查询字符串中获取代码和状态 https://example.com/signin-oidc?code=somecode&state=somestate

感谢任何类型的指导。


更新 添加了颁发者签名密钥:

TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetValue<string>("AppSettings:ClientSecret")))
                }

【问题讨论】:

    标签: c# asp.net-core asp.net-identity openid-connect oauth2


    【解决方案1】:

    您看到的错误是由于您没有使用 OIDC 中间件提供的 OpenID Connect provider configuration discovery feature 造成的,该中间件允许它检索用于签署身份令牌的加密密钥。

    如果您的提供商支持此功能,请删除整个 Configuration 节点并改为设置 Authority。所有端点都应该自动为您注册。

    如果它不支持此功能,您必须手动将签名密钥添加到OpenIdConnectOptions.TokenValidationParameters.IssuerSigningKeys

    【讨论】:

    • 这节省了我很多时间,并且可以开始手动添加签名密钥,因为我的提供商不提供配置发现端点。也感谢您的即时回复
    • 如果我收到相同的错误消息但没有UseOpenIdConnectAuthentication 而是在我的AddAuthentication() 上使用AddMicrosoftIdentityWebApp 怎么办?这就是基于 Azure 且今天推荐的 MIP(Microsoft 身份平台)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    • 2013-11-26
    相关资源
    最近更新 更多