AxaFrance / oidc-client

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

AuthenticationProvider dynamically add/change extraQueryParams #521

Closed chustedt closed 4 years ago

chustedt commented 4 years ago

Hello,

I want to dynamically change extraQueryParams in the AuthenticationProvider. Depending on my user clicking register or login I want to set a specific query param in the redirect to the identity server so when I call the consumer login, that specific param would be set.

Is there anyway to handle this or has someone come across this before?

Thanks!

FrancoisDF commented 3 years ago

I was actually looking to do the same. Did you close the issue because you found out a solution?

FrancoisDF commented 3 years ago

Well, actually after trying out few things, I realized that it's working as expected. Even if not part of the code, nor the example, oidc-client will automatically picked up the extraQueryParams from the configuration. Just in case someone have the same issue, it should look like that:

const configuration = {
    authority: ...,
    client_id: ...,
    extraQueryParams: {
      key: value 
    },
    ...
  }
 <AuthenticationProvider  
      configuration={configuration}
      isEnabled={true}
      UserStore={InMemoryWebStorage}>
   <Provider store={store}>
       <BrowserRouter >
          <App />
       </BrowserRouter>
   </Provider>
</AuthenticationProvider>
chustedt commented 3 years ago

Our project originally had two separate buttons in our react-app one for registration and login that needed to open a separate page on our IM. I wanted to able to edit the extraQueryParams after the AuthenticationProvider was established. I did find a way to change the settings, but I can't find the code anymore. We ended up moving the login/register buttons into IM itself and have a single button in the react-app.

If you really need to update them after the AuthenticationProvider is created, I can try to find my changes. I vaguely remember updating something like .settings.extraQueryParams.

skoliver89 commented 3 years ago

Our project originally had two separate buttons in our react-app one for registration and login that needed to open a separate page on our IM. I wanted to able to edit the extraQueryParams after the AuthenticationProvider was established. I did find a way to change the settings, but I can't find the code anymore. We ended up moving the login/register buttons into IM itself and have a single button in the react-app.

If you really need to update them after the AuthenticationProvider is created, I can try to find my changes. I vaguely remember updating something like .settings.extraQueryParams.

I recently need to add extra params to pass dark mode settings to the ids4 login page. I think you are referring to something like this?

import { AuthenticationContext, getUserManager} from "@axa-fr/react-oidc-context";
const userMgr = getUserManager();
const darkMode = true;
userMgr.settings.extraQueryParams = { darkMode };

where the \~.settings.\~ line would be put where your update should be handled.