|
7 | 7 | <dom-module id="auth0-auth">
|
8 | 8 |
|
9 | 9 | <template>
|
10 |
| - <template is="dom-if" if="{{jwtManager}}"> |
11 |
| - <jwt-manager name="auth0:authUser" on-auth-token="_handleTokenEvent"></jwt-manager> |
12 |
| - </template> |
| 10 | + <!--<template is="dom-if" if="{{jwtManager}}">--> |
| 11 | + <jwt-manager id="jwtManager" name="auth0:authUser" jwt="[[jwt]]" on-auth-token="_handleTokenEvent"></jwt-manager> |
| 12 | + <!--</template>--> |
13 | 13 | <iron-ajax
|
14 | 14 | id="ajax"
|
15 | 15 | method="DELETE">
|
|
103 | 103 | _parseHash: function(){
|
104 | 104 | var idToken = localStorage.getItem('auth0:authUser');
|
105 | 105 | var accessToken = localStorage.getItem('auth0:accessToken');
|
106 |
| - if (idToken && accessToken) { |
| 106 | + if (idToken && accessToken && this.$.jwtManager.tokenIsValid(idToken)) { |
107 | 107 | this.auth0.client.userInfo(accessToken, function(err, user) {
|
108 | 108 | this._setUserProfile(user);
|
109 | 109 | this._setIdToken(idToken);
|
110 |
| - |
| 110 | + this.$.jwtManager.monitorExpiry(idToken); |
111 | 111 | }.bind(this));
|
112 | 112 | return
|
113 | 113 | }
|
|
120 | 120 | localStorage.setItem('auth0:authUser', authResult.idToken);
|
121 | 121 | localStorage.setItem('auth0:accessToken', authResult.accessToken);
|
122 | 122 | this._setIdToken(authResult.idToken);
|
| 123 | + this.jwt = authResult.idToken; |
123 | 124 | return
|
124 | 125 | } else {
|
125 | 126 | this.auth0.renewAuth({
|
|
137 | 138 | var lock = new Auth0Lock(this.clientId, this.domain, this.options);
|
138 | 139 | lock.show();
|
139 | 140 | } else {
|
| 141 | + console.log('renewAuth........') |
140 | 142 | this.auth0.client.userInfo(result.accessToken, function(err, user) {
|
141 | 143 | this._setUserProfile(user);
|
142 | 144 | }.bind(this));
|
143 |
| - localStorage.setItem('auth0:authUser', result.idToken); |
| 145 | +// localStorage.setItem('auth0:authUser', result.idToken); |
144 | 146 | localStorage.setItem('auth0:accessToken', result.accessToken);
|
| 147 | + this.jwt = result.idToken; |
145 | 148 | this._setIdToken(result.idToken);
|
146 | 149 | }
|
147 | 150 | }.bind(this));
|
|
151 | 154 |
|
152 | 155 | _handleTokenEvent: function (event) {
|
153 | 156 | if(event.detail.status === 'EXPIRED') {
|
154 |
| - this.signOut(this.clientId) |
| 157 | + console.log('expired') |
| 158 | + this.auth0.renewAuth({ |
| 159 | + redirectUri: window.location.origin + '?sso-silent-auth=true', |
| 160 | + scope: this.options.auth.scope, |
| 161 | + usePostMessage: true |
| 162 | + }, function (err, result) { |
| 163 | + if (err || !result || !result.idToken || !result.accessToken) { |
| 164 | + // regular login |
| 165 | + if(this.hostedPages) { |
| 166 | + this.auth0.authorize(this.options.auth); |
| 167 | + return |
| 168 | + } |
| 169 | + //else |
| 170 | + var lock = new Auth0Lock(this.clientId, this.domain, this.options); |
| 171 | + lock.show(); |
| 172 | + } else { |
| 173 | + this.auth0.client.userInfo(result.accessToken, function(err, user) { |
| 174 | + this._setUserProfile(user); |
| 175 | + }.bind(this)); |
| 176 | + localStorage.setItem('auth0:authUser', result.idToken); |
| 177 | + localStorage.setItem('auth0:accessToken', result.accessToken); |
| 178 | + this._setIdToken(result.idToken); |
| 179 | + this.jwt = result.idToken; |
| 180 | + } |
| 181 | + }.bind(this)); |
155 | 182 | }
|
156 | 183 | },
|
157 | 184 |
|
|
0 commit comments