Search in sources :

Example 1 with TokenRequest

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.");
    }
}
Also used : MicrosoftClientAssertion(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftClientAssertion) TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) ClientCertificateMetadata(com.microsoft.identity.common.internal.providers.keys.ClientCertificateMetadata) OAuth2StrategyParameters(com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters) MicrosoftStsOAuth2Strategy(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy) KeyStoreConfiguration(com.microsoft.identity.common.internal.providers.keys.KeyStoreConfiguration) MicrosoftStsOAuth2Strategy(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy) OAuth2Strategy(com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy) CertificateCredential(com.microsoft.identity.common.internal.providers.keys.CertificateCredential) MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest) MicrosoftStsOAuth2Configuration(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Configuration) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest) ClientException(com.microsoft.identity.common.exception.ClientException) Test(org.junit.Test)

Example 2 with TokenRequest

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;
}
Also used : CertificateCredential(com.microsoft.identity.common.internal.providers.keys.CertificateCredential) MicrosoftClientAssertion(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftClientAssertion) MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest) ClientCertificateMetadata(com.microsoft.identity.common.internal.providers.keys.ClientCertificateMetadata) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest) KeyStoreConfiguration(com.microsoft.identity.common.internal.providers.keys.KeyStoreConfiguration)

Example 3 with TokenRequest

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;
}
Also used : MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest)

Example 4 with TokenRequest

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;
}
Also used : MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftStsTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest)

Example 5 with TokenRequest

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;
}
Also used : TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) MockTokenResponse(com.microsoft.identity.internal.testutils.mocks.MockTokenResponse) TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) HttpResponse(com.microsoft.identity.common.internal.net.HttpResponse)

Aggregations

TokenRequest (com.microsoft.identity.common.internal.providers.oauth2.TokenRequest)10 MicrosoftStsTokenRequest (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsTokenRequest)8 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)8 TokenRequest (com.google.api.client.auth.oauth2.TokenRequest)7 GenericUrl (com.google.api.client.http.GenericUrl)6 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)5 IOException (java.io.IOException)5 ClientException (com.microsoft.identity.common.exception.ClientException)4 MicrosoftTokenRequest (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest)4 RefreshTokenRequest (com.google.api.client.auth.oauth2.RefreshTokenRequest)3 TokenResponse (com.google.api.client.auth.oauth2.TokenResponse)3 MicrosoftStsOAuth2Configuration (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Configuration)3 MicrosoftStsOAuth2Strategy (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsOAuth2Strategy)3 Test (org.junit.Test)3 JsonWebSignature (com.google.api.client.json.webtoken.JsonWebSignature)2 JsonWebToken (com.google.api.client.json.webtoken.JsonWebToken)2 Beta (com.google.api.client.util.Beta)2 AzureActiveDirectoryAuthority (com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority)2 HttpResponse (com.microsoft.identity.common.internal.net.HttpResponse)2 CertificateCredential (com.microsoft.identity.common.internal.providers.keys.CertificateCredential)2