【发布时间】:2015-01-10 09:10:46
【问题描述】:
我在使用 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
【问题讨论】:
-
您是否在 Google 的应用配置页面上授予您的应用访问 Google+ API 的权限?
-
是的,我确定在应用配置中打开 Google+ API。但我考虑为 Google+ 注册我的公共域和 SSL。你对此有什么想法吗?
-
您解决了这个问题吗?因为我遇到了同样的问题。
标签: asp.net-mvc asp.net-mvc-4 oauth google-oauth asp.net-identity-2