【问题标题】:How to use the .NET 4.5 Owin to Authenticate with LinkedIn如何使用 .NET 4.5 Owin 通过 LinkedIn 进行身份验证
【发布时间】:2014-05-27 12:38:41
【问题描述】:

.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();
        }
    }
}

【问题讨论】:

  • 如果有人能这么好心地祝福这个社区并解决我的问题,那将是非凡的。
  • 你想用 twitter 验证,还是做更多的事情(发布等)?
  • 我只是担心LinkedIN
  • 使用nuget获取全系列Owin.Security.Providers github.com/owin-middleware/OwinOAuthProviders

标签: c# .net oauth linkedin


【解决方案1】:

我不确定“内置”...但您可以使用 nuget 获取另一个 OWIN 包。

查看这个网站Introducing the Yahoo and LinkedIn OAuth security providers for OWIN 以获得非常简单的教程。

简而言之:

  1. 使用 nuget 安装此包:Owin.Security.Providers
  2. LinkedIn Developers注册LinkedIn开发者帐户
  3. 请求 API 密钥。填写完成后记下 API 密钥和 Secret Key
  4. 编辑您的 App_Start\Startup.Auth.cs 文件以包含“使用 Owin.Security.Providers.Linkedin”
  5. 在该文件的底部,为 LinkedIn 添加一个部分:

        app.UseLinkedInAuthentication(new LinkedInAuthenticationOptions() 
        {
            ClientId = "API Key",
            ClientSecret = "Secret Key",
        });
    

【讨论】:

  • 虽然这在理论上可以回答问题,it would be preferable 在这里包含答案的基本部分,并提供链接以供参考。
猜你喜欢
  • 2017-12-17
  • 2014-11-22
  • 2018-08-30
  • 2018-12-20
  • 2015-09-23
  • 2023-03-07
  • 2017-05-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多