use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest 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.oauth2.TokenRequest 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.oauth2.TokenRequest in project microsoft-authentication-library-common-for-android by AzureAD.
the class KeyVaultAuthHelper method createTokenRequestWithClientSecret.
private TokenRequest createTokenRequestWithClientSecret() {
TokenRequest tr = new MicrosoftStsTokenRequest();
tr.setClientSecret(mSecret);
tr.setClientId(CLIENT_ID);
tr.setScope(SCOPE);
return tr;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest in project microsoft-authentication-library-common-for-android by AzureAD.
the class KeyVaultAuthHelper method createTokenRequestWithClientSecret.
private TokenRequest createTokenRequestWithClientSecret(@NonNull final String secret) {
TokenRequest tr = new MicrosoftStsTokenRequest();
tr.setClientSecret(secret);
tr.setClientId(CLIENT_ID);
tr.setScope(SCOPE);
return tr;
}
use of com.microsoft.identity.common.internal.providers.oauth2.TokenRequest in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockTestStrategy method performTokenRequest.
@Override
protected HttpResponse performTokenRequest(final MicrosoftStsTokenRequest tokenRequest) {
final TokenResult tokenResult = getTokenResult();
final TokenResponse tokenResponse = tokenResult.getTokenResponse();
final HttpResponse httpResponse = makeHttpResponseFromResponseObject(tokenResponse);
return httpResponse;
}
Aggregations