来自谷歌和Facebook通过OWIN GetExternalLoginInfoAsync获取基本信息() [英] Getting Basic Info from Google and Facebook through OWIN GetExternalLoginInfoAsync()

查看:304
本文介绍了来自谷歌和Facebook通过OWIN GetExternalLoginInfoAsync获取基本信息()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的另一个MVC假人,并试图为我即将开展的项目工作了外部登录。我使用的是默认的MVC模板自带的VS2013。以下具体步骤为<一说后, href=\"http://www.asp.net/mvc/tutorials/mvc-5/create-an-aspnet-mvc-5-app-with-facebook-and-google-oauth2-and-openid-sign-on\"相对=nofollow> OWIN教程。我的问题是,当用户从谷歌或Facebook或其他外部帐户登录,他希望不要再把他的信息。在code我找到了实现通过Facebook和谷歌登录,它只是获取的用户名是无用的。我的意思是,我知道它的工作仍然然后但如果我想获得它的Facebook已经告诉我将访问用户的基本信息。这是我在成功登录后得到的答复。有没有办法用这个来获取基本信息。

I am another MVC dummy and trying to work out external logins for my upcoming projects. I am using the default MVC template for that comes with VS2013. After following the exact steps as told in OWIN tutorial . The problem I have is that when a user is logging in from Google or Facebook or any other external account, he expects not to put his information again. The code I found for enabling logging in through Facebook and Google, it just fetches the username which is useless. I mean i know it would work still then but what if I want to get the basic information which facebook had already told the user I would be accessing. This is what I get in reply after successful login. Is there a way to get the basic information using this.

加法:
我还包括来自Facebook的的NuGet包,并能得到通过以下code一些信息。现在的问题归结为,如何我询问用户不是代表他只是正常的信息发布如越多,获得的职位等使用此OWIN的音乐库。

ADDITION: I also included Facebook package from Nuget and was able to get some info through the following code. NOW THE PROBLEM comes down to, how to I ask the user for more than just normal info eg posting on his behalf, getting posts etc using this OWIN's library.

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
        if (loginInfo.Login.LoginProvider.ToLower() == "facebook")
        {
            var accessToken = "something";
            var client = new FacebookClient(accessToken);
            dynamic me = client.Get(loginInfo.DefaultUserName);
        }

推荐答案

您可以通过添加作用域请求初始登录时,做到这一点。
这里是一个很好的样本解释<一个href=\"http://blogs.msdn.com/b/webdev/archive/2013/10/16/get-more-information-from-social-providers-used-in-the-vs-2013-project-templates.aspx\"相对=nofollow>这里

You can do it by adding Scopes when requesting the initial login. There is an excellent sample is explained here

code的位:

List<string> scope = newList<string>() { "email", "user_about_me", "user_hometown", "friends_about_me", "friends_photos" };
 var x = newFacebookAuthenticationOptions();
 x.Scope.Add("email");
 x.Scope.Add("friends_about_me");
 x.Scope.Add("friends_photos");
 x.AppId = "636919159681109";
 x.AppSecret = "f3c16511fe95e854cf5885c10f83f26f";
 x.Provider = newFacebookAuthenticationProvider()
{
    OnAuthenticated = async context =>
    {
         //Get the access token from FB and store it in the database and
        //use FacebookC# SDK to get more information about the user
        context.Identity.AddClaim(
        new System.Security.Claims.Claim("FacebookAccessToken",
                                             context.AccessToken));
    }
};
 x.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
 app.UseFacebookAuthentication(x);

这篇关于来自谷歌和Facebook通过OWIN GetExternalLoginInfoAsync获取基本信息()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆