简体   繁体   English

如何获取使用Google或Facebook登录的用户的数据

[英]How to get the data of the user who is logged in with Google or Facebook

is there a function or method in the application that takes parameters such as email addresses, names of people who log in with google or facebook?应用程序中是否有 function 或方法采用 email 地址、使用 google 登录的人名或 facebook 等参数? if there is, how is it.如果有的话,怎么样。

when I logged in with google, I could access it with the following codes.当我使用谷歌登录时,我可以使用以下代码访问它。 but I have no idea how to get their information with facebook.但我不知道如何通过 facebook 获取他们的信息。

 public class GoogleUserRequest
{
    public const string PROVIDER = "google";

    [JsonProperty("idToken")]
    [Required]
    public string IdToken { get; set; }
}



public async Task<UserApp> AuthenticateGoogleUserAsync(GoogleUserRequest request)
    {
        Payload payload = await ValidateAsync(request.IdToken, new ValidationSettings()
        {
            Audience = new[] {"GOOGLE CLİENT ID"}
        });

        return await ExternalLoginUser(GoogleUserRequest.PROVIDER, payload.Subject, payload.Email, payload.GivenName,
                payload.FamilyName);
    }

with these codes, I can keep factors such as name, email, emal verification via payload variable.使用这些代码,我可以通过有效负载变量保留名称、email、电子邮件验证等因素。 If I want to create the same with facebook (Meta) , what kind of coding should I do.如果我想用facebook (Meta)创建相同的内容,我应该做什么样的编码。

is there a function or method in the application that takes parameters such as email addresses, names of people who log in with google or facebook?应用程序中是否有 function 或方法采用 email 地址、使用 google 登录的人名或 facebook 等参数?

You can get the external login information for the current login by using SignInManager<TUser>.GetExternalLoginInfoAsync(String) method:您可以使用SignInManager<TUser>.GetExternalLoginInfoAsync(String)方法获取当前登录的外部登录信息:

public class HomeController: Controller
{
    private readonly SignInManager<IdentityUser> _signInManager;

    public ExternalLoginModel(SignInManager<IdentityUser> signInManager)
    {
        _signInManager = signInManager;
    }

    public async Task<UserApp> AuthenticateGoogleUserAsync(GoogleUserRequest request)
    {          
        var info = await _signInManager.GetExternalLoginInfoAsync();
        var name = info.Principal.Identity.Name;
        var email = info.Principal.FindFirst(ClaimTypes.Email).Value;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 ASP.Net Core Identity 3.1 从 controller 中的登录用户获取 Google 和 Facebook 个人资料图片? - How can I get Google and Facebook profile picture from logged in user in a controller with ASP.Net Core Identity 3.1? 如何使用两个不同的数据库表获取当时登录用户的描述? - how can i get the description of the user who is logged in at that moment using two different database table? 使用Facebook sdk和.Net登录用户详细信息 - get logged in user details with Facebook sdk and .Net 如何获取Facebook用户注册我的网站的个人资料照片与Facebook注册申请(不使用mvc) - How to get the profile photo of facebook user who is registered my site with facebook registration application(not using mvc) 如何判断用户是否通过Facebook登录 - How to tell if user logged in via Facebook 如何获取Facebook登录用户的好友详细信息并从C#应用程序向他们发送消息,其中登录用户不是管理员 - How to get the Facebook logged in users Friends details and send them message from C# application where logged in user is not the admin 如何在vuejs中获取登录用户 - How to get logged user in vuejs 根据登录用户获取sql数据 - get sql data based on logged in user Facebook Graph API在用户未登录时获取数据 - Facebook Graph API getting data when user not logged in Facebook如何识别oAuth流程中正在发出请求的用户 - How does facebook identify the user who is making the requests in the oAuth flow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM