Search in sources :

Example 1 with AuthorizationStrategy

use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockStrategyWithMockedHttpResponse method requestAuthorization.

/**
 * Template method for executing an OAuth2 authorization request.
 *
 * @param request               microsoft sts authorization request.
 * @param authorizationStrategy authorization strategy.
 * @return GenericAuthorizationResponse
 */
@Override
public Future<AuthorizationResult> requestAuthorization(final MicrosoftStsAuthorizationRequest request, final AuthorizationStrategy authorizationStrategy) {
    final MockSuccessAuthorizationResultMockedTests authorizationResult = new MockSuccessAuthorizationResultMockedTests();
    final ResultFuture<AuthorizationResult> future = new ResultFuture<>();
    future.setResult(authorizationResult);
    return future;
}
Also used : ResultFuture(com.microsoft.identity.common.internal.result.ResultFuture) MockSuccessAuthorizationResultMockedTests(com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultMockedTests) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)

Example 2 with AuthorizationStrategy

use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class ResourceOwnerPasswordCredentialsTestStrategy method requestAuthorization.

/**
 * Template method for executing an OAuth2 authorization request.
 *
 * @param request               microsoft sts authorization request.
 * @param authorizationStrategy authorization strategy.
 * @return GenericAuthorizationResponse
 */
@Override
public Future<AuthorizationResult> requestAuthorization(final MicrosoftStsAuthorizationRequest request, final AuthorizationStrategy authorizationStrategy) {
    final MockSuccessAuthorizationResultNetworkTests authorizationResult = new MockSuccessAuthorizationResultNetworkTests();
    final ResultFuture<AuthorizationResult> future = new ResultFuture<>();
    future.setResult(authorizationResult);
    return future;
}
Also used : ResultFuture(com.microsoft.identity.common.internal.result.ResultFuture) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) MockSuccessAuthorizationResultNetworkTests(com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultNetworkTests)

Example 3 with AuthorizationStrategy

use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class LocalMSALController method performAuthorizationRequest.

// Suppressing rawtype warnings due to the generic types AuthorizationResult and OAuth2Strategy
@SuppressWarnings(WarningType.rawtype_warning)
private AuthorizationResult performAuthorizationRequest(@NonNull final OAuth2Strategy strategy, @NonNull final Context context, @NonNull final InteractiveTokenCommandParameters parameters) throws ExecutionException, InterruptedException, ClientException {
    throwIfNetworkNotAvailable(context, parameters.isPowerOptCheckEnabled());
    mAuthorizationStrategy = AuthorizationStrategyFactory.getInstance().getAuthorizationStrategy(parameters);
    mAuthorizationRequest = getAuthorizationRequest(strategy, parameters);
    // Suppressing unchecked warnings due to casting of AuthorizationRequest to GenericAuthorizationRequest and AuthorizationStrategy to GenericAuthorizationStrategy in the arguments of call to requestAuthorization method
    @SuppressWarnings(WarningType.unchecked_warning) final Future<AuthorizationResult> future = strategy.requestAuthorization(mAuthorizationRequest, mAuthorizationStrategy);
    final AuthorizationResult result = future.get();
    return result;
}
Also used : AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)

Example 4 with AuthorizationStrategy

use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class MockTestStrategy method requestAuthorization.

/**
 * Template method for executing an OAuth2 authorization request.
 *
 * @param request               microsoft sts authorization request.
 * @param authorizationStrategy authorization strategy.
 * @return GenericAuthorizationResponse
 */
@Override
public Future<AuthorizationResult> requestAuthorization(final MicrosoftStsAuthorizationRequest request, final AuthorizationStrategy authorizationStrategy) {
    final MockSuccessAuthorizationResultMockedTests authorizationResult = new MockSuccessAuthorizationResultMockedTests();
    final ResultFuture<AuthorizationResult> future = new ResultFuture<>();
    future.setResult(authorizationResult);
    return future;
}
Also used : ResultFuture(com.microsoft.identity.common.internal.result.ResultFuture) MockSuccessAuthorizationResultMockedTests(com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultMockedTests) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)

Example 5 with AuthorizationStrategy

use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class ConfidentialClientHelper method requestAccessTokenForAutomation.

/**
 * Yep.  Hardcoding this method to retrieve access token for MSIDLABS
 */
private String requestAccessTokenForAutomation() throws CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, IOException {
    String accessToken = null;
    final TokenRequest tokenRequest = this.createTokenRequest();
    tokenRequest.setGrantType(CLIENT_CREDENTIALS);
    final AccountsInOneOrganization aadAudience = new AccountsInOneOrganization(TENANT_ID);
    final AzureActiveDirectoryAuthority authority = new AzureActiveDirectoryAuthority(aadAudience);
    try {
        final OAuth2StrategyParameters strategyParameters = new OAuth2StrategyParameters();
        OAuth2Strategy<AccessToken, BaseAccount, AuthorizationRequest, AuthorizationRequest.Builder, AuthorizationStrategy, OAuth2Configuration, OAuth2StrategyParameters, AuthorizationResponse, RefreshToken, TokenRequest, TokenResponse, TokenResult, AuthorizationResult> strategy = authority.createOAuth2Strategy(strategyParameters);
        TokenResult tokenResult = strategy.requestToken(tokenRequest);
        if (tokenResult.getSuccess()) {
            accessToken = tokenResult.getTokenResponse().getAccessToken();
        } else {
            throw new RuntimeException(tokenResult.getErrorResponse().getErrorDescription());
        }
    } catch (final ClientException e) {
        e.printStackTrace();
    }
    return accessToken;
}
Also used : AuthorizationStrategy(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy) AuthorizationRequest(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationRequest) TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) OAuth2StrategyParameters(com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) AuthorizationResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResponse) RefreshToken(com.microsoft.identity.common.internal.providers.oauth2.RefreshToken) TokenResponse(com.microsoft.identity.common.internal.providers.oauth2.TokenResponse) AccessToken(com.microsoft.identity.common.internal.providers.oauth2.AccessToken) BaseAccount(com.microsoft.identity.common.BaseAccount) AccountsInOneOrganization(com.microsoft.identity.common.internal.authorities.AccountsInOneOrganization) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) AzureActiveDirectoryAuthority(com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority) OAuth2Configuration(com.microsoft.identity.common.internal.providers.oauth2.OAuth2Configuration) ClientException(com.microsoft.identity.common.exception.ClientException)

Aggregations

AuthorizationResult (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)5 ResultFuture (com.microsoft.identity.common.internal.result.ResultFuture)3 MockSuccessAuthorizationResultMockedTests (com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultMockedTests)2 BaseAccount (com.microsoft.identity.common.BaseAccount)1 ClientException (com.microsoft.identity.common.exception.ClientException)1 AccountsInOneOrganization (com.microsoft.identity.common.internal.authorities.AccountsInOneOrganization)1 AzureActiveDirectoryAuthority (com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority)1 AccessToken (com.microsoft.identity.common.internal.providers.oauth2.AccessToken)1 AuthorizationRequest (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationRequest)1 AuthorizationResponse (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResponse)1 AuthorizationStrategy (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationStrategy)1 OAuth2Configuration (com.microsoft.identity.common.internal.providers.oauth2.OAuth2Configuration)1 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)1 RefreshToken (com.microsoft.identity.common.internal.providers.oauth2.RefreshToken)1 TokenRequest (com.microsoft.identity.common.internal.providers.oauth2.TokenRequest)1 TokenResponse (com.microsoft.identity.common.internal.providers.oauth2.TokenResponse)1 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)1 MockSuccessAuthorizationResultNetworkTests (com.microsoft.identity.internal.testutils.mocks.MockSuccessAuthorizationResultNetworkTests)1