3232use OCP \ISession ;
3333use OCP \IURLGenerator ;
3434use OCP \IUserSession ;
35+ use OCP \AppFramework \Utility \ITimeFactory ;
3536use OCP \Lock \ILockingProvider ;
3637use OCP \Lock \LockedException ;
3738use OCP \PreConditionNotMetException ;
@@ -67,11 +68,12 @@ public function __construct(
6768 private DiscoveryService $ discoveryService ,
6869 private ProviderMapper $ providerMapper ,
6970 private ILockingProvider $ lockingProvider ,
71+ private ITimeFactory $ timeFactory ,
7072 ) {
7173 }
7274
7375 public function storeToken (array $ tokenData ): Token {
74- $ token = new Token ($ tokenData );
76+ $ token = new Token ($ tokenData, $ this -> timeFactory );
7577 $ this ->session ->set (self ::SESSION_TOKEN_KEY , json_encode ($ token , JSON_THROW_ON_ERROR ));
7678 $ this ->logger ->debug ('[TokenService] Store token in the session ' , ['session_id ' => $ this ->session ->getId ()]);
7779 return $ token ;
@@ -93,7 +95,7 @@ public function getToken(bool $refreshIfExpired = true): ?Token {
9395 return null ;
9496 }
9597
96- $ token = new Token (json_decode ($ sessionData , true , 512 , JSON_THROW_ON_ERROR ));
98+ $ token = new Token (json_decode ($ sessionData , true , 512 , JSON_THROW_ON_ERROR ), $ this -> timeFactory );
9799 // token is still valid
98100 if (!$ token ->isExpired ()) {
99101 $ this ->logger ->debug ('[TokenService] getToken: token is still valid, it expires in ' . strval ($ token ->getExpiresInFromNow ()) . ' and refresh expires in ' . strval ($ token ->getRefreshExpiresInFromNow ()));
@@ -225,7 +227,7 @@ public function refresh(Token $token): Token {
225227 // the token expiration and the moment it attempted to acquire the lock
226228 $ sessionData = $ this ->session ->get (self ::SESSION_TOKEN_KEY );
227229 if ($ sessionData ) {
228- $ currentToken = new Token (json_decode ($ sessionData , true , 512 , JSON_THROW_ON_ERROR ));
230+ $ currentToken = new Token (json_decode ($ sessionData , true , 512 , JSON_THROW_ON_ERROR ), $ this -> timeFactory );
229231 if (!$ currentToken ->isExpired ()) {
230232 $ this ->logger ->debug ('[TokenService] Token already refreshed by another request ' );
231233 return $ currentToken ;
@@ -368,7 +370,7 @@ public function getExchangedToken(string $targetAudience, array $extraScopes = [
368370 $ bodyArray ,
369371 ['provider_id ' => $ loginToken ->getProviderId ()],
370372 );
371- return new Token ($ tokenData );
373+ return new Token ($ tokenData, $ this -> timeFactory );
372374 } catch (ClientException |ServerException $ e ) {
373375 $ response = $ e ->getResponse ();
374376 $ body = (string )$ response ->getBody ();
@@ -439,6 +441,6 @@ public function getTokenFromOidcProviderApp(string $userId, string $targetAudien
439441 'refresh_expires_in ' => method_exists ($ generationEvent , 'getRefreshExpiresIn ' )
440442 ? $ generationEvent ->getRefreshExpiresIn ()
441443 : $ generationEvent ->getExpiresIn (),
442- ]);
444+ ], $ this -> timeFactory );
443445 }
444446}
0 commit comments