use of com.azure.core.credential.AccessToken in project ambry by linkedin.
the class ADAuthBasedStorageClient method refreshToken.
private void refreshToken() throws MalformedURLException, ExecutionException, InterruptedException {
IAuthenticationResult iAuthenticationResult = getAccessTokenByClientCredentialGrant(azureCloudConfig);
AccessToken accessToken = new AccessToken(iAuthenticationResult.accessToken(), iAuthenticationResult.expiresOnDate().toInstant().atOffset(OffsetDateTime.now().getOffset()));
if (accessTokenRef == null) {
accessTokenRef = new AtomicReference<>(accessToken);
} else {
accessTokenRef.set(accessToken);
}
}
use of com.azure.core.credential.AccessToken in project azure-iot-sdk-java by Azure.
the class TokenCredentialCacheTest method tokenCredentialCachesToken.
@Test
public void tokenCredentialCachesToken() {
TokenCredentialCache cache = new TokenCredentialCache(mockTokenCredential);
new Expectations() {
{
mockTokenCredential.getToken((TokenRequestContext) any).block();
result = mockAccessToken;
mockAccessToken.getExpiresAt();
result = OffsetDateTime.MAX;
}
};
AccessToken accessToken = cache.getAccessToken();
AccessToken accessToken2 = cache.getAccessToken();
assertEquals(mockAccessToken, accessToken);
assertEquals(mockAccessToken, accessToken2);
}
Aggregations