IdentityModel / oidc-client-js

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Apache License 2.0
2.43k stars 842 forks source link

How can we update and reassign config to UserManager #1345

Closed ismeddnl closed 3 years ago

ismeddnl commented 3 years ago

Hi ,

How can we update and reassign config to UserManager instead of recall the contructor (Oidc.UserManager(config)), could you please suggest how to solve this. thanks.

var config = {
    authority: "https://localhost/idserv",
    client_id: "mvc",
    redirect_uri: window.location.origin + "/oidcjs/callback.html",
    post_logout_redirect_uri: window.location.origin + "/oidcjs/index.html",
};
var mgr = new Oidc.UserManager(config);

var login = function login() {
    mgr.signinRedirect();
}
var logout = function logout() {
    mgr.signoutRedirect();
}
apisettingcall().then(function (response) {
            config.authority = response.idpSetting.idpAuthority;
            config.client_id = response.idpSetting.idpClientId;
            config.redirect_uri = response.idpSetting.idpRedirectUri;
           // i want to reupdate the Config setting here instead of recall the contructor
            mgr = new Oidc.UserManager(config);
        });
brockallen commented 3 years ago

Just create a new instance?

ismeddnl commented 3 years ago

actually, i dont want to create a new instance, i just want to reupdate the config to usermanager after api call.

ismeddnl commented 3 years ago

Hi @brockallen , i got the solution , i just reupdated the setting like this ,

apisettingcall().then(function (response) {
            mgr._settings._authority = "https://localhost/idserv";
            mgr._settings._client_id = response.idpSetting.idpClientId;
            mgr._settings._redirect_uri = response.idpSetting.idpRedirectUri;
            mgr._settings._post_logout_redirect_uri = response.idpSetting.idpPostLogoutUri;
            mgr._settings._popup_redirect_uri = response.idpSetting.idpRedirectUri;
            mgr._settings._silent_redirect_uri = response.idpSetting.idpSilentRedirectUri;
        });
mellis481 commented 3 years ago

Just create a new instance?

@brockallen Are there any caveats to creating a second user manager instance? For instance, would all instances have to call singinCallback() on the login callback?

brockallen commented 3 years ago

The design is that only one instance runs on a page.