我一直在尝试使用string.split
jwtHelper
获取jwtHeler.decodeToken(token).iat
错误。如何将字符串检索为字符串而不是承诺?
这是我记录token
t {__zone_symbol__state: null, __zone_symbol__value: Array(0)}
__zone_symbol__state:true
__zone_symbol__value:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzMjkiLCJpc3MiOiJodHRwOlwvXC9wcm9qZWN0cy5zdGFybGluZXdpbmRvd3MuY29tXC9yZWZyZXNoIiwiaWF0IjoxNTAxMTY
刷新功能
public scheduleRefresh() {
let source = this.authHttp.tokenStream.flatMap(
token => {
console.log("token=", token);
let jwtIat = this.jwtHelper.decodeToken(token).iat;
let jwtExp = this.jwtHelper.decodeToken(token).exp;
let iat = new Date(0);
let exp = new Date(0);
let delay = (exp.setUTCSeconds(jwtExp) - iat.setUTCSeconds(jwtIat));
return Observable.interval(delay);
});
this.refreshSubscription = source.subscribe(() => {
this.refresh().subscribe((res) => console.log('-> Refreshed...'),
(error) => console.log('Refresh error: ' + JSON.stringify(error)))
});
}
}
app.module.ts
export function getAuthHttp(http, storage) {
return new AuthHttp(new AuthConfig({
headerName: 'Authorization',
headerPrefix: 'Bearer',
noJwtError: true,
globalHeaders: [{'Accept': 'application/json', 'Content-Type': 'application/json', 'X-Requested-With': 'XMLHttpRequest'}],
tokenGetter: (() => storage.ready().then(() => storage.get('token')))
}), http);
}