use of com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryOAuth2Strategy in project microsoft-authentication-library-common-for-android by AzureAD.
the class AzureActiveDirectoryClientCredentialsGrantTest method test_ClientCredentials.
@Test
public void test_ClientCredentials() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException {
final CertificateCredential credential = new CertificateCredential.CertificateCredentialBuilder(CLIENT_ID).clientCertificateMetadata(new ClientCertificateMetadata(CERTIFICATE_ALIAS, null)).keyStoreConfiguration(new KeyStoreConfiguration(KEYSTORE_TYPE, KEYSTORE_PROVIDER, null)).build();
final String audience = AAD_CLIENT_ASSERTION_AUDIENCE;
final MicrosoftClientAssertion assertion = new MicrosoftClientAssertion(audience, credential);
final AzureActiveDirectoryTokenRequest tr = new AzureActiveDirectoryTokenRequest();
tr.setClientAssertionType(assertion.getClientAssertionType());
tr.setClientAssertion(assertion.getClientAssertion());
tr.setClientId(CLIENT_ID);
tr.setResourceId(RESOURCE);
tr.setGrantType(GRANT_TYPE);
final OAuth2StrategyParameters options = new OAuth2StrategyParameters();
final OAuth2Strategy strategy = new AzureActiveDirectoryOAuth2Strategy(new AzureActiveDirectoryOAuth2Configuration(), options);
try {
final TokenResult tokenResult = strategy.requestToken(tr);
assertEquals(true, tokenResult.getSuccess());
} catch (final ClientException exception) {
fail("Unexpected exception.");
}
}
use of com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryOAuth2Strategy in project azure-activedirectory-library-for-android by AzureAD.
the class TokenCacheAccessor method updateTokenCacheUsingCommonCache.
void updateTokenCacheUsingCommonCache(final AuthenticationRequest request, final AuthenticationResult result) throws MalformedURLException {
AzureActiveDirectory ad = new AzureActiveDirectory();
AzureActiveDirectoryTokenResponse tokenResponse = CoreAdapter.asAadTokenResponse(result);
AzureActiveDirectoryOAuth2Configuration config = new AzureActiveDirectoryOAuth2Configuration();
config.setAuthorityHostValidationEnabled(this.isValidateAuthorityHost());
if (null != mAuthority) {
config.setAuthorityUrl(new URL(mAuthority));
}
AzureActiveDirectoryOAuth2Strategy strategy = ad.createOAuth2Strategy(config);
AzureActiveDirectoryAuthorizationRequest.Builder aadAuthRequestBuilder = new AzureActiveDirectoryAuthorizationRequest.Builder();
aadAuthRequestBuilder.setClientId(request.getClientId()).setResource(request.getResource()).setScope(request.getResource()).setRedirectUri(request.getRedirectUri()).setLoginHint(request.getLoginHint()).setCorrelationId(request.getCorrelationId());
if (null != mAuthority) {
aadAuthRequestBuilder.setAuthority(new URL(mAuthority));
}
mCommonCache.save(strategy, aadAuthRequestBuilder.build(), tokenResponse);
}
Aggregations