使用Asp.Net MVC设置Google身份验证

时间:2014-12-05 15:10:57

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

我使用的是Asp.Net MVC-5提供的默认模板。启用Google身份验证。我的本地网站将我带到谷歌身份验证页面。但是,当谷歌重定向时,成功的身份验证,我得到以下错误:

  

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

我明确地双重检查并信任了IIS Express网站。

P.S。我从this article

正确地遵循了每一步

1 个答案:

答案 0 :(得分:0)

这是一步一步的视频 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"];
            });

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