[英]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.