AxaFrance / oidc-client

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

Enhancement Request: Allow `logout` to be passed arguments for `state` #503

Closed anied closed 2 years ago

anied commented 4 years ago

Enhancement Request: Allow logout to be passed arguments for state

As near as I can tell, under the hood, react-oidc is calling into oidc-client-js's UserManager's signoutRedirect instance method in order to prompt a logout. signoutRedirect accepts an args object, which can include a state property, which would be forwarded to any URL passed for end_session_endpoint as a query param.

It would be nice if the logout method made available via the various packages could be made to accept args (or possibly just state) so that it could be passed through to react-oidc's signoutRedirect. For instance, in the context variant, changing logoutCallback to something like this:

  const logoutCallback = useCallback(async (args = {}) => {
    try {
      onLogout();
      await logoutUserInt(userManager, args);
      oidcLogInt.info('Logout successfull');
    } catch (error) {
      onError(error.message);
    }
  }, [logoutUserInt, oidcLogInt, onError, onLogout, userManager]);

and logoutUser in oidcServices.ts to something like this:

export const logoutUser = async (userManager: UserManager, args) => {
  if (!userManager || !userManager.getUser) {
    return;
  }
  const oidcUser = await userManager.getUser();
  if (oidcUser) {
    oidcLog.info('Logout user...');
    await userManager.signoutRedirect(args);
  }
};

would enable leveraging of state. That's obviously a rough, not very Typescripty example, but it is the sort of thing I am envisioning.

Being able to pass state through would allow us to take different actions on the way back into the application based on how the user was logged out. For example, we could opt to show a warning on the screen if they were logged out programmatically rather than by user action.

guillaume-chervet commented 4 years ago

Hi @anied, thank you for your issue,

We absolutely need to add this feature. @anied , do you have time to try a contribution?

rahul-sharma-uipath commented 3 years ago

@guillaume-chervet @youf-olivier do you mind if I open a PR for this?

guillaume-chervet commented 3 years ago

It would be very it would be very nice :)

rahul-sharma-uipath commented 3 years ago

can you give me contributor permission? I want to open up a branch

youf-olivier commented 3 years ago

Hello. You just have to make a PR from a fork. We can't add you in the contributors because of internal Axa Policies.

But don't worry it's very simple to contribute from a fork.

guillaume-chervet commented 2 years ago

Hi @anied , very sorry for the delay. You can do it in the latest v5. I close the issue feel free to reopen it. And also thank you for that issue.