Search in sources :

Example 16 with AuthorizationResult

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

the class EmbeddedWebViewAuthorizationStrategy method completeAuthorization.

@Override
public void completeAuthorization(int requestCode, int resultCode, Intent data) {
    if (requestCode == AuthenticationConstants.UIRequest.BROWSER_FLOW) {
        if (mOAuth2Strategy != null && mAuthorizationResultFuture != null) {
            // Suppressing unchecked warnings due to method createAuthorizationResult being a member of the raw type AuthorizationResultFactory
            @SuppressWarnings(WarningType.unchecked_warning) final AuthorizationResult result = mOAuth2Strategy.getAuthorizationResultFactory().createAuthorizationResult(resultCode, data, mAuthorizationRequest);
            mAuthorizationResultFuture.setResult(result);
        } else {
            Logger.warn(TAG, "SDK Cancel triggering before request is sent out. " + "Potentially due to an stale activity state, " + "oAuth2Strategy null ? [" + (mOAuth2Strategy == null) + "]" + "mAuthorizationResultFuture ? [" + (mAuthorizationResultFuture == null) + "]");
        }
    } else {
        Logger.warnPII(TAG, "Unknown request code " + requestCode);
    }
}
Also used : AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)

Example 17 with AuthorizationResult

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

the class MicrosoftStsAuthorizationResultFactoryTest method testNoMatchingResultCode.

@Test
public void testNoMatchingResultCode() {
    Intent intent = new Intent();
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(0, intent, getMstsAuthorizationRequest());
    assertNotNull(result);
    assertNull(result.getAuthorizationResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
    assertNotNull(errorResponse);
    assertEquals(MicrosoftAuthorizationErrorResponse.UNKNOWN_ERROR, errorResponse.getError());
    assertEquals(MicrosoftAuthorizationErrorResponse.UNKNOWN_RESULT_CODE, errorResponse.getErrorDescription());
}
Also used : AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) MicrosoftStsAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult) Test(org.junit.Test)

Example 18 with AuthorizationResult

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

the class MicrosoftStsAuthorizationResultFactoryTest method testBrowserCodeError.

@Test
public void testBrowserCodeError() {
    Intent intent = new Intent();
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, intent, getMstsAuthorizationRequest());
    assertNotNull(result);
    assertNull(result.getAuthorizationResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    assertNotNull(result.getAuthorizationErrorResponse());
}
Also used : Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) MicrosoftStsAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult) Test(org.junit.Test)

Example 19 with AuthorizationResult

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

the class MicrosoftStsAuthorizationResultFactoryTest method testUrlWithEmptyParams.

@Test
public void testUrlWithEmptyParams() {
    Intent intent = new Intent();
    intent.putExtra(AUTHORIZATION_FINAL_URL, REDIRECT_URI);
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, intent, getMstsAuthorizationRequest());
    assertNotNull(result);
    assertNull(result.getAuthorizationResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
    assertNotNull(errorResponse);
    assertEquals(MicrosoftAuthorizationErrorResponse.AUTHORIZATION_FAILED, errorResponse.getError());
    assertEquals(MicrosoftAuthorizationErrorResponse.AUTHORIZATION_SERVER_INVALID_RESPONSE, errorResponse.getErrorDescription());
}
Also used : AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) MicrosoftStsAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult) Test(org.junit.Test)

Example 20 with AuthorizationResult

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

the class MicrosoftStsAuthorizationResultFactoryTest method testUrlWithInvalidAuthCodeAndFragmentParas.

@Test
public void testUrlWithInvalidAuthCodeAndFragmentParas() {
    Intent intent = new Intent();
    intent.putExtra(AUTHORIZATION_FINAL_URL, REDIRECT_URI + "?" + FRAGMENT_STRING);
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, intent, getMstsAuthorizationRequest());
    assertNotNull(result);
    assertNotNull(result.getAuthorizationErrorResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
    assertEquals(errorResponse.getError(), MicrosoftAuthorizationErrorResponse.AUTHORIZATION_FAILED);
    assertEquals(errorResponse.getErrorDescription(), MicrosoftAuthorizationErrorResponse.AUTHORIZATION_SERVER_INVALID_RESPONSE);
}
Also used : AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) MicrosoftStsAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult) Test(org.junit.Test)

Aggregations

AuthorizationResult (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)35 MicrosoftAuthorizationResult (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult)22 Test (org.junit.Test)21 Intent (android.content.Intent)20 MicrosoftAuthorizationErrorResponse (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse)20 AuthorizationErrorResponse (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse)20 AzureActiveDirectoryAuthorizationResult (com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationResult)11 MicrosoftStsAuthorizationResult (com.microsoft.identity.common.internal.providers.microsoft.microsoftsts.MicrosoftStsAuthorizationResult)11 AzureActiveDirectoryAuthorizationErrorResponse (com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationErrorResponse)10 Bundle (android.os.Bundle)8 ClientException (com.microsoft.identity.common.exception.ClientException)5 OAuth2StrategyParameters (com.microsoft.identity.common.internal.providers.oauth2.OAuth2StrategyParameters)4 ServiceException (com.microsoft.identity.common.exception.ServiceException)3 OAuth2Strategy (com.microsoft.identity.common.internal.providers.oauth2.OAuth2Strategy)3 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)3 AcquireTokenResult (com.microsoft.identity.common.internal.result.AcquireTokenResult)3 ResultFuture (com.microsoft.identity.common.internal.result.ResultFuture)3 ApiEndEvent (com.microsoft.identity.common.internal.telemetry.events.ApiEndEvent)3 ApiStartEvent (com.microsoft.identity.common.internal.telemetry.events.ApiStartEvent)3 ArgumentException (com.microsoft.identity.common.exception.ArgumentException)2