@@ -81,8 +81,10 @@ export default Service.extend({
8181 if ( ! tokenName ) {
8282 return ;
8383 }
84+
8485 const { tokenExpirationEpoch } = this . getTokenData ( tokenName ) ;
8586 const expirationDate = new Date ( 0 ) ;
87+
8688 return tokenExpirationEpoch ? expirationDate . setUTCMilliseconds ( tokenExpirationEpoch ) : null ;
8789 } ) ,
8890
@@ -216,9 +218,17 @@ export default Service.extend({
216218 } ,
217219
218220 calculateExpiration ( resp ) {
219- const now = this . now ( ) ;
221+ let tokenExpirationEpoch ;
220222 const ttl = resp . ttl || resp . lease_duration ;
221- const tokenExpirationEpoch = now + ttl * 1e3 ;
223+ const now = this . now ( ) ;
224+
225+ if ( resp . type === 'batch' ) {
226+ const expireTime = resp . expire_time ;
227+ tokenExpirationEpoch = new Date ( expireTime ) . getTime ( ) ;
228+ } else {
229+ tokenExpirationEpoch = now + ttl * 1e3 ;
230+ }
231+
222232 this . set ( 'expirationCalcTS' , now ) ;
223233 return {
224234 ttl,
@@ -296,21 +306,16 @@ export default Service.extend({
296306 resp . policies
297307 ) ;
298308
299- if ( resp . renewable ) {
300- Object . assign ( data , this . calculateExpiration ( resp ) ) ;
301- } else if ( resp . type === 'batch' ) {
302- // if it's a batch token, it's not renewable but has an expire time
303- // so manually set tokenExpirationEpoch and allow expiration
304- data . tokenExpirationEpoch = new Date ( resp . expire_time ) . getTime ( ) ;
305- this . set ( 'allowExpiration' , true ) ;
306- }
309+ Object . assign ( data , this . calculateExpiration ( resp ) ) ;
307310
308311 if ( ! data . displayName ) {
309312 data . displayName = ( this . getTokenData ( tokenName ) || { } ) . displayName ;
310313 }
314+
311315 this . set ( 'tokens' , addToArray ( this . tokens , tokenName ) ) ;
312316 this . set ( 'allowExpiration' , false ) ;
313317 this . setTokenData ( tokenName , data ) ;
318+
314319 return resolve ( {
315320 namespace : currentNamespace || data . userRootNamespace ,
316321 token : tokenName ,
0 commit comments