如何使用.NET 4.5 Owin使用LinkedIn进行身份验证
本文关键字:LinkedIn 身份验证 使用 Owin 何使用 NET | 更新日期: 2023-09-27 17:58:17
。NET 4.5现在有这些不同的身份验证方法,但我看不出LinkedIn有这种方法。有人知道如果。NET 4.5有一个内置的方式来使用LinkedIn进行oAuth?
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
namespace WebPageStarterKit
{
public partial class Startup {
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301883
public void ConfigureAuth(IAppBuilder app)
{
// Enable the application to use a cookie to store information for the signed in user
// and also store information about a user logging in with a third party login provider.
// This is required if your application allows users to login
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Uncomment the following lines to enable logging in with third party login providers
//app.UseMicrosoftAccountAuthentication(
// clientId: "",
// clientSecret: "");
//app.UseTwitterAuthentication(
// consumerKey: "",
// consumerSecret: "");
//app.UseFacebookAuthentication(
// appId: "",
// appSecret: "");
//app.UseGoogleAuthentication();
}
}
}
我不确定"内置"。。。但是您可以使用nuget获得另一个OWIN包。
查看此网站介绍OWIN的雅虎和领英OAuth安全提供商,了解非常直接的教程。
简而言之:
- 使用nuget安装此软件包:Owin。安全提供商
- 在LinkedIn Developers注册LinkedIn开发者帐户
- 请求API密钥。填写完表单后,请记下API密钥和密钥
- 编辑您的应用程序启动''启动。Auth.cs文件包含"使用Owin.Security.Providers.Linkedin"
-
在该文件的底部,添加一个LinkedIn:部分
app.UseLinkedInAuthentication(new LinkedInAuthenticationOptions() { ClientId = "API Key", ClientSecret = "Secret Key", });