【问题标题】:Adding Google authentication to ASP.NET with Angular Visual Studio template使用 Angular Visual Studio 模板将 Google 身份验证添加到 ASP.NET
【发布时间】:2022-06-13 19:56:13
【问题描述】:

我有一个项目,我使用带有 Angular Visual Studio 模板的 ASP.NET 创建了一个具有个人帐户身份验证类型的项目。

然后我按照此处列出的步骤添加了 Google 身份验证。

https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/google-logins?view=aspnetcore-6.0

但是,当我尝试注册时,控制台中出现错误提示

错误:无法匹配任何路由。 URL 段:'signin-google'。

我尝试遵循完全相同的步骤,但使用剃须刀页面而不是 Angular 的 asp.net 核心 Web 应用程序,它可以正常工作。 Angular 有什么我缺少的吗?

感谢您的任何建议

【问题讨论】:

  • 你看到了吗?总是很好地展示你的研究。 stackoverflow.com/questions/57269386/…
  • @JeremyThompson 我设法解决了我的问题。当 asp.net Identity 应该接管时,Angular 接管了路由。我通过添加此行“googleOptions.CallbackPath = new PathString("/Identity/signin-google");”来更改 google 的重定向 URL 来修复它到我的 Program.cs 文件中。
  • @PhadonPhipat 将其作为答案。可以回答您自己的问题。

标签: c# asp.net angular authentication


【解决方案1】:

我设法解决了我的问题。当 asp.net Identity 应该接管时,Angular 接管了路由。我通过添加此行“googleOptions.CallbackPath = new PathString("/Identity/signin-google");”来更改 google 的重定向 URL 来修复它到我的 Program.cs 文件中。

【讨论】:

    【解决方案2】:

    您需要告诉 Angular 排除该路由并将其转发到后端,方法是将其添加到 proxy.conf.js

    const PROXY_CONFIG = [
      {
        context: [
          "/weatherforecast",
          "/_configuration",
          "/.well-known",
          "/Identity",
          "/connect",
          "/ApplyDatabaseMigrations",
          "/_framework",
          "/signin-google", //           <---- Right here
        ],
        target: target,
        secure: false,
        headers: {
          Connection: 'Keep-Alive'
        }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-29
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      相关资源
      最近更新 更多