No user in signinSilentCallback using identityserver and oidc client of javascript

≯℡__Kan透↙ 提交于 2019-12-05 21:45:37

signinSilentCallback: Returns promise to notify the parent window of response from the authorization endpoint. https://github.com/IdentityModel/oidc-client-js/wiki

signinSilentCallback - This is not something will return you the user object.

If you really need to get the user object on silent renew i would suggest to use this approach with folloowing code snippet. This works for me in salesforce apps as well.

this.userManager.events.addAccessTokenExpiring(() =>
            {
                this.userManager.signinSilent({scope: oidcSettings.scope, response_type: oidcSettings.response_type})
                    .then((user: CoreApi.Authentication.Interfaces.OidcClientUser) =>
                    {
                        this.handleUser(user); // This function just set the current user
                    })
                    .catch((error: Error) =>
                    {
                        this.userManager.getUser()
                            .then((user: CoreApi.Authentication.Interfaces.OidcClientUser) =>
                            {
                                this.handleUser(user);
                            });
                    });
            });

We need to handle the getUser in catch as well due to one of bug reported for iFrame in oidc-client js

From above code focus on the way the silent renew is performed when the token expires.

you can set automaticSilentRenew to true in your config

var mgr = new UserManager({
                authority: "http://localhost:5000",
                client_id: "js",
                redirect_uri: "http://localhost:50144/signin-oidc",
                silent_redirect_uri: "http://localhost:50144/signin-oidc",
                response_type: "id_token token",
                post_logout_redirect_uri: "http://localhost:50144/signout-callback-oidc",
                automaticSilentRenew: true; //here

            });

and you can use UserManager events to load the new user when the token is refreshed

this.mgr.events.addUserLoaded(args => {
  this.mgr.getUser().then(user => {
    this._user = user; // load the new user
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!