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

Help needed on , STS logout then silent renew force to sign in #1388

Open ebinroy opened 3 years ago

ebinroy commented 3 years ago

Hi All, if STS user has logout then silent renew will be called. In silent renew I will get the query string error="login_required". I tried to the below code but I would like to redirect to the STS login again

function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

//same as the auth config settings
const stsSettings = {
authority: "https://localhost:5000/",
client_id: "AngularClient",
scope: "openid profile api1",
response_type: "code",

redirect_uri: "http://localhost:4200/signin-callback",
};

var errParam = getParameterByName('error');
console.log("errParam ====> ", errParam);

//STS user logout then remove the User
if (errParam == "login_required"){
//redirect the user to STS for sign-in????????
new Oidc.UserManager(stsSettings).removeUser();
}
else{
new Oidc.UserManager(stsSettings).signinSilentCallback();
}

instead of this code new Oidc.UserManager(stsSettings).removeUser();I have tried new Oidc.UserManager(stsSettings).signinRedirectCallback(); and new Oidc.UserManager(stsSettings).signoutRedirectCallback(); but nothing is working.

Please help me to achieve this.