在Asp.net核心中使用身份验证服务器进行外部登录时,如果外部登录无效,可能是由于配置或代码设置不正确导致的。以下是一些可能的解决方法和代码示例:
"Google": {
"ClientId": "your-client-id",
"ClientSecret": "your-client-secret"
}
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication()
.AddGoogle(options =>
{
options.ClientId = Configuration["Google:ClientId"];
options.ClientSecret = Configuration["Google:ClientSecret"];
});
}
Sign in with Google
public async Task OnGetCallbackAsync()
{
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
// Handle external login failure
return RedirectToAction("Login");
}
// Handle external login success
// ...
}
通过检查以上配置和代码示例,您应该能够解决Asp.net核心中使用身份验证服务器进行外部登录无效的问题。如果问题仍然存在,建议查看官方文档或在相关论坛上寻求帮助。