Search in sources :

Example 6 with AccessToken

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);
    }
}
Also used : IAuthenticationResult(com.microsoft.aad.msal4j.IAuthenticationResult) AccessToken(com.azure.core.credential.AccessToken)

Example 7 with 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);
}
Also used : Expectations(mockit.Expectations) TokenRequestContext(com.azure.core.credential.TokenRequestContext) AccessToken(com.azure.core.credential.AccessToken) TokenCredentialCache(com.microsoft.azure.sdk.iot.service.auth.TokenCredentialCache) Test(org.junit.Test)

Aggregations

AccessToken (com.azure.core.credential.AccessToken)7 TokenRequestContext (com.azure.core.credential.TokenRequestContext)4 TokenCredentialCache (com.microsoft.azure.sdk.iot.service.auth.TokenCredentialCache)4 Expectations (mockit.Expectations)4 Test (org.junit.Test)4 OffsetDateTime (java.time.OffsetDateTime)2 IAuthenticationResult (com.microsoft.aad.msal4j.IAuthenticationResult)1 Duration (java.time.Duration)1 UUID (java.util.UUID)1