javascript - 错误:没有响应 oidc-client.js 的状态
问题描述
注销后,我收到此错误“无响应状态”。它涉及回调 url ,在那里停留了一段时间然后出错。但是刷新后,状态被附加到 URL 并且页面将我带到预期的登录页面,并显示成功注销的消息。
注销时出错https://app.something.url?device=desktop#/oops/No%20state%20in%20response
我的代码如下:
用户管理器实例创建
window.__env = window.__env || {};
var metadataParams = {
issuer: window.__env.ssoUrl,
jwks_uri: window.__env.ssoUrl + '/XX/JWKS', // JSON web key contains encryption information used to validate the token
authorization_endpoint: window.__env.ssoUrl + '/as/XXXXXX', // Authorisation endpoint
token_endpoint: window.__env.ssoUrl + '/as/XXXXX',
userinfo_endpoint: window.__env.ssoUrl + '/idp/XXXXX', // UserInformation endpoint
end_session_endpoint: window.__env.ssoUrl + '/XXX/startXXX.ping' + '?TargetResource=https://' + window.location.hostname + '/somefolder/callback.html' // Logout endpoint
};
window.__env.ssoConfig = {
authority: window.__env.ssoUrl + '/as/XXXXXXX', // AUTH URL on the token during token validation
metadata: metadataParams,
client_id: window.__env.ssoClientId,
redirect_uri: 'https://' + window.location.hostname + '/somefolder/callback.html', // URL where login will redirect
response_type: 'code',
scope: 'XXXXXX',
checkSessionInterval: 10,
silent_redirect_uri:'https://' + window.location.hostname + '/somefolder/callback.html',
automaticSilentRenew: true,
filterProtocolClaims: false,
silentRequestTimeout: 60000,
loadUserInfo: true
};
// create a user manager instance
var userManager = new Oidc.UserManager(window.__env.ssoConfig);
注销方法:
function logMeOut(params, alternateUrl, override, isLogoutButton) {
var gotoUrl;
var idToken = window.__env.idToken;
params = params || {};
// Clear all storage data
AppStoreData.clearData();
sessionStorage.removeItem('appName-ssoHash');
localStorage.clear();
if (override) {
debug.log('there\'s an override');
gotoUrl = alternateUrl ? alternateUrl : '';
} else {
if (tpUID) {
params.tpUID = tpUID;
}
gotoUrl = setRedirectUrl(defaultReturnUrl, destinationParam, type, params);
debug.log(gotoUrl);
}
sessionStorage.setItem('appname-redirect', encodeURI(gotoUrl));
// if logged in, then... log out with gotoUrl appended
if (idToken && isLogoutButton) {
// Run signout
var logoutSSO = userMgr.signoutRedirect();
logoutSSO.then(function() {
debug.log('logout success');
}).catch(function(err) {
debug.log(err);
debug.log('logout fail');
});
}
//else, go to location
else {
if (gotoUrl) {
window.location = gotoUrl;
}
else {
debug.log('oops: no url to go to');
$state.go('oops');
}
}
}
Callback.html 代码如下:
window.onload = function () {
var redirectUrl = decodeURI(sessionStorage.getItem('appName-redirect'));
if (redirectUrl) {
sessionStorage.setItem('appName-signinRedirect', 'true');
// Redirect back to portal
var params = window.location.search.split('?')[1];
// Remove any states
redirectUrl = redirectUrl.split('#/')[0];
// Redirect back
window.location.href = redirectUrl + '&' + params;
}
}
//Dependencies
"oidc-client": "1.8.2"
"angular": "1.5.8",
"@uirouter/angularjs": "0.3.1"
登录成功,没有任何问题
解决方案
推荐阅读
- ios - do I need to embed navigation controller if I want to make custom navigation bar view?
- reactjs - 如何连接日期和时间
- c++ - C++14 中向量的 unordered_map 和擦除删除习语的奇怪行为
- c# - AutoMapper 映射无法正常工作 JObject/Json
- spring - 是否可以从 (SERVER = DEDICATED) 切换到 (SERVER = POOLED)
- r - 如何将 csv 中的时间格式更改为 hh:mm:ss
- ruby-on-rails - 如何在rails中使用ajax获取数据
- laravel - Laravel - timestamp() 和 timestampTz() 有什么区别?
- php - 过滤值时的Laravel条件子句
- pandas - 如何从熊猫去年同月减去价值?