登录身份服务器后无法重定向回角度客户端 [英] Cannot redirect back to angular client after login in identity server

查看:66
本文介绍了登录身份服务器后无法重定向回角度客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用身份服务器登录后,重定向存在问题.

I've got an issue with redirecting after loggin in with identity server.

我有以下angular-auth-oidc-client配置:

I have the following angular-auth-oidc-client config:

    export function configureAuth(oidcConfigService: OidcConfigService) {
  return () =>
    oidcConfigService.withConfig({
      stsServer: 'http://localhost:5002',
      redirectUrl: window.location.origin,
      postLogoutRedirectUri: window.location.origin,
      clientId: 'applications-portal',
      scope: 'openid profile',
      responseType: 'id_token token',
      logLevel: LogLevel.Debug,
    });
}

和app.component.ts:

And app.component.ts:

  ngOnInit() {
    this.oidcSecurityService.checkAuth().subscribe((auth) => {
      console.log('is authenticated', auth);
      if (!auth) {
        this.login();
      }
    });
  }

  login() {
    this.oidcSecurityService.authorize();
  }

这是身份服务器应用程序中的客户端配置:

This is the client configuration in the identity server app:

new Client
                {
                    ClientId = "applications-portal",
                    ClientName = "Applications Portal",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    AllowedScopes =
                    {
                        "service",
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile
                    },
                    AccessTokenType = AccessTokenType.Jwt,
                    AllowAccessTokensViaBrowser = true,
                    RequireConsent = false,
                    RequireClientSecret = false,
                    RequirePkce = true,
                    RedirectUris = {
                        "http://localhost:4200",
                    },
                    PostLogoutRedirectUris =
                    {
                        "http://localhost:4200"
                    },
                    AllowedCorsOrigins =
                    {
                        "http://localhost:4200"
                    },
                }

和StartUp.cs:

And StartUp.cs:

    services.ConfigureApplicationCookie(config =>
    {
        config.Cookie.Name = "Identity.Cookie";
        config.LoginPath = "/Auth/Login";
    });

问题是当我在登录(GET)方法中重定向到AuthController时,得到的returnUrl如下所示: returnUrl值

The problem is that when I get redirected to AuthController in Login (GET) method I get returnUrl that looks like this: returnUrl Value

登录后,它不会将我重定向回客户端应用程序,而是停留在登录页面上.我相信returnUrl本身有问题.我是第一次使用IdentityServer,所以我真的不知道要做什么.

And after the login it does not redirect me back to the client app, but stays on the login page. I belive that there's something wrong with the returnUrl itself. I'm using IdentityServer for the first time, so I don't really know what to dig for.

已更新:

问题出在Chrome浏览器中.SameSite阻止它重定向.我在 https://www.thinktecture中尝试了该解决方案.com/en/identity/samesite/prepare-your-identityserver/但这没用.在其他浏览器中,它可以按预期工作.您能否给我一个提示,在这种情况下如何使用Chrome?

The problem is in Chrome browser. SameSite thing prevents it to redirect. I've tried the solution here https://www.thinktecture.com/en/identity/samesite/prepare-your-identityserver/ but it didn't work. In other browsers, it works as expected. Could you give me a hint what to do in this case with Chrome?

我也尝试将其设置为宽松",但没有任何变化.

I've also tried setting it to Lax but nothing changes.

            services.ConfigureApplicationCookie(config =>
        {
            config.Cookie.Name = "Identity.Cookie";
            config.LoginPath = "/Auth/Login";
            config.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
        });

推荐答案

通过将Cookie配置更改为:

Solved it by changing the Cookie configuration to:

        services.ConfigureApplicationCookie(config =>
        {
            config.Cookie.Name = "Identity.Cookie";
            config.LoginPath = "/Auth/Login";
            config.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax;
        });

在配置"方法中:

app.UseCookiePolicy(new CookiePolicyOptions
            {
                MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.Lax,
            });

这篇关于登录身份服务器后无法重定向回角度客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆