我们尝试使用Oidc-客户端库无声地更新令牌(刷新令牌)。我们成功登录了。但是,一旦用户的令牌过期,静默回调页就不会被调用,即使配置如下。如果有任何遗漏或重新纠正,请提供帮助。此外,静默重定向uri作为redirect_uri之一配置在标识服务器中。
Login.ts
Office.initialize = function () {
var settings = {
authority: "https://xxxx.xxxxx.com/xxxx/v1",
client_id: "https://xxx.xxx.com/",
redirect_uri: "https://localhost:3000/taskpane.html",
post_logout_redirect_uri: "https://localhost:3000/logout.html",
revokeAccessTokenOnSignout: true,
response_type: "id_token token",
scope: "openid read:xxxx read:xxxx",
state: true,
filterProtocolClaims: true,
loadUserInfo: true,
nonce:true,
clearHashAfterLogin: true,
automaticSilentRenew: true,
silent_redirect_uri: 'https://localhost:3000/silent-refresh.html',
monitorsession:true,
metadata: {
issuer: 'https://xxx.xxx.com/xxx/v1',
authorization_endpoint: "https://xxx.xxx.com/xxxxx/v1/connect/authorize"
}
};
var mgr = new Oidc.UserManager(settings);
mgr.signinRedirect();
mgr.events.addAccessTokenExpiring(function(){
console.log("token expiring...");
});
}silent-refresh.html
<head>
<title>RefreshToken</title>
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
</head>
<body>
<script type="text/javascript" src=https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.10.0/oidc-client.js></script>
<script>
new Oidc.UserManager().signinSilentCallback().then((user)=>
{ consolse.log("silentrenewed");}
)
.catch((err) => {
console.log(err);
});
</script>
</body>Auth.ts
import { UserManager, WebStorageStateStore } from "oidc-client";
export default class AuthSigninService {
private userManager: UserManager;
constructor() {
const settings: any = {
..................
automaticSilentRenew: true,
accessTokenExpiringNotificationTime: 4,
silent_redirect_uri: "https://localhost:3000/taskpane.html",
monitorsession:false,
};
this.userManager = new UserManager(settings);
}
public signin()
{
return this.userManager.signinRedirect();
}
public async silentRenew() {
try {
const user = await this.userManager.signinSilentCallback().then((success) => {
console.log("silentrenewed");
console.log(success);
}
)
.catch((err) => {
console.log(err);
});
}
catch (err) {
console.log(err);
}
}
}taskpane.ts
document.getElementById('btnSilent').onclick = SilentRenew;
async function SilentRenew() {
const auth = new AuthSigninService();
auth.silentRenew();
}发布于 2020-08-05 22:05:31
可能的原因:
,我会尝试什么,
与比较的东西
我的代码样本做如果沉默更新和水疗代码可能会给你一些想法。
我倾向于将无声的更新URI设置为主index.html页面,这比较简单。然后编写如下代码:
if (window.top === window.self) {
// If index.html is running on the main window, run the app
const app = new App();
app.execute();
} else {
// If index.html is running on an iframe, handle token renewal responses
const app = new IFrameApp();
app.execute();
}顺便说一下,这是我的OAuth代码。
https://stackoverflow.com/questions/63270087
复制相似问题