简体   繁体   English

尝试使用来自 .NET 核心 Web 应用程序的 OpenIDConnect 进行身份验证时无效 scope

[英]Invalid scope when trying to authenticate using OpenIDConnect from a .NET Core Web App

So I am having an rather unusual issue when trying to setup OpenIDConnect inside a .NET Core App for authentication.因此,当我尝试在 .NET 核心应用程序中设置 OpenIDConnect 以进行身份验证时,我遇到了一个相当不寻常的问题。

I have ran a test using Okta and everything was working fine but then when switching the details to au.neticate using a different service I am getting the following error.我已经使用 Okta 进行了测试并且一切正常,但是当使用不同的服务将详细信息切换到 au.neticate 时,我收到以下错误。

OpenIdConnectProtocolException: Message contains error: 'invalid_scope', error_description: 'The requested scope is invalid, unknown, malformed, or exceeds that which the client is permitted to request.', error_uri: 'error_uri is null'.

Everything looks to be set correctly in the Program.cs file with the following一切看起来都在 Program.cs 文件中正确设置了以下内容

.AddOpenIdConnect(o =>
{
    o.SignInScheme = "Cookies";
    o.ClientId = config.GetSection("SsoConfig:ClientId").Value;
    o.ClientSecret = config.GetSection("SsoConfig:ClientSecret").Value;
    o.Authority = config.GetSection("SsoConfig:Authority").Value;
    o.SignedOutRedirectUri = config.GetSection("SsoConfig:SignedOutRedirectUri").Value;
    o.ResponseType = "code";
    o.Scope.Add("openid");
    o.Scope.Add("profile")
}

Any ideas what might cause this error?任何想法可能会导致此错误? From what I can see everything is setup correctly and when using Okta it works but the other provider we are switching to it is failing with the above error.据我所知,一切都已正确设置,并且在使用 Okta 时它可以正常工作,但我们切换到它的其他提供商因上述错误而失败。 It is a 3rd party service used by a client that we have having to connect to so we have provided the same details I entered on Okta so I know they should work.这是我们必须连接到的客户端使用的第 3 方服务,因此我们提供了我在 Okta 上输入的相同详细信息,因此我知道它们应该可以工作。

Maybe I have missed something obvious but the documentation shows the above as the way to do it.也许我错过了一些明显的东西,但文档显示了上面的方法。

For reference it is a .NET 6 Core Web App and the library I am using is Microsoft.AspNetCore.Authentication.OpenIdConnect (6.0.9)作为参考,它是一个 .NET 6 Core Web 应用程序,我使用的库是 Microsoft.AspNetCore.Authentication.OpenIdConnect (6.0.9)

Many thanks.非常感谢。

Although, I am very late to answer this, but I also faced the same issue today while authenticating with AWS Cognito.虽然,我回答这个问题已经很晚了,但我今天在使用 AWS Cognito 进行身份验证时也遇到了同样的问题。

I found that AddOpenIdConnect method adds 2 two scopes by default - openid & profile , and that creates the problem.我发现AddOpenIdConnect方法默认添加了 2 个两个范围 - openid & profile ,这就产生了问题。

在此处输入图像描述

As a solution, I just cleared the default scopes and added the required ones manually.作为解决方案,我只是清除了默认范围并手动添加了所需的范围。

.AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme , options =>
{
    .
    .
    .
    options.Scope.Clear();
    options.Scope.Add("openid");
    options.Scope.Add("email");
    options.Scope.Add("phone");
});

暂无
暂无

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

相关问题 从 CRM 导航时使用单点登录验证 .net 核心 Web 应用程序 - Authenticate .net core Web App using Single Sign on while navigating from CRM 使用OpenIDConnect和Session []变量的ASP.NET Framework v4 App将不会对第二个会话进行身份验证 - ASP.NET Framework v4 App using OpenIDConnect and Session[] variables will not authenticate the second session 如何通过 IdentityServer4 将 OpenIdConnect 添加到 ASP.NET Core ServerSide Blazor Web 应用程序? - How to add OpenIdConnect via IdentityServer4 to ASP.NET Core ServerSide Blazor web app? 尝试从 ASP.NET Core 5 Web 应用程序运行 Api 控制器功能时找不到 404 - 404 not found when trying to run Api Controller function from ASP.NET core 5 web app .net核心中的多个OpenIdConnect授权 - Multiple OpenIdConnect authorization in .net core 当应用程序 A 的身份验证失败时,.NET OpenIdConnect 重新向应用程序 B 进行身份验证 - .NET OpenIdConnect reauthenticate to App B when authentication failed for App A 如何.Net Core 应用程序可以从 Expressjs session 进行身份验证? - How .Net Core app can authenticate from Expressjs session? 使用 OpenIdConnect 的 Azure Active Directory 的访问令牌无效 - Invalid access token from Azure Active Directory using OpenIdConnect 在asp.net中使用Saml 2.0对Web应用程序进行身份验证 - Authenticate web app Using Saml 2.0 in asp.net 使用OpenIdConnect和Azure AD对CORS请求进行身份验证 - Authenticate CORS request using OpenIdConnect and Azure AD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM