Asp.net mvc 5 通过owin的Google身份验证返回拒绝访问

Asp.net mvc 5 通过owin的Google身份验证返回拒绝访问,asp.net-mvc-5,owin,google-authentication,Asp.net Mvc 5,Owin,Google Authentication,我正在使用google中间件进行身份验证 下面是我的中间件设置 app.UseCookieAuthentication(new CookieAuthenticationOptions { //AuthenticationType = AuthServerConstants.PrimaryAuthenticationType AuthenticationMode = AuthenticationMode.Passive,

我正在使用google中间件进行身份验证

下面是我的中间件设置

 app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            //AuthenticationType = AuthServerConstants.PrimaryAuthenticationType
            AuthenticationMode = AuthenticationMode.Passive,
            AuthenticationType = DefaultAuthenticationTypes.ExternalCookie,
            ExpireTimeSpan = TimeSpan.FromMinutes(30)
        }).UseExternalSignInCookie(AuthServerConstants.ExternalAuthenticationType);
下面是我的google中间件

var google = new GoogleOAuth2AuthenticationOptions
        {
            ClientId = AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppId),
            ClientSecret = AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppSecret),
            SignInAsAuthenticationType = signInAsType,
            AuthenticationMode = AuthenticationMode.Passive
        };
        app.UseGoogleAuthentication(google);
var google=新的GoogleOAuth2AuthenticationOptions
{
ClientId=AppSettingHelpers.GetValue(AppSettingConstants.GoogleAppId),
ClientSecret=AppSettingHelpers.GetValue(AppSettingConstants.GoogleAppSecret),
SignInAsAuthenticationType=signInAsType,
AuthenticationMode=AuthenticationMode.Passive
};
app.UseGoogleAuthentication(谷歌);
我已经在Google开发者控制台中启用了Google+API

我使用的是谷歌中间件2.1版。我的谷歌认证仍然返回
error=access\u denied

有人能告诉我在这个过程中可能遗漏了什么吗

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

事实上,2014年4月20日,OpenID已被弃用,因为我们无法使用它

app.UseGoogleAuthentication();
相反,我们必须使用创建项目。然后,您需要像使用“ClientId”和“ClientSecret”一样更新代码

您的代码应该如下所示

app.UseGoogleAuthentication(AppSettingHelpers.GetValue<string>(AppSettingConstan‌​ts.GoogleAppId),     AppSettingHelpers.GetValue<string>(AppSettingConstants.GoogleAppSecret));
 http://YourDomain/signin-google 
LocalHost - https://YourLocalHost/signin-google
这对我有用


希望这能有所帮助。

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

您是否尝试过不使用GoogleOAuth2AuthenticationOptions直接调用它?也就是说,app.UseGoogleAuthentication(AppSettingHelpers.GetValue(AppSettingConstants.GoogleAppId),AppSettingHelpers.GetValue(AppSettingConstants.GoogleAppSecret))还没有,可能我会试试。v2.1的正确源代码甚至没有调试。这段代码对我来说运行良好,直到10天,不知道出了什么问题。我应该立即迁移到v3.0。从现在开始,我肯定要迁移到3.0.0版。所有OWIN dll的问题仍然存在。您将它们称为AppId和AppSecret让我怀疑您是否从正确的位置获取了这些值。请参阅“web应用程序的客户端ID”