【问题标题】:Google Authentication via owin returns access denied通过 owin 进行的 Google 身份验证返回访问被拒绝
【发布时间】:2014-09-23 14:44:46
【问题描述】:

我正在使用谷歌的中间件进行身份验证

以下是我的中间件设置

 app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            //AuthenticationType = AuthServerConstants.PrimaryAuthenticationType
            AuthenticationMode = AuthenticationMode.Passive,
            AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            ExpireTimeSpan = TimeSpan.FromMinutes(30)
        }).UseExternalSignInCookie(AuthServerConstants.ExternalAuthenticationType);

以下是我的谷歌中间件

var google = new GoogleOAuth2AuthenticationOptions
        {
            ClientId = AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppId),
            ClientSecret = AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppSecret),
            SignInAsAuthenticationType = signInAsType,
            AuthenticationMode = AuthenticationMode.Passive
        };
        app.UseGoogleAuthentication(google);

我已在 google 开发者控制台中启用了 Google+API

我使用的是 Google 中间件 2.1 版。我的谷歌身份验证仍然返回error=access_denied

谁能告诉我在这个过程中可能遗漏了什么。

注意 我的外部身份验证 cookie 中间件尚未在浏览器中设置 cookie。

【问题讨论】:

  • 你试过不使用GoogleOAuth2AuthenticationOptions直接调用吗?这意味着,app.UseGoogleAuthentication(AppSettingHelpers.GetValue(AppSettingConstants.GoogleAppId), AppSettingHelpers.GetValue(AppSettingConstants.GoogleAppSecret))
  • 还没有,也许我会试试。 v2.1 的正确源代码甚至无法调试。这段代码对我来说工作正常,直到 10 天,突然不知道出了什么问题
  • 我是否应该从现在开始迁移到 v3.0 blogs.msdn.com/b/webdev/archive/2014/07/02/…
  • 已将所有 OWIN dll 迁移到 3.0.0 版,但问题仍然存在
  • 您将它们称为 AppId 和 AppSecret 让我想知道您是否从正确的位置获取这些值。请参阅console.developers.google.com/project/[project]/apiui/…,“Web 应用程序的客户端 ID”

标签: asp.net-mvc-5 owin google-authentication


【解决方案1】:

实际上,2014 年 4 月 20 日,Open ID 已被弃用,因此我们无法使用

app.UseGoogleAuthentication();

相反,我们必须使用Goolge Console 创建项目。然后,您需要像使用“ClientId”和“ClientSecret”一样更新您的代码。

你的代码应该是这样的

app.UseGoogleAuthentication(AppSettingHelpers.GetValue<string>(AppSettingConstan‌​ts.GoogleAppId),     AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppSecret));

请注意:在 Google 控制台上创建项目时提供重定向 URI 时应小心。因为重定向 URI 可能看起来像

 http://YourDomain/signin-google 
LocalHost - https://YourLocalHost/signin-google

这对我有用。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我最近遇到了同样的问题。就我而言,我必须在 Google 开发者控制台上启用 Google+ API。您可以先在“查找产品和服务”搜索框中输入名称,然后单击“启用”按钮来启用 Google+ API。

    【讨论】:

      猜你喜欢
      • 2016-08-09
      • 1970-01-01
      • 2017-11-28
      • 2016-03-15
      • 2014-07-14
      • 2018-01-06
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      相关资源
      最近更新 更多