OpenIdConnectAuthenticationHandler:message.State为空或空字符串

10

我正在为ASP.Net Core应用程序使用UseOpenIdConnectAuthentication中间件来对接Dell Cloud访问管理器令牌提供程序(设置为提供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")))
                }
3个回答

11
你看到的错误是由于你没有使用OIDC中间件提供的OpenID Connect提供者配置发现功能,它允许中间件检索用于签署身份令牌的加密密钥。
如果你的提供者支持此功能,请删除整个Configuration节点,并设置Authority。所有端点都应自动注册。
如果不支持此功能,则必须手动将签名密钥添加到OpenIdConnectOptions.TokenValidationParameters.IssuerSigningKeys中。

这节省了我很多时间,因为我的提供商没有提供配置发现端点,所以我可以开始手动添加签名密钥。还要感谢您的即时回复。 - CodeZero
12
如果我收到相同的错误信息,但没有使用 UseOpenIdConnectAuthentication,而是在 AddAuthentication() 中使用 AddMicrosoftIdentityWebApp,那该怎么办?这是基于 Azure 的、今天推荐的 MIP(Microsoft Identity Platform)。 - Konrad Viltersten

0

当作用域错误时,我遇到了这个错误,为了修复它,我在末尾添加了.default

"Scopes": "https://Company.onmicrosoft.com/OAuth2.POC.MicroServiceAPI/.default"

0
这个错误意味着您的OpenID Connect提供商在其响应中没有发送一个名为state的参数。然而,如果在发送给OpenID Connect提供商的请求URL中包含了state参数,那么它是一个必需的参数(请参考这些文档)。
如果OpenID Connect提供商按预期工作,那就意味着登录请求URL中没有发送state值。在我的情况下,这是因为我使用了错误的登录请求URL,并在OpenIdConnectOptions.Events.OnRedirectToIdentityProvider中修改了我的后端响应。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接