use of com.microsoft.identity.common.exception.DeviceRegistrationRequiredException 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);
}
Aggregations