Search in sources :

Example 1 with AuthorizationResult

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

the class AzureActiveDirectoryAuthorizationResultFactoryTest method testNullBundle.

@Test
public void testNullBundle() {
    Intent intent = new Intent();
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, intent, getAADRequest());
    assertNotNull(result);
    assertNull(result.getAuthorizationResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
    assertNotNull(errorResponse);
    assertEquals(MicrosoftAuthorizationErrorResponse.AUTHORIZATION_FAILED, errorResponse.getError());
    assertEquals(MicrosoftAuthorizationErrorResponse.NULL_INTENT, errorResponse.getErrorDescription());
}
Also used : AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) AzureActiveDirectoryAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) AzureActiveDirectoryAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult) Test(org.junit.Test)

Example 2 with AuthorizationResult

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

the class AzureActiveDirectoryAuthorizationResultFactoryTest method testUrlWithInvalidParams.

@Test
public void testUrlWithInvalidParams() {
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    bundle.putString(AuthenticationConstants.Browser.RESPONSE_FINAL_URL, REDIRECT_URI + "?some_random_error=accessdenied");
    intent.putExtras(bundle);
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, intent, getAADRequest());
    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) AzureActiveDirectoryAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) Bundle(android.os.Bundle) Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) AzureActiveDirectoryAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult) Test(org.junit.Test)

Example 3 with AuthorizationResult

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

the class AzureActiveDirectoryAuthorizationResultFactoryTest method testNullIntent.

@Test
public void testNullIntent() {
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, null, getAADRequest());
    assertNotNull(result);
    assertNull(result.getAuthorizationResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
    assertNotNull(errorResponse);
    assertEquals(MicrosoftAuthorizationErrorResponse.AUTHORIZATION_FAILED, errorResponse.getError());
    assertEquals(MicrosoftAuthorizationErrorResponse.NULL_INTENT, errorResponse.getErrorDescription());
}
Also used : AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) AzureActiveDirectoryAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) AzureActiveDirectoryAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult) Test(org.junit.Test)

Example 4 with AuthorizationResult

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

the class AzureActiveDirectoryAuthorizationResultFactoryTest method testUrlWithIncorrectState.

public void testUrlWithIncorrectState() {
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    String responseUrl = REDIRECT_URI + "?" + AUTH_CODE_AND_STATE + "&" + AuthenticationConstants.AAD.CORRELATION_ID + "=" + CORRELATION_ID;
    bundle.putString(AuthenticationConstants.Browser.RESPONSE_FINAL_URL, responseUrl);
    bundle.putString(AuthenticationConstants.AAD.CORRELATION_ID, CORRELATION_ID);
    intent.putExtras(bundle);
    intent.putExtra(MicrosoftAuthorizationResult.REQUEST_STATE_PARAMETER, STATE);
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, intent, getAADRequest());
    assertNotNull(result);
    assertNull(result.getAuthorizationResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
    assertNotNull(errorResponse);
    assertEquals(ErrorStrings.STATE_MISMATCH, errorResponse.getError());
    assertEquals(MicrosoftAuthorizationErrorResponse.STATE_NOT_THE_SAME, errorResponse.getErrorDescription());
}
Also used : AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) AzureActiveDirectoryAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) Bundle(android.os.Bundle) Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) AzureActiveDirectoryAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationResult) MicrosoftAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationResult)

Example 5 with AuthorizationResult

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

the class AzureActiveDirectoryAuthorizationResultFactoryTest method testBrowserCodeRequestResume.

@Test
public void testBrowserCodeRequestResume() {
    Intent intent = new Intent();
    intent.putExtras(new Bundle());
    AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROKER_REQUEST_RESUME, intent, getAADRequest());
    assertNotNull(result);
    assertNull(result.getAuthorizationResponse());
    assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
    AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
    assertNotNull(errorResponse);
    assertEquals(MicrosoftAuthorizationErrorResponse.BROKER_NEEDS_TO_BE_INSTALLED, errorResponse.getError());
    assertEquals(MicrosoftAuthorizationErrorResponse.BROKER_NEEDS_TO_BE_INSTALLED_ERROR_DESCRIPTION, errorResponse.getErrorDescription());
}
Also used : AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) AzureActiveDirectoryAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) Bundle(android.os.Bundle) Intent(android.content.Intent) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) AzureActiveDirectoryAuthorizationResult(com.microsoft.identity.common.internal.providers.microsoft.azureactivedirectory.AzureActiveDirectoryAuthorizationResult) 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