Cannot redirect back to angular client after login in identity server

AlienTedCoder

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

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,
    });
}

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"
                    },
                }

And StartUp.cs:

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

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

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.

UPDATED:

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;
        });
AlienTedCoder

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;
        });

And in Configure method:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I redirect back to the client application after external login?

Client Application not Redirect to Identity Server 4 after hosted in iss

Redirect back to a page after a login

Identity Server 4 is not redirecting to Angular app after login

Angular routing with login to Identity server

Redirect back to location after being redirected to login

redirect back to the same url after login

Laravel redirect back to original destination after login

How to redirect user to client app after logging out from identity server?

Identity Server SameSite=None cannot login

How to make Angular Client to inform Identity Server which login method to use?

Login after signup in identity server4

Redirecting to login after logout (Identity Server 3)

Identity server registration doesn't redirect back to React app

Redirect MVC Action to Identity server 4 login page manually

Angular - Redirect to Login after register and show a message

Angular2 Redirect After Login

Angular 2 - Redirect after successful login not working

Angular redirect to previous page after login not working

Redirect to a specific path in Angular after login

Redirect back to previous page after login in django-allauth

How to redirect back to previous page after login in Code Igniter?

Okta Sign In Widget redirect back to original page after login

How to return back to the same page after login redirect in Svelte?

how to redirect the user back to desired URL after login (php)

Flow external login tokens from the Identity Server to the client app

Problem in refreshing the login token from client to identity server

How to get back to your client after the OAuthCallBack without redirect

IdentityServer4 Redirect to different client after login