Search in sources :

Example 1 with MicrosoftAuthorizationErrorResponse

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

the class ExceptionAdapter method exceptionFromAcquireTokenResult.

@Nullable
public static BaseException exceptionFromAcquireTokenResult(final AcquireTokenResult result, final CommandParameters commandParameters) {
    final String methodName = ":exceptionFromAcquireTokenResult";
    @SuppressWarnings(WarningType.rawtype_warning) final AuthorizationResult authorizationResult = result.getAuthorizationResult();
    if (null != authorizationResult) {
        final AuthorizationErrorResponse authorizationErrorResponse = authorizationResult.getAuthorizationErrorResponse();
        if (!authorizationResult.getSuccess()) {
            // THERE ARE CURRENTLY NO USAGES of INVALID_REQUEST
            switch(result.getAuthorizationResult().getAuthorizationStatus()) {
                case FAIL:
                    // Check if the error is to register device and throw DEVICE_REGISTRATION_NEEDED exception
                    if (authorizationErrorResponse instanceof MicrosoftAuthorizationErrorResponse) {
                        MicrosoftAuthorizationErrorResponse microsoftAuthorizationErrorResponse = (MicrosoftAuthorizationErrorResponse) authorizationErrorResponse;
                        if (microsoftAuthorizationErrorResponse.getError().equals(MicrosoftAuthorizationErrorResponse.DEVICE_REGISTRATION_NEEDED)) {
                            return new DeviceRegistrationRequiredException(microsoftAuthorizationErrorResponse.getError(), microsoftAuthorizationErrorResponse.getErrorDescription(), microsoftAuthorizationErrorResponse.getUserName());
                        }
                    }
                    return new ServiceException(authorizationErrorResponse.getError(), authorizationErrorResponse.getErrorDescription(), ServiceException.DEFAULT_STATUS_CODE, null);
                case SDK_CANCEL:
                    return new ClientException(authorizationErrorResponse.getError(), authorizationErrorResponse.getErrorDescription());
                case USER_CANCEL:
                    return new UserCancelException();
            }
        }
    } else {
        Logger.warn(TAG + methodName, "AuthorizationResult was null -- expected for ATS cases.");
    }
    return exceptionFromTokenResult(result.getTokenResult(), commandParameters);
}
Also used : MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) AuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse) MicrosoftAuthorizationErrorResponse(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse) ServiceException(com.microsoft.identity.common.exception.ServiceException) DeviceRegistrationRequiredException(com.microsoft.identity.common.exception.DeviceRegistrationRequiredException) UserCancelException(com.microsoft.identity.common.exception.UserCancelException) ClientException(com.microsoft.identity.common.exception.ClientException) AuthorizationResult(com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult) Nullable(androidx.annotation.Nullable)

Aggregations

Nullable (androidx.annotation.Nullable)1 ClientException (com.microsoft.identity.common.exception.ClientException)1 DeviceRegistrationRequiredException (com.microsoft.identity.common.exception.DeviceRegistrationRequiredException)1 ServiceException (com.microsoft.identity.common.exception.ServiceException)1 UserCancelException (com.microsoft.identity.common.exception.UserCancelException)1 MicrosoftAuthorizationErrorResponse (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftAuthorizationErrorResponse)1 AuthorizationErrorResponse (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationErrorResponse)1 AuthorizationResult (com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult)1