@@ -207,8 +207,10 @@ void saveTokens(TokenRequestExecutor tokenRequestExecutor, AuthenticationResult
207
207
idTokens .put (idTokenEntity .getKey (), idTokenEntity );
208
208
209
209
AccountCacheEntity accountCacheEntity = authenticationResult .accountCacheEntity ();
210
- accountCacheEntity .environment (environment );
211
- accounts .put (accountCacheEntity .getKey (), accountCacheEntity );
210
+ if (accountCacheEntity !=null ) {
211
+ accountCacheEntity .environment (environment );
212
+ accounts .put (accountCacheEntity .getKey (), accountCacheEntity );
213
+ }
212
214
}
213
215
} finally {
214
216
lock .writeLock ().unlock ();
@@ -533,6 +535,18 @@ private Optional<IdTokenCacheEntity> getIdTokenCacheEntity(
533
535
).findAny ();
534
536
}
535
537
538
+ private Optional <RefreshTokenCacheEntity > getRefreshTokenCacheEntity (
539
+ String clientId ,
540
+ Set <String > environmentAliases ,
541
+ String userAssertionHash ) {
542
+ return refreshTokens .values ().stream ().filter (
543
+ refreshToken ->
544
+ userAssertionHashMatches (refreshToken , userAssertionHash ) &&
545
+ environmentAliases .contains (refreshToken .environment ) &&
546
+ refreshToken .clientId .equals (clientId )
547
+ ).findAny ();
548
+ }
549
+
536
550
private Optional <RefreshTokenCacheEntity > getRefreshTokenCacheEntity (
537
551
IAccount account ,
538
552
String clientId ,
@@ -683,6 +697,11 @@ AuthenticationResult getCachedAuthenticationResult(
683
697
getIdTokenCacheEntity (authority , clientId , environmentAliases , userAssertionHash );
684
698
685
699
idTokenCacheEntity .ifPresent (tokenCacheEntity -> builder .idToken (tokenCacheEntity .secret ));
700
+
701
+ Optional <RefreshTokenCacheEntity > rtCacheEntity = getRefreshTokenCacheEntity (clientId , environmentAliases , userAssertionHash );
702
+
703
+ rtCacheEntity .ifPresent (refreshTokenCacheEntity ->
704
+ builder .refreshToken (refreshTokenCacheEntity .secret ));
686
705
} finally {
687
706
lock .readLock ().unlock ();
688
707
}
0 commit comments