use of com.microsoft.identity.common.internal.providers.keys.KeyStoreConfiguration 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.keys.KeyStoreConfiguration in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftSTSClientCredentialsGrantTest 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 = MSSTS_CLIENT_ASSERTION_AUDIENCE;
final MicrosoftClientAssertion assertion = new MicrosoftClientAssertion(audience, credential);
final TokenRequest tr = new MicrosoftStsTokenRequest();
tr.setClientAssertionType(assertion.getClientAssertionType());
tr.setClientAssertion(assertion.getClientAssertion());
tr.setClientId(CLIENT_ID);
tr.setScope(SCOPE);
tr.setGrantType(GRANT_TYPE);
final OAuth2StrategyParameters options = new OAuth2StrategyParameters();
final OAuth2Strategy strategy = new MicrosoftStsOAuth2Strategy(new MicrosoftStsOAuth2Configuration(), 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.keys.KeyStoreConfiguration in project microsoft-authentication-library-common-for-android by AzureAD.
the class KeyVaultAuthHelper method createTokenRequestWithClientAssertion.
private TokenRequest createTokenRequestWithClientAssertion() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException {
CertificateCredential certificateCredential = new CertificateCredential.CertificateCredentialBuilder(CLIENT_ID).clientCertificateMetadata(new ClientCertificateMetadata(CERTIFICATE_ALIAS, null)).keyStoreConfiguration(new KeyStoreConfiguration(KEYSTORE_TYPE, KEYSTORE_PROVIDER, null)).build();
MicrosoftClientAssertion assertion = new MicrosoftClientAssertion(MSSTS_CLIENT_ASSERTION_AUDIENCE, certificateCredential);
TokenRequest tr = new MicrosoftStsTokenRequest();
tr.setClientAssertionType(assertion.getClientAssertionType());
tr.setClientAssertion(assertion.getClientAssertion());
tr.setClientId(CLIENT_ID);
tr.setScope(SCOPE);
return tr;
}
use of com.microsoft.identity.common.internal.providers.keys.KeyStoreConfiguration in project microsoft-authentication-library-common-for-android by AzureAD.
the class CertificateCredentialBuilder method test_CertificateBuilder_LookupCertificateWithPassword_IsCorrect.
@Test
public void test_CertificateBuilder_LookupCertificateWithPassword_IsCorrect() throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException, NoSuchProviderException, IOException, CertificateException {
PowerMockito.mockStatic(KeyStore.class);
when(KeyStore.getInstance(WINDOWS_MY_KEYSTORE, WINDOWS_KEYSTORE_PROVIDER)).thenReturn(keyStoreMock);
CertificateCredential cred = new CertificateCredential.CertificateCredentialBuilder(CLIENT_ID).keyStoreConfiguration(new KeyStoreConfiguration(WINDOWS_MY_KEYSTORE, WINDOWS_KEYSTORE_PROVIDER, null)).clientCertificateMetadata(new ClientCertificateMetadata(CERTIFICATE_ALIAS, CERTIFICATE_PASSWORD)).build();
assertEquals(privateKey, cred.getPrivateKey());
assertEquals(certificate, cred.getPublicCertificate());
assertEquals(CLIENT_ID, cred.getClientId());
}
use of com.microsoft.identity.common.internal.providers.keys.KeyStoreConfiguration in project microsoft-authentication-library-common-for-android by AzureAD.
the class CertificateCredentialBuilder method test_CertificateBuilder_NoCertificateMetadata_ExpectException.
@Test(expected = IllegalArgumentException.class)
public void test_CertificateBuilder_NoCertificateMetadata_ExpectException() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException {
PowerMockito.mockStatic(KeyStore.class);
when(KeyStore.getInstance(WINDOWS_MY_KEYSTORE, WINDOWS_KEYSTORE_PROVIDER)).thenReturn(keyStoreMock);
CertificateCredential cred = new CertificateCredential.CertificateCredentialBuilder(CLIENT_ID).keyStoreConfiguration(new KeyStoreConfiguration(WINDOWS_MY_KEYSTORE, WINDOWS_KEYSTORE_PROVIDER, null)).build();
}
Aggregations