简体   繁体   中英

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? 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.

 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. If I want to create the same with facebook (Meta) , what kind of coding should I do.

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?

You can get the external login information for the current login by using SignInManager<TUser>.GetExternalLoginInfoAsync(String) method:

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM