use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class AzureActiveDirectoryAuthorizationResultFactoryTest method testBrowserCodeAuthenticationException.
@Test
public void testBrowserCodeAuthenticationException() {
Intent intent = new Intent();
Bundle bundle = new Bundle();
String mockError = "mockError";
String mockErrorDescription = "mockErrorDescription";
ClientException exception = new ClientException(mockError, mockErrorDescription);
bundle.putSerializable(AuthenticationConstants.Browser.RESPONSE_AUTHENTICATION_EXCEPTION, exception);
intent.putExtras(bundle);
AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_AUTHENTICATION_EXCEPTION, intent, getAADRequest());
assertNotNull(result);
assertNull(result.getAuthorizationResponse());
assertEquals(AuthorizationStatus.FAIL, result.getAuthorizationStatus());
AuthorizationErrorResponse errorResponse = result.getAuthorizationErrorResponse();
assertNotNull(errorResponse);
assertEquals(mockError, errorResponse.getError());
assertEquals(mockErrorDescription, errorResponse.getErrorDescription());
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class MicrosoftStsAuthorizationResultFactoryTest method testNullIntent.
@Test
public void testNullIntent() {
AuthorizationResult result = mAuthorizationResultFactory.createAuthorizationResult(AuthenticationConstants.UIResponse.BROWSER_CODE_COMPLETE, null, 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.NULL_INTENT, errorResponse.getErrorDescription());
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class BaseController method logResult.
/**
* Log IResult objects. IResult objects are returned from Authorization and Token Requests
*
* @param tag The log tag to use.
* @param result The result object to log.
*/
public static void logResult(@NonNull final String tag, @NonNull final IResult result) {
final String TAG = tag + ":" + result.getClass().getSimpleName();
if (result.getSuccess()) {
Logger.info(TAG, "Success Result");
logExposedFieldsOfObject(TAG, result.getSuccessResponse());
} else {
Logger.warn(TAG, "Failure Result");
if (result.getErrorResponse() != null) {
if (result.getErrorResponse().getError() != null) {
Logger.warn(TAG, "Error: " + result.getErrorResponse().getError());
}
if (result.getErrorResponse().getErrorDescription() != null) {
Logger.warnPII(TAG, "Description: " + result.getErrorResponse().getErrorDescription());
}
logExposedFieldsOfObject(TAG, result.getErrorResponse());
}
}
if (result instanceof AuthorizationResult) {
@SuppressWarnings(WarningType.rawtype_warning) AuthorizationResult authResult = (AuthorizationResult) result;
if (authResult.getAuthorizationStatus() != null) {
Logger.info(TAG, "Authorization Status: " + authResult.getAuthorizationStatus().toString());
}
}
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class LocalMSALController method acquireToken.
@Override
public AcquireTokenResult acquireToken(@NonNull final InteractiveTokenCommandParameters parameters) throws ExecutionException, InterruptedException, ClientException, IOException, ArgumentException {
final String methodName = ":acquireToken";
Logger.verbose(TAG + methodName, "Acquiring token...");
Telemetry.emit(new ApiStartEvent().putProperties(parameters).putApiId(TelemetryEventStrings.Api.LOCAL_ACQUIRE_TOKEN_INTERACTIVE));
final AcquireTokenResult acquireTokenResult = new AcquireTokenResult();
// 00) Validate MSAL Parameters
parameters.validate();
// Add default scopes
final Set<String> mergedScopes = addDefaultScopes(parameters);
final InteractiveTokenCommandParameters parametersWithScopes = parameters.toBuilder().scopes(mergedScopes).build();
logParameters(TAG, parametersWithScopes);
// 0) Get known authority result
throwIfNetworkNotAvailable(parametersWithScopes.getAndroidApplicationContext(), parametersWithScopes.isPowerOptCheckEnabled());
Authority.KnownAuthorityResult authorityResult = Authority.getKnownAuthorityResult(parametersWithScopes.getAuthority());
// 0.1 If not known throw resulting exception
if (!authorityResult.getKnown()) {
Telemetry.emit(new ApiEndEvent().putException(authorityResult.getClientException()).putApiId(TelemetryEventStrings.Api.LOCAL_ACQUIRE_TOKEN_INTERACTIVE));
throw authorityResult.getClientException();
}
// Build up params for Strategy construction
final OAuth2StrategyParameters strategyParameters = new OAuth2StrategyParameters();
strategyParameters.setContext(parametersWithScopes.getAndroidApplicationContext());
// 1) Get oAuth2Strategy for Authority Type
@SuppressWarnings(WarningType.rawtype_warning) final OAuth2Strategy oAuth2Strategy = parametersWithScopes.getAuthority().createOAuth2Strategy(strategyParameters);
// 2) Request authorization interactively
@SuppressWarnings(WarningType.rawtype_warning) final AuthorizationResult result = performAuthorizationRequest(oAuth2Strategy, parametersWithScopes.getAndroidApplicationContext(), parametersWithScopes);
acquireTokenResult.setAuthorizationResult(result);
logResult(TAG, result);
if (result.getAuthorizationStatus().equals(AuthorizationStatus.SUCCESS)) {
// 3) Exchange authorization code for token
final TokenResult tokenResult = performTokenRequest(oAuth2Strategy, mAuthorizationRequest, result.getAuthorizationResponse(), parametersWithScopes);
acquireTokenResult.setTokenResult(tokenResult);
if (tokenResult != null && tokenResult.getSuccess()) {
// 4) Save tokens in token cache
final List<ICacheRecord> records = saveTokens(oAuth2Strategy, mAuthorizationRequest, tokenResult.getTokenResponse(), parametersWithScopes.getOAuth2TokenCache());
// The first element in the returned list is the item we *just* saved, the rest of
// the elements are necessary to construct the full IAccount + TenantProfile
final ICacheRecord newestRecord = records.get(0);
acquireTokenResult.setLocalAuthenticationResult(new LocalAuthenticationResult(finalizeCacheRecordForResult(newestRecord, parametersWithScopes.getAuthenticationScheme()), records, SdkType.MSAL, false));
}
}
Telemetry.emit(new ApiEndEvent().putResult(acquireTokenResult).putApiId(TelemetryEventStrings.Api.LOCAL_ACQUIRE_TOKEN_INTERACTIVE));
return acquireTokenResult;
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult 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;
}
Aggregations