当我使用Asp .Net Identity 2连接Google+时,我遇到了问题。目前,我的网站通过OAuth API 2连接Google+,并使用Claim Identity存储用户的一些信息。我用https运行localhost时设置得很好。但是当我将我的网站部署到生产服务器时出现问题。在使用接受为我的网站提供获取其信息的权限后,Google+会使用url / signin-google回调我的网站。之后,ASP .Net MVC会自动重定向到ExternalCallBack
操作,但会出现错误?error=access_denied
。我已捕获网络并查看以下信息:
在url回调signin-google:
signin-google?state=nNABsQBmwoPILh1mViOUIqzDcxQIS3HVZx2jtrSYCwd-ifMn4bDgBV1H1qdewFZx5Lz1c35ZZEpUem9jDTUrKlzWDuV-MwTQ3Tesx66PEjWdQQHo0QPJHX_bRMHqgN-Ad1whLs4iUyUSCH39oeTvYg3Cx6O0_v7Sc5GaUujHgr6xW1jw8EImhWJgnFGXgkAjD5hOtr7RoYO23xJyw0AIyuWnyx1gInJndWKvL-eqWPD9BtRaNe3nhWF5NGEG_2Ir&code=4/OEwsZCeeDPKrN5Dls3Uu-Q0wacdMqlhdbb8B1P__8X8.MmSgAQ_-cmIRgrKXntQAax20FxCmlQI
Asp.Net.Collrelation.Google nXgdr60bDh6tfivnvc6NA6ubz1K9zwjOqgrBBQgsitE
在URL回调外部登录:
external-login-callback?error=access_denied
希望你帮帮我。
*编辑: 这是我在Startup.Config.cs中的代码
var googleOpt = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "xxxxxxxxpm0il.apps.googleusercontent.com",
ClientSecret = "xxxxxxxx",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = (context) =>
{
context.Identity.AddClaim(new System.Security.Claims.Claim("GoogleAccessToken", context.AccessToken));
return Task.FromResult(o);
}
}
};
googleOpt.Scope.Add("https://www.googleapis.com/auth/plus.login");
googleOpt.Scope.Add("https://www.googleapis.com/auth/plus.profile.emails.read");
googleOpt.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;
app.UseGoogleAuthentication(googleOpt);
在我的帐户控制器中,我使用Asp .Net MVC 5.2的默认代码
答案 0 :(得分:1)
我遇到了同样的问题,必须在Google Developer Console中启用Google+ API。
如果关闭此功能,则无效。我一打开它,一切都很好。