forked from DuendeArchive/identity-model-oidc-client-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSilentRenewService.js
More file actions
44 lines (36 loc) · 1.43 KB
/
SilentRenewService.js
File metadata and controls
44 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
import Log from './Log';
export default class SilentRenewService {
constructor(userManager) {
this._userManager = userManager;
}
start() {
if (!this._callback) {
this._callback = this._tokenExpiring.bind(this);
this._userManager.events.addAccessTokenExpiring(this._callback);
// this will trigger loading of the user so the expiring events can be initialized
this._userManager.getUser().then(user=>{
// deliberate nop
}).catch(err=>{
// catch to suppress errors since we're in a ctor
Log.error("Error from getUser:", err.message);
});
}
}
stop() {
if (this._callback) {
this._userManager.events.removeAccessTokenExpiring(this._callback);
delete this._callback;
}
}
_tokenExpiring() {
Log.debug("SilentRenewService automatically renewing access token");
this._userManager.signinSilent().then(user => {
Log.debug("Silent token renewal successful");
}, err => {
Log.error("Error from signinSilent:", err.message);
this._userManager.events._raiseSilentRenewError(err);
});
}
}