question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Callback does not redirect back to the requested url

See original GitHub issue

Issue and Steps to Reproduce

Requesting to url /profile if unauthenticated it will go to the oidc provider to initiate login, then it will redirect to callback , but during testing it didnt redirect to profile its just stuck to Authentication complete You will be redirected to your application. Is there a config to set to redirect after the callback? Do you store the requested url like localstorage or cookie then use that to redirect after callback ?

Versions

 5.8.0-alpha0

Config

 export const configuration = {
  client_id: "testingapp-auth",
  redirect_uri: window.location.origin + "/authentication/callback",
  silent_redirect_uri:
    window.location.origin +
    "/authentication/callback/authentication/silent-callback", // Optional activate silent-signin that use cookies between OIDC server and client javascript to restore the session
  scope: "openid profile email offline_access roles",
  authority: "http://oidcprovider.com/apps/testingapp",
    service_worker_relative_url: "/OidcServiceWorker.js",
    service_worker_only: true,
};

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
masterbatercommented, May 8, 2022

@masterbater I’m currently running into the same issue, could you share your solution?

Im using react router v6 you can also use history.replace though

import { useOidcIdToken } from "@axa-fr/react-oidc";
import React, { useEffect } from "react";
import { useNavigate } from "react-router-dom";

const CallbackSuccessComponent = () => {
  const navigate = useNavigate();
  const { idToken} = useOidcIdToken();
  useEffect(() => {
    if (idToken) {
      navigate("/", { replace: true });
      window.location.reload();
    }
  }, [idToken]);

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

export default CallbackSuccessComponent;

<OidcProvider callbackSuccessComponent={CallbackSuccessComponent} configuration={configuration} > <App /> </OidcProvider> You can also save to localstorage the requested url then programatically call the login function then use that to supply in the navigate(requestedUrl, { replace: true });

It works, thanks.

Although the implementation isn’t amazingly spectacular, for example the call to navigate leaves you on that endpoint directly (in my case the router is supposed to redirect / back to /app, which doesn’t happen without window.location.reload(), which isn’t great, preferably you’d rather not have that reload.

On top of that you’d need to have the OidcProvider within the Router, which shouldn’t be required.

@guillaume-chervet You have an idea how we can improve on that?

You are right Im just playing around with this library so Im doing some temporary solution. window.location.reload is not needed as long as the token callback is successful hence for the reason why there is checking for idToken and the code I provided you is just barebones and removed some of my logic. As what I have said you can customized what you want to redirect path after callback, just save the path before calling the login hook.

Hope this will get fix for some people doesnt want to customized. Even this get fix you depending on your app you might need some custom logic or UI on its default provided component

1reaction
Thodor12commented, Jun 2, 2022

I can also confirm this is working as intended now, thanks 👍🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

callbackUrl does not redirect upon sigin-in · Issue #591 - GitHub
After signing it does not redirect to the query stringified callbackUrl (Which is correct on the sign-in page).
Read more >
Exact callback url redirection is not working after SSO login
The SSO is different domain. Once I successfully loggedin it is redirecting to home page. Scenario 1 : Request url : localhost:6000 action: ......
Read more >
Redirect Users - Auth0
Sometimes, the callback URL is not necessarily where you want users redirected after authentication. For example, if a user intends to access a...
Read more >
Redirect to Load Callback URL after authorized
I am building an app with OAuth flow. I am struggling to redirect the user to the app's Load Callback URL after authorization...
Read more >
Redirect URI (reply URL) restrictions - Microsoft Entra
Redirect URIs not configured with a path segment are returned with a trailing slash (' / ') in the response. This applies only...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found