AxaFrance / oidc-client

Light, Secure, Pure Javascript OIDC (Open ID Connect) Client. We provide also a REACT wrapper (compatible NextJS, etc.).
MIT License
570 stars 152 forks source link

ServiceWorker stuck on Loading screen #1376

Closed kramer99 closed 3 weeks ago

kramer99 commented 1 month ago

Issue and Steps to Reproduce

Trying out the service worker approach after using the local storage approach successfully.

The app gets stuck on the Loading component. It does not start the /authorize flow.

This is a NextJs app.

config:

const oidcConfig: OidcConfiguration = {
  authority: process.env.NEXT_PUBLIC_AUTHORITY || '',
  client_id: process.env.NEXT_PUBLIC_CLIENT_ID || '',
  // service_worker_only: true,
  service_worker_relative_url: '/ibor/OidcServiceWorker.js',
  redirect_uri: '',
  scope: 'openid ibor'
};

if (isBrowser()) {
  // these variables are not available during SSR
  oidcConfig.redirect_uri = `${window.location.origin}/ibor/callback`;
  // oidcConfig.storage = localStorage;
}

OidcTrustedDomins.js:

const trustedDomains = {
  default: [
    'https://terrabella.addelocal.com/ibor',
    'https://api-dev.addepar.com'
  ]
};

I added some logging with the onEvent prop and was able to see that the service worker is installed and running:

image

Versions

7.22.5

guillaume-chervet commented 1 month ago

Hi @kramer99 , with Next.js you need to set up a specific route to be able to retrieve the callback. So you have a sample of your callback url informations and query string?

kramer99 commented 1 month ago

Here's my callback:

import React from 'react';
import { useOidc } from '@axa-fr/react-oidc';
import { useRouter } from 'next/router';
import Loader from '../../components/Loader';

const Page = () => {
  const { isAuthenticated } = useOidc();
  const router = useRouter();

  if (isAuthenticated) router.push('/');
  else router.push('/signin');

  return <Loader />;
};

export default Page;

...it never gets called though, as the /authorize endpoint on the IDP is not even redirected to to begin with.

guillaume-chervet commented 3 weeks ago

Did you find a solution @kramer99 ?