加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – GetExternalLoginInfo在Google OWIN提供程序上返回’

发布时间:2020-12-16 03:29:49 所属栏目:asp.Net 来源:网络整理
导读:我从Visual Studio 2013获得了一个近乎完整的ASP.NET MVC模板应用程序.它是使用以下设置创建的: Create Project Web ASP.NET Web Application OK MVC,Individual User Accounts OK 我正在尝试使用OWIN Google提供商登录并遇到问题. OWIN配置方法如下所示:
我从Visual Studio 2013获得了一个近乎完整的ASP.NET MVC模板应用程序.它是使用以下设置创建的:

Create > Project > Web > ASP.NET Web Application > OK > MVC,Individual User Accounts > OK

我正在尝试使用OWIN Google提供商登录并遇到问题.

OWIN配置方法如下所示:

app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Account/Login")
        });

        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        var google = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions
        {
            ClientId = "xxxxx.apps.googleusercontent.com",ClientSecret = "xxxxxxxxx-yyyyyyyyy"
        };

        google.Scope.Add("profile");
        google.Scope.Add("email");

        app.UseGoogleAuthentication(google);

我点击网页上的Google提供商按钮,使用google进行身份验证,然后返回到ExternalLoginCallback.此时,该过程在此行中出现故障:

var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

loginInfo为null,它将我重定向回Login页面,没有任何可见错误.

解决方法

我在这里回答一个旧问题,但对于将来可能遇到此问题的任何人来说,适用于我的解决方案是使用Google Developers Console中的API Manager启用“Google API”.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读