让 ASP.NET Core Google 登录工作时出现问题

问题描述 投票:0回答:1

我有一个 ASP.NET Core 网络应用程序,我想在其中添加 Google 登录。

我遵循了这个描述: https://learn.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-7.0

当我运行应用程序时,选择 Google 登录按钮/选项,将我的邮件添加到 Google 站点的登录屏幕(https://accounts.google.com/v3/signin/identifier ...)我得到到下一页说:

此浏览器或应用程序可能不安全。 ...

我在我的应用程序 Google 凭据页面 (https://console.cloud.google.com/apis/credentials/oauthclient/) 尝试了一些编辑设置的操作。

我添加了:“授权 JavaScript 来源”部分的 https://localhost:7049 和“授权重定向 URI”部分的 https://localhost:7049/signin-google。

我是否遗漏了其他重要的东西?

感谢您的帮助!

asp.net-core google-signin
1个回答
1
投票

在谷歌控制台中设置。

Program.cs 文件中的代码应如下所示:

builder.Services.AddAuthentication().AddGoogle(googleOptions =>
{
    googleOptions.ClientId = "103****7s.apps.googleusercontent.com";
    googleOptions.ClientSecret = "GOCSPX-****_b3-jMPKHe";
}).AddMicrosoftAccount(microsoftOptions =>
{
    microsoftOptions.ClientId = "b3fb++_if_you_have_++c5fe2d";
    microsoftOptions.ClientSecret = "R****cbku";
});

测试结果

© www.soinside.com 2019 - 2024. All rights reserved.