【问题标题】:How authenticate .net core app from angular client using identityserver4如何使用 identityserver4 从 Angular 客户端验证 .net 核心应用程序
【发布时间】:2021-05-16 09:11:51
【问题描述】:

我的 Angular 应用程序在 http://localhost:4200 上运行,我的带有集成 identityserver4 身份验证的 .net 核心 mvc 应用程序在 https://localhost:44312/ 上运行

https://localhost:44312/connect/authorize?client_id=DocumentationGen&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauthentication%2Flogin-callback&response_type=code&scope=DocumentationGenAPI%20openid%20profile&state=d9ecb6d546e147569672b85fb8239fc7&code_challenge=W78Reow6OnPtRs36FcieAc1-rUPfHSvE2rHWD9BpBYw&code_challenge_method=S256&prompt=none&response_mode=query

当我尝试进行身份验证时,出现以下错误

https://localhost:44312/home/error?errorId=CfDJ8B-i8u6rBkNAj3HnFY4JfcyXVNdYo37R9IxB3zFzX--WIeR89rnU7XNedmt_AHjo_HCw8Y04yrfDTxNnDud2_P2D_yNvqJyUhQrDp0iB_5njT13pYmY-a0N5jNdgMPYVHVY0hIF0aqx0KCkYJ9O_fga8djacA_78tizfFjWcN7mndsQxepe-Ox1UYdFHd_fuka86LaCL4JVeMA07r1NSG5LIOUv7RabIowsU0JHrbXR3NizS05-cdzsQDmFiVjl1DWfL0M3ba5y4ERSdbDFkLsay8xg4FiapvLCdcirWSkfzXnb3HPmgH9GYaBvMi0CVVQ1xn23ZRNcYTA5b4FO83kFwD-VVNi1u6YKc-PjUvFHw1InpFDXwtkl8zZWU_Iv6hg

【问题讨论】:

    标签: angular .net-core identityserver4


    【解决方案1】:

    经过一番研究终于在这个链接中得到了答案

    https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity-api-authorization?view=aspnetcore-5.0
    

    将此添加到您的 startup.cs 文件中,以便从不同的端口进行身份验证

    services.AddIdentityServer()
                   .AddApiAuthorization<ApplicationUser, ApplicationDbContext>(options =>
                   {
                       options.Clients.AddSPA(
                           "client name", spa =>
                           spa.WithRedirectUri("http://localhost:4200/authentication/login-callback")
                              .WithLogoutRedirectUri(
                                  "http://localhost:4200/authentication/logout-callback").WithClientId("ClientId"));
                    });
    

    【讨论】:

      猜你喜欢
      • 2021-06-16
      • 2018-02-28
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多