如何在asp.net mvc 4中实现社交登录?

5

我希望使用oauth与Facebook、Twitter、Google等实现基于角色的登录。它将仅使用oauth并具有角色系统,而不是具有常规注册和登录的默认模板。似乎dot net open auth将有助于初始工作,但我找不到使用或扩展它的好例子。有人能解释如何从头开始使用dotnet open auth以及如何获取额外信息吗?


3
文档非常详尽(并且链接在 AuthConfig.cs 文件中!http://go.microsoft.com/fwlink/?LinkID=252166)。 - Iain Galloway
2个回答

10
  1. 启动 Visual Studio 2012
  2. 使用Internet模板创建新的ASP.NET MVC 4应用程序
  3. 打开~/App_Start/AuthConfig.cs文件
  4. 取消对要使用的提供程序进行注释,为相应的提供程序放置客户端密钥和密钥

有关OAuth集成的更多信息,请访问DotNetOpenAuth网站,查看文档,并下载和尝试示例。


我知道MVC 4在Internet Application模板中提供了这些功能。我只需要社交登录,而不需要通常的“创建账户”方式。我还需要从网站上获取更多信息,例如电子邮件、用户名等。 - Sakibul Alam
1
嘿,Darin Dimitrov,如果我想打开一个空项目,如何实现Facebook登录/创建/更新/删除用户?你有例子吗? - hackp0int

0
打开 ~/App_Start/AuthConfig.cs 文件并使用 this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Web.WebPages.OAuth;

namespace MVCTemplateProject
{
    public static class AuthConfig
    {
        public static void RegisterAuth()
        {

            OAuthWebSecurity.RegisterMicrosoftClient(
               clientId: "code",
                clientSecret: "code");

            //OAuthWebSecurity.RegisterTwitterClient(
            //    consumerKey: "",
            //    consumerSecret: "");

            //OAuthWebSecurity.RegisterFacebookClient(
            //    appId: "",
            //    appSecret: "");
            OAuthWebSecurity.RegisterLinkedInClient("code", "code");
            OAuthWebSecurity.RegisterGoogleClient();
        }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接