我正在使用一個ASP.NET MVC 5
網絡應用程序。我需要提供用戶登錄他們的LinkedIn
帳戶。 MVC 5爲Facebook和Google提供登錄支持。但是我對LinkedIn如何實現這一點並不清楚。LinkedIn登錄ASP.NET MVC 5應用程序
在MVC 5中,LinkedIn沒有任何Katana支持。我應該採取什麼方法在MVC 5中實現這種特定行爲?任何建議將不勝感激。謝謝。
我正在使用一個ASP.NET MVC 5
網絡應用程序。我需要提供用戶登錄他們的LinkedIn
帳戶。 MVC 5爲Facebook和Google提供登錄支持。但是我對LinkedIn如何實現這一點並不清楚。LinkedIn登錄ASP.NET MVC 5應用程序
在MVC 5中,LinkedIn沒有任何Katana支持。我應該採取什麼方法在MVC 5中實現這種特定行爲?任何建議將不勝感激。謝謝。
終於找到了一種成功地做到這一點..!我複製了用於在Owin/Katana中執行Facebook身份驗證的代碼。你可以在這裏找到它。
我複製所有文件,並在下面的圖片中紅色方框內指定的文件夾。
在我自己的MVC 5 Web應用程序項目粘貼他們,我需要實現LinkedIn認證。將所有類更名爲LinkedIn而不是Facebook。
然後,我改變了代碼,使其適應LinkedIn。
LinkedInAuthenticationHandler類
private const string TokenEndpoint = "https://www.linkedin.com/uas/oauth2/accessToken";
private const string GraphApiEndpoint = "https://api.linkedin.com/v1/people/~";
改變此密碼ApplyResponseChallengeAsync方法內。
string authorizationEndpoint =
"https://www.linkedin.com/uas/oauth2/authorization" +
"?response_type=code" +
"&client_id=" + Uri.EscapeDataString(Options.AppId) +
"&redirect_uri=" + Uri.EscapeDataString(redirectUri) +
"&scope=" + Uri.EscapeDataString(scope) +
"&state=" + Uri.EscapeDataString(state);
LinkedInAuthenticationOptions類
CallbackPath = new PathString("/signin-linkedin");
然後去Startup.Auth.cs文件App_Start文件夾中的項目,並在其中添加此代碼。
app.UseLinkedInAuthentication(
APIKey: "...YourLinkedInAPIKeyHere...",
SecretKey: "...YourLinkedInSecretKeyHere..."
);
也向LinkedIn API提供您的應用程序詳細信息。你可以從這裏閱讀更多關於它的細節。
這就是全部。祝你好運!
這不是特定於MVC 5,但是這裏有幾條鏈接,介紹如何實現LinkedIn oAuth。
Custom oAuth LinkedIn Provider
DotNetOpenAuth for MVC
,使用LinkedIn
而且,我只是碰到這種來到SO,LinkedIn full profile details using DotNetOpenAuth in MVC4
自從OP以來已經過去了一段時間,恕我直言,更直接的解決方案將用於Owin.Security.Providers
NuGet package。
將包裝添加到您的解決方案後,使用LinkedIn作爲提供商非常簡單,如the author blog的解釋。
而且,在這樣的事實,該項目是open sourced頂部,獎金就是你在同一時間進行其他認證供應商,如GitHub上,雅虎或StackExchange的支持:O)