zavadil-ts-common 1.1.55 → 1.1.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import {AccessTokenPayload, IdTokenPayload, OAuthRestClient} from "./OAuthRestClient";
2
2
  import {EventManager} from "../component";
3
+ import {DateUtil} from "../util";
3
4
 
4
5
  /**
5
6
  * Manages refresh of id and access tokens.
@@ -28,8 +29,8 @@ export class OAuthTokenManager {
28
29
 
29
30
  isTokenExpired(expires?: Date | null): boolean {
30
31
  if (expires === undefined || expires === null) return false;
31
- const now = Date.now();
32
- const exp = new Date(expires).getTime();
32
+ const now = new Date();
33
+ const exp = DateUtil.parseDate(expires) || now;
33
34
  return (exp < now);
34
35
  }
35
36
 
@@ -48,16 +48,15 @@ export class RestClientWithOAuth extends RestClient {
48
48
  */
49
49
  initialize(): Promise<boolean> {
50
50
  return this.initializeIdToken()
51
- .then(
52
- () => this.checkAccessToken()
53
- .catch(
54
- () => this.getServerInfo().then(
55
- (si) => {
56
- document.location = `${si.oauthServerUrl}/login?app_name=${si.targetAudience}&redirect_url=${document.location}`;
57
- return Promise.resolve(false);
58
- }
59
- )
60
- )
51
+ .then(() => this.checkAccessToken())
52
+ .catch(
53
+ () => this.getServerInfo().then(
54
+ (si) => {
55
+ const documentlocation = `${si.oauthServerUrl}/login?app_name=${si.targetAudience}&redirect_url=${document.location}`;
56
+ console.log('redirect', documentlocation);
57
+ return Promise.resolve(false);
58
+ }
59
+ )
61
60
  );
62
61
  }
63
62