gpt4 book ai didi

oauth - 在 ASP.NET Core 2.0 中设置 LinkedIn/OAuth 身份验证

转载 作者:行者123 更新时间:2023-12-04 12:45:16 24 4
gpt4 key购买 nike

我正在尝试将 LinkedIn 身份验证添加到我的 ASP.NET Core 2.0 应用程序,但收到以下错误:

No authentication handler is configured to handle the scheme: LinkedIn



以下是我在 ConfigureServicesStartup.cs 中添加 LinkedIn/OAuth 身份验证的方法:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie("internal_cookie", options => {
options.AccessDeniedPath = "/Account/Forbidden/";
options.LoginPath = "/Account/Login";
})
.AddCookie("external_cookie")
.AddOAuth("LinkedIn", options => {

options.SignInScheme = "external_cookie";
options.ClientId = "1234567890";
options.ClientSecret = "1234567890";
options.CallbackPath = "/linkedin-callback";

options.AuthorizationEndpoint = "https://www.linkedin.com/oauth/v2/authorization";
options.TokenEndpoint = "https://www.linkedin.com/oauth/v2/accessToken";
options.UserInformationEndpoint = "https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url,picture-urls::(original))";

options.Scope.Add("r_basicprofile");
options.Scope.Add("r_emailaddress");

options.Events = new OAuthEvents
{
OnCreatingTicket = OnCreatingTicketLinkedInCallBack,
OnTicketReceived = OnTicketReceivedCallback
};
})
.AddFacebook(options =>
{
options.AppId = "1234567980";
options.AppSecret = "1234567890";
options.Events = new OAuthEvents
{
OnCreatingTicket = OnCreatingTicketFacebookCallback,
OnTicketReceived = OnTicketReceivedCallback
};
})
.AddGoogle(options =>
{
options.ClientId = "1234567890";
options.ClientSecret = "1234567890";
options.CallbackPath = "/google-callback";
options.Events = new OAuthEvents
{
OnCreatingTicket = OnCreatingTicketGoogleCallback,
OnTicketReceived = OnTicketReceivedCallback
};
});

我的错误在哪里?

更新:
进行建议的更正后,我现在收到以下错误:

No IAuthenticationSignInHandler is configured to handle sign in for the scheme: social_login

最佳答案

您将与您的自定义 LinkedIn 处理程序注册关联的身份验证方案与 OAuthHandler 的登录方案混合在一起。最终将调用以保持身份(通常是 cookie 处理程序实例)。

修复您的注册以指定 LinkedIn作为方案和social_login作为登录方案(假设您的 cookie 处理程序确实命名为 social_login ),它应该可以工作:

services.AddAuthentication()
.AddCookie("social_login")
.AddOAuth("LinkedIn", options =>
{
options.SignInScheme = "social_login";

// ...
});

注意:您可以删除 SignInScheme赋值 if social_login是默认登录方案(即,如果您调用 services.AddAuthentication("social_login")services.AddAuthentication(options => options.DefaultSignInScheme = "social_login") :
services.AddAuthentication("social_login")
.AddCookie("social_login")
.AddOAuth("LinkedIn", options =>
{
// ...
});

关于oauth - 在 ASP.NET Core 2.0 中设置 LinkedIn/OAuth 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45777071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com