【问题标题】:Setting up Google Authentication with Asp.Net MVC使用 Asp.Net MVC 设置 Google 身份验证
【发布时间】:2015-02-03 19:15:05
【问题描述】:

我正在使用 Asp.Net MVC-5 提供的默认模板。启用谷歌身份验证。我的本地站点将我带到 google 身份验证页面。然而,当谷歌重定向回来时,成功的身份验证,我得到以下错误:

证书链由不受信任的机构颁发

我明确地仔细检查并信任了 IIS Express 站点。

附:我从this article开始正确地遵循了每一步

【问题讨论】:

  • 听起来好像运行本地站点的 HTTPS 证书在您的浏览器中不受信任。可能是因为它是自签名的。如果是localhost,这是半预期的,因为没有合法的证书颁发机构会为localhost 签署证书。
  • 有点离题,但仅供参考 Google Open ID 2.0 现在已弃用:developers.google.com/accounts/docs/OpenID2

标签: c# asp.net-mvc owin google-authentication


【解决方案1】:

这是一步一步的视频 youtube link to video on google authentication for mvc in dotnet5 command line setup...

首先到这里创建您的凭据...:https://console.developers.google.com/apis/credentials\

然后是命令行时间:

dotnet new mvc -o MyApplicationName --auth Individual
dotnet add package Microsoft.AspNetCore.Authentication.Google
dotnet user-secrets init
dotnet user-secrets set "Authentication:Google:ClientId" <MyClientIDSecret>
dotnet user-secrets set "Authentication:Google:ClientSecret" <MyClientSecret>
dotnet add package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet add package Microsoft.AspNetCore.Identity.UI
dotnet tool update --global dotnet-ef
dotnet ef migrations add InitialCreate
dotnet ef database update

然后在visual studio或vs code中打开并更改代码:

就在 addControllersWithViews 之上:

services.AddAuthentication()
            .AddGoogle(options =>
            {
                IConfigurationSection googleAuthNSection =
                    Configuration.GetSection("Authentication:Google");

                options.ClientId = googleAuthNSection["ClientId"];
                options.ClientSecret = googleAuthNSection["ClientSecret"];
            });

将 [Authorize] 添加到家庭控制器 将 [Allowanonymous] 添加到索引

【讨论】:

  • @Blastfurnace 我已将视频中的代码放入帖子中,这样更好吗?
猜你喜欢
  • 2012-11-18
  • 2010-09-24
  • 2012-02-21
  • 2014-05-06
  • 1970-01-01
  • 1970-01-01
  • 2015-04-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多