当我们有额外的查询参数时,在 oidc-client.js 中静默更新
Silent renew in oidc-client.js when we have extra query params
我遇到了以下错误
我有以下 UserManagerSettings
private getClientSettings(loginType?): UserManagerSettings {
let logout;
if (window.sessionStorage.getItem('loginType') === 'Internal') {
logout = environment.post_logout_redirect_uri + 'biz-admin';
} else {
logout = environment.post_logout_redirect_uri;
}
return {
authority: environment.authority,
client_id: environment.client,
redirect_uri: environment.redirectUri,
post_logout_redirect_uri: logout,
response_type: 'id_token token',
scope: environment.scopes,
filterProtocolClaims: true,
silent_redirect_uri: 'http://localhost:4200/assets/silent-refresh.html',
loadUserInfo: true,
extraQueryParams: {
loginType: loginType,
},
};
}
下面添加一个过期事件
this.manager.events.addAccessTokenExpiring(x => {
this.renewToken().then(u => {
this.user = u;
});
});
以下函数呼号无声
public renewToken(): Promise<User> {
return this.manager.signinSilent(this.getClientSettings('Internal'));
}
静音-refresh.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.7.0/oidc-client.js"></script>
<script>
var mgr = new Oidc.UserManager();
mgr.signinSilentCallback().catch(error => {
console.error(error);
});
</script>
URI,我有基于登录类型的自定义逻辑
redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fassets%2Fsilent-refresh.html&response_type=id_token&scope=openid&state=307b01d8e3234027b92e0f2920364d4a&nonce=c8d110e677bd4fc8a993b77798893edf&prompt=none&loginType=undefined
此外,我在数据库中有正确的重定向 URI,但更新仍然不起作用。 renewtoken()
被调用但永远不会返回到 'then' 代码。
问题 -
- silent renew是如何做到access_token的?它是否从某处获取保存的 ID 密码?
- 如何向
signInSilent()
发送额外的查询参数,即使在我将其作为参数传递后它仍未定义,signInSilent()
如何获取用户管理器设置?
我按照以下步骤设法解决了我的问题-
启动
services.AddIdentityServer(options =>
{
options.Authentication.CookieLifetime = TimeSpan.FromDays(30);
options.Authentication.CookieSlidingExpiration = true;
})
services.AddAuthentication(x => x.DefaultAuthenticateScheme = IdentityServer4.IdentityServerConstants.DefaultCookieAuthenticationScheme);
注销
public async Task<IActionResult> Logout(LogoutInputModel model) { await HttpContext.SignOutAsync(IdentityServer4.IdentityServerConstants.DefaultCookieAuthenticationScheme);}
angular这边什么都没有,我们需要在identity server code
配置上面的设置
感谢以下用户的评论
https://github.com/IdentityModel/oidc-client-js/issues/911#issuecomment-617724445
我遇到了以下错误
我有以下 UserManagerSettings
private getClientSettings(loginType?): UserManagerSettings {
let logout;
if (window.sessionStorage.getItem('loginType') === 'Internal') {
logout = environment.post_logout_redirect_uri + 'biz-admin';
} else {
logout = environment.post_logout_redirect_uri;
}
return {
authority: environment.authority,
client_id: environment.client,
redirect_uri: environment.redirectUri,
post_logout_redirect_uri: logout,
response_type: 'id_token token',
scope: environment.scopes,
filterProtocolClaims: true,
silent_redirect_uri: 'http://localhost:4200/assets/silent-refresh.html',
loadUserInfo: true,
extraQueryParams: {
loginType: loginType,
},
};
}
下面添加一个过期事件
this.manager.events.addAccessTokenExpiring(x => {
this.renewToken().then(u => {
this.user = u;
});
});
以下函数呼号无声
public renewToken(): Promise<User> {
return this.manager.signinSilent(this.getClientSettings('Internal'));
}
静音-refresh.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.7.0/oidc-client.js"></script>
<script>
var mgr = new Oidc.UserManager();
mgr.signinSilentCallback().catch(error => {
console.error(error);
});
</script>
URI,我有基于登录类型的自定义逻辑
redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fassets%2Fsilent-refresh.html&response_type=id_token&scope=openid&state=307b01d8e3234027b92e0f2920364d4a&nonce=c8d110e677bd4fc8a993b77798893edf&prompt=none&loginType=undefined
此外,我在数据库中有正确的重定向 URI,但更新仍然不起作用。 renewtoken()
被调用但永远不会返回到 'then' 代码。
问题 -
- silent renew是如何做到access_token的?它是否从某处获取保存的 ID 密码?
- 如何向
signInSilent()
发送额外的查询参数,即使在我将其作为参数传递后它仍未定义,signInSilent()
如何获取用户管理器设置?
我按照以下步骤设法解决了我的问题-
启动
services.AddIdentityServer(options =>
{
options.Authentication.CookieLifetime = TimeSpan.FromDays(30);
options.Authentication.CookieSlidingExpiration = true;
})
services.AddAuthentication(x => x.DefaultAuthenticateScheme = IdentityServer4.IdentityServerConstants.DefaultCookieAuthenticationScheme);
注销
public async Task<IActionResult> Logout(LogoutInputModel model) { await HttpContext.SignOutAsync(IdentityServer4.IdentityServerConstants.DefaultCookieAuthenticationScheme);}
angular这边什么都没有,我们需要在identity server code
配置上面的设置感谢以下用户的评论 https://github.com/IdentityModel/oidc-client-js/issues/911#issuecomment-617724445