【问题标题】:.Net Core OpenIDConect using third party provider.Net Core OpenID Connect 使用第三方提供商
【发布时间】:2021-11-01 07:48:09
【问题描述】:

我在 .Net core 3.1 上,使用 OpenIDConnect 进行身份验证,这是我的 startup.cs

  public void ConfigureServices(IServiceCollection services)
        {
           
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
           .AddCookie()
           .AddOpenIdConnect("test",o =>
           {
               o.SignInScheme = "Cookies";
               o.SignOutScheme = "Cookies";
               o.ClientId = "test";
               o.ClientSecret = "gs";
               o.Authority = "https://test";
               o.ResponseType = OpenIdConnectResponseType.CodeIdToken;
             o.MetadataAddress = "https://test/.well-known/openid-configuration";
              o.SaveTokens = true;
               o.GetClaimsFromUserInfoEndpoint = true;
               o.Scope.Add("openid");
               o.Scope.Add("profile");
           });


            services.AddControllersWithViews();
            services.AddRazorPages();
        }

这是我的 Home 控制器和动作 Login with [Authorize] 属性

 [Authorize]
    public IActionResult Login()
    {
      
        return View();
    }

登录按钮位于主文件夹 Index.cshtml

<a asp-controller="Home" asp-action="Login" target="_self" role="menuitem" class="btn btn-primary" type="button" id="btnLogin" aria-label="Log in to your account">LogIn</a>

当我点击登录按钮时,这是错误:

没有找到该网址的网页:https://localhost:34343/Account/Login?ReturnUrl=%2FHome%2FLogin

为什么要进入帐户/登录?

【问题讨论】:

    标签: c# .net-core model-view-controller openid-connect


    【解决方案1】:

    尝试替换

    options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    

    通过

    options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
    

    【讨论】:

    • no-authenticationscheme-was-specified-and-there-was-no-defaultchallengescheme,这是错误
    • 无法让 OpenID 与第三方身份服务器一起工作。有什么建议吗?
    • 所以添加这个:options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    • 这是错误消息“InvalidOperationException:未指定 authenticationScheme,并且未找到 DefaultChallengeScheme。可以使用 AddAuthentication(string defaultScheme) 或 AddAuthentication(Action configureOptions) 设置默认方案。”
    • 这就是我的 startup.cs 的样子 services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; } )
    猜你喜欢
    • 2012-05-16
    • 2017-10-14
    • 2021-04-19
    • 1970-01-01
    • 2021-03-10
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多