【发布时间】:2021-03-22 10:39:42
【问题描述】:
我想使用以下配置将 Google 身份验证添加到 Cookie 身份验证: 启动:
//ConfigureServices:
services.AddAuthentication( )
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
// ...
})
.AddGoogle(options =>
{
IConfigurationSection googleAuthNSection =
Configuration.GetSection("ExternalLogin:Google");
options.ClientId = googleAuthNSection["ClientId"];
options.ClientSecret = googleAuthNSection["ClientSecret"];
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.CorrelationCookie.SameSite = SameSiteMode.Lax;
});
//Configure():
app.UseAuthentication();
app.UseAuthorization();
和
[AllowAnonymous]
public IActionResult SigninGoogle(string returnurl)
{
var authProperties = new AuthenticationProperties
{ RedirectUri = Url.Action("ExternalLoginCallback","Auth",new{returnurl}).ToString(),
Items =
{
{ "LoginProvider", "Google" },
},
AllowRefresh = true,
};
return Challenge(authProperties, GoogleDefaults.AuthenticationScheme );
}
[AllowAnonymous][HttpGet("signin-google")]
public async Task<IActionResult> ExternalLoginCallback(string returnurl, string remoteError = null)
{
var result = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
if (result.Succeeded)
{}
//..
}
点击“SigninGoogle”后登录谷歌就OK了!
但是在返回 google 到“signin-google”时我有问题:
【问题讨论】:
标签: c# asp.net asp.net-core .net-core