簡體   English   中英

在 ASP .NET Core 3.1 中使用 Linkedin 注冊/登錄

[英]Register/Login with Linkedin in ASP .NET Core 3.1

我正在為我的 web 項目使用 ASP .NET Core 3.1 個人身份驗證模板。 我正在嘗試集成 LinkedIn 外部登錄,但不知道如何正確執行。

我使用以下鏈接尋求幫助: OAuth LinkedIn 集成

這是我的代碼:

services.AddAuthentication()
            .AddOAuth("LinkedIn", "LinkedIn", options =>
            {
                IConfigurationSection linkedinAuthNSection =
                Configuration.GetSection("Authentication:Linkedin");

                options.ClientId = linkedinAuthNSection["ClientId"];
                options.ClientSecret = linkedinAuthNSection["ClientSecret"];

                options.CallbackPath = new PathString("/signin-linkedin");
                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,formatted-name,email-address,picture-url)";
                options.Scope.Add("r_liteprofile");
                options.Scope.Add("r_emailaddress");
                options.Scope.Add("w_member_social");
            });

但我在OnGetCallbackAsync處理程序中遇到錯誤:

var info = await _signInManager.GetExternalLoginInfoAsync();

收到info的值null

After trying multiple options i just found a github repo and nuget package for linkedin external login and it is working perfectly without any extra code just like Microsoft official documentation for Google and Facebook Login.

我的代碼:

services.AddAuthentication()
            .AddLinkedIn(options =>
            {
                IConfigurationSection linkedinAuthNSection =
                Configuration.GetSection("Authentication:Linkedin");

                options.ClientId = linkedinAuthNSection["ClientId"];
                options.ClientSecret = linkedinAuthNSection["ClientSecret"];
            });

Nuget Package: AspNet.Security.OAuth.LinkedIn

Github 回購: AspNet.Security.OAuth.Providers

超過 60 個提供商集成可用,包括 Instagarm、Dropbox、Soundcloud 等。完整列表可在 github 鏈接中找到。

只需將AspNet.Security.OAuth.Providers中的Providers替換為您想要的提供程序名稱。 一些例子是:

Instagram:AspNet.Security.OAuth.Instagram

Dropbox: AspNet.Security.OAuth.Dropbox

蘋果: AspNet.Security.OAuth.Apple

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM