oidc-client icon indicating copy to clipboard operation
oidc-client copied to clipboard

Failing to redirect to route after logging in

Open sharjeel-jan opened this issue 2 years ago • 10 comments

Issue and Steps to Reproduce

Failing to redirect to specified page after being logged in, the page gets stuck with the callback url being filled -

image

I've tried to add the customCallback but that doesnt seem to resolve the issue, heres my current code -

App.js -

const CallbackSuccessComponent = () => {
  const navigate = useNavigate();
  const { idToken } = useOidcIdToken();

  useEffect(() => {
    console.log(idToken);
    if (idToken) {
      navigate("/automagiqapps/ui/dashboard", { replace: true });
      window.location.reload();
    }
  }, [idToken]);

  return <div>CallbackSuccessComponent</div>;
};

function App() {
  const configuration = {
    client_id: "<CLIENT_ID>",
    redirect_uri: "${window.location.origin}/automagiqapps/ui/#callback",
    scope: "openid profile",
    authority:
      "<AZURE_AUTH_URL>",
    // service_worker_relative_url: "./OidcServiceWorker.js",
    // service_worker_only: true,
  };

  return (
    <OidcProvider
      configuration={configuration}
      callbackSuccessComponent={CallbackSuccessComponent}
    >
      <Router>
        <SnackbarProvider
          maxSnack={2}
          autoHideDuration={2000}
          anchorOrigin={{
            vertical: "bottom",
            horizontal: "center",
          }}
        >
          <Routes>{routes}</Routes>
        </SnackbarProvider>
      </Router>
    </OidcProvider>
  );
}

Login logic, pretty much copied from examples -

{!isAuthenticated && (
  <ListItemButton
    sx={{ px: 3, pt: 2.5, pb: 2.5 }}
    onClick={() => login("/automagiqapps/ui/dashboard")}
  >
    <ListItemIcon>
      <LoginIcon />
    </ListItemIcon>
    <ListItemText
      primary="Login"
      primaryTypographyProps={{
        fontSize: 15,
        fontWeight: "medium",
        variant: "body2",
      }}
    />
  </ListItemButton>
)}

Versions

"@axa-fr/react-oidc": "^6.10.13"

Screenshots

Expected

Redirected to specified route

Actual

Stuck on callback URL after pressing login and being authenticated

Additional Details

  • Installed packages:

sharjeel-jan avatar Nov 14 '22 13:11 sharjeel-jan

hi @sharjeel-jan ,

Thank you very much for your issue.

Do you have an error in the console? or something that may help :)

Do you see in the requests debug tab an uri with "#callback" in the url?

guillaume-chervet avatar Nov 14 '22 14:11 guillaume-chervet

Hi @guillaume-chervet

Thanks for getting back to me so quick, I see no error in the console and I dont believe I see an #callback in any of the URLS

I've attached a screenshot below of the network tab

image

sharjeel-jan avatar Nov 14 '22 15:11 sharjeel-jan

Thank you @sharjeel-jan , that strange.

I may need more information to help you.

Did you tried your configuration on the code of that repository? (after clone and replace configuration value by yours)

guillaume-chervet avatar Nov 14 '22 15:11 guillaume-chervet

I havent yet tried my configuration with the example code, I'll try that and get back to you, thanks

sharjeel-jan avatar Nov 14 '22 16:11 sharjeel-jan

Hi @guillaume-chervet

Running with the example code I get the following after pressing Login

image

sharjeel-jan avatar Nov 14 '22 19:11 sharjeel-jan

Do you know if you oidc provider support hash redirect? It seem to redirect on the path without the hash.

guillaume-chervet avatar Nov 14 '22 21:11 guillaume-chervet

I am not sure but what happen if you replace ${window.location.origin}/automagiqapps/ui/#callback By ${window.location.origin}/automagiqapps/ui#callback

guillaume-chervet avatar Nov 15 '22 07:11 guillaume-chervet

Any update on this @sharjeel-jan? i seem to have a simular issue

solrankos avatar Nov 22 '22 10:11 solrankos

hi @sharjeel-jan, did you solve your problem?

guillaume-chervet avatar Nov 25 '22 17:11 guillaume-chervet

It seems that @sharjeel-jan is using Azure AD or similar as an IDP. You might wanna ensure that the redirect uris configured for your frontends client id have been configured as a "spa" instead of "web" app.

https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/2338#issuecomment-698515769

hodorsoft avatar Jun 14 '23 13:06 hodorsoft