.NET OAuth2 登录 Google 服务器端
.NET OAuth2 Sign-on Google server-side
我阅读了有关实现外部登录的文档 (google)
它与 Identity 配合使用非常完美,但由于某些原因我无法使用该方法,我想知道如何以更手动的方式获得授权字段(如电子邮件和姓名)。
像这样:
https://developers.google.com/identity/sign-in/web/sign-in
我需要类似的东西,但来自服务器端。
我已将此添加到我的 Startup.cs
services.AddAuthentication(options =>
{
options.DefaultScheme = Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = "Google";
})
.AddCookie()
.AddGoogle("Google", googleOptions =>
{
googleOptions.ClientId = Configuration["Authentication:Google:ClientId"];
googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
});
此Action谁开启Google登录window
string localeToken = (string)HttpContext.Request.RouteValues["clientId"];
var redirectUrl = Url.Action("SignInCallback", "Home", new { ReturnUrl = $"SO-{localeToken}/Account/GoogleLogin" });
Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties =
new Microsoft.AspNetCore.Authentication.AuthenticationProperties();
//_signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
properties.RedirectUri = redirectUrl;
ChallengeResult challengeResult = new ChallengeResult(provider, properties);
return challengeResult;
此操作发生后重定向到 SignInCallback,一切看起来不错,但我不知道我需要进一步做什么,我不知道我在哪里以及如何获取用户数据,如 ID 或电子邮件,以便我可以用它创建用户没有身份的手动数据。
我阅读了有关实现外部登录的文档 (google)
它与 Identity 配合使用非常完美,但由于某些原因我无法使用该方法,我想知道如何以更手动的方式获得授权字段(如电子邮件和姓名)。
像这样: https://developers.google.com/identity/sign-in/web/sign-in
我需要类似的东西,但来自服务器端。
我已将此添加到我的 Startup.cs
services.AddAuthentication(options =>
{
options.DefaultScheme = Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultAuthenticateScheme = "Google";
})
.AddCookie()
.AddGoogle("Google", googleOptions =>
{
googleOptions.ClientId = Configuration["Authentication:Google:ClientId"];
googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
});
此Action谁开启Google登录window
string localeToken = (string)HttpContext.Request.RouteValues["clientId"];
var redirectUrl = Url.Action("SignInCallback", "Home", new { ReturnUrl = $"SO-{localeToken}/Account/GoogleLogin" });
Microsoft.AspNetCore.Authentication.AuthenticationProperties? properties =
new Microsoft.AspNetCore.Authentication.AuthenticationProperties();
//_signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
properties.RedirectUri = redirectUrl;
ChallengeResult challengeResult = new ChallengeResult(provider, properties);
return challengeResult;
此操作发生后重定向到 SignInCallback,一切看起来不错,但我不知道我需要进一步做什么,我不知道我在哪里以及如何获取用户数据,如 ID 或电子邮件,以便我可以用它创建用户没有身份的手动数据。