spartacus icon indicating copy to clipboard operation
spartacus copied to clipboard

fix: CXSPA-6581 Race condition in OpenID code flow causes redirect loop or double redirect on login

Open pawelfras opened this issue 2 years ago • 1 comments

This PR contains a fix for the redirect loop caused by race conditions in OpenID code flow when all routes in the application are protected (required login from the beginning). LoginGuard tried to check whether the user was logged in before the code/token was taken from the URL and stored in the application which caused a redirect loop.

QA steps:

  • build and deploy Spartacus packages locally:
 npx ts-node ./tools/schematics/testing.ts in the SPA root folder
  • generate fresh ng17 application:
 npx @angular/cli new my-app --standalone=false --ssr=false --style=scss
  • go to the project's directory and install Spartacus with SSR from local packages: npx @angular/cli add @spartacus/schematics@latest
  • in the generated application, add the following config to enable protected routes and Authorization Code Flow
    provideConfig(<OccConfig>{
      backend: {
        occ: {
          baseUrl: 'https://40.76.109.9:9002',
        },
      },
    }),
    provideConfig(<RoutingConfig>{
      routing: {
        protected: true,
      },
    }),
    provideConfig(<AuthConfig>{
      authentication: {
        client_id: 'client4kyma',
        client_secret: 'secret',
        tokenEndpoint: '/oauth/token',
        revokeEndpoint: '/oauth/revoke',
        loginUrl: '/oauth/authorize',
        OAuthLibConfig: {
          responseType: 'code',
          scope: '',
          customTokenParameters: ['token_type'],
          strictDiscoveryDocumentValidation: false,
          skipIssuerCheck: true,
          disablePKCE: true,
          oidc: false,
          clearHashAfterLogin: false,
        },
      },
    }),
  • run app and verify if there is no redirection loop when logging

closes CXSPA-6581

pawelfras avatar Apr 03 '24 11:04 pawelfras

3 flaky tests on run #43197 ↗︎

0 119 2 0 Flakiness 3
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge 1f8bab2f49e98e0703b84e5f1e186b305c485879 into 663f028707c51890f31d1a3b8fdf...
Project: spartacus Commit: 3d8065afc7 ℹ️
Status: Passed Duration: 13:59 💡
Started: Apr 3, 2024 11:34 AM Ended: Apr 3, 2024 11:48 AM

Review all test suite changes for PR #18697 ↗︎

cypress[bot] avatar Apr 03 '24 11:04 cypress[bot]

Closing in favour of https://github.com/SAP/spartacus/pull/18706

pawelfras avatar Aug 19 '24 11:08 pawelfras