繁体   English   中英

ASP.NET Core Google登录返回403

[英]ASP.NET Core Google Sign In Returns 403

我知道我缺少明显的东西,但是我无法弄清楚它是什么。 我正在尝试制作一个简单的“使用Google登录”测试应用,当我获得Google同意屏幕后,在我的网站上显示403。

在启动中,我配置Cookie和Google:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookies",
    AutomaticAuthenticate = true,
    AutomaticChallenge = true,
    LoginPath = new Microsoft.AspNetCore.Http.PathString("/Account/Login"),
    AccessDeniedPath = new Microsoft.AspNetCore.Http.PathString("/Account/Denied")
});

app.UseGoogleAuthentication(new GoogleOptions
{
    AuthenticationScheme = "Google",
    SignInScheme = "Cookies",
    ClientId = "xxx"                                                                      
    ClientSecret = "xxx"                                                                 
    AutomaticChallenge = true
});

我已经将google api配置为击中中间件创建的端点:

在此处输入图片说明

但是从Google到http://localhost:5000/signin-google?state=xxxxxxx的回调给了我403错误。 我的开发人员例外页面显示:

在此处输入图片说明

我的登录方法很简单:

[HttpGet("login")]
public IActionResult Login(string returnUrl)
{
   return Challenge(new AuthenticationProperties
   {
       RedirectUri = returnUrl ??  "Home/Index"
   });
}

有人可以帮助我了解我的错误吗?

加。 我知道了。 原来我的应用程序配置正确。 我必须在Google的控制台API中“启用” Google+ API:

在此处输入图片说明

如果有人知道这背后的原因,或者为什么不是很明显您需要这样做,那么我当然想知道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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