use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class LocalMSALController method deviceCodeFlowAuthRequest.
// Suppressing rawtype warnings due to the generic types AuthorizationResult and OAuth2Strategy
@SuppressWarnings(WarningType.rawtype_warning)
@Override
public AuthorizationResult deviceCodeFlowAuthRequest(final DeviceCodeFlowCommandParameters parameters) throws ServiceException, ClientException, IOException {
// Logging start of method
final String methodName = ":deviceCodeFlowAuthRequest";
Logger.verbose(TAG + methodName, "Device Code Flow: Authorizing user code...");
// Default scopes here
final Set<String> mergedScopes = addDefaultScopes(parameters);
final DeviceCodeFlowCommandParameters parametersWithScopes = parameters.toBuilder().scopes(mergedScopes).build();
logParameters(TAG, parametersWithScopes);
// Start telemetry with LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE
Telemetry.emit(new ApiStartEvent().putProperties(parametersWithScopes).putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
final Authority.KnownAuthorityResult authorityResult = Authority.getKnownAuthorityResult(parametersWithScopes.getAuthority());
// If not known throw resulting exception
if (!authorityResult.getKnown()) {
Telemetry.emit(new ApiEndEvent().putException(authorityResult.getClientException()).putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
throw authorityResult.getClientException();
}
final AuthorizationResult authorizationResult;
try {
// Create OAuth2Strategy using commandParameters and strategyParameters
final OAuth2StrategyParameters strategyParameters = new OAuth2StrategyParameters();
strategyParameters.setContext(parametersWithScopes.getAndroidApplicationContext());
final OAuth2Strategy oAuth2Strategy = parametersWithScopes.getAuthority().createOAuth2Strategy(strategyParameters);
// DCF protocol step 1: Get user code
// Populate global authorization request
mAuthorizationRequest = getAuthorizationRequest(oAuth2Strategy, parametersWithScopes);
// Call method defined in oAuth2Strategy to request authorization
authorizationResult = oAuth2Strategy.getDeviceCode((MicrosoftStsAuthorizationRequest) mAuthorizationRequest);
validateServiceResult(authorizationResult);
} catch (Exception error) {
Telemetry.emit(new ApiEndEvent().putException(error).putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
throw error;
}
Logger.verbose(TAG + methodName, "Device Code Flow authorization step finished...");
logResult(TAG, authorizationResult);
// End telemetry with LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE
Telemetry.emit(new ApiEndEvent().putApiId(TelemetryEventStrings.Api.LOCAL_DEVICE_CODE_FLOW_ACQUIRE_URL_AND_CODE));
return authorizationResult;
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class DeviceCodeFlowCommand method execute.
@Override
public AcquireTokenResult execute() throws Exception {
final String methodName = ":execute";
Logger.verbose(TAG + methodName, "Device Code Flow command initiating...");
// Get the controller used to execute the command
final BaseController controller = getDefaultController();
// Fetch the parameters
final DeviceCodeFlowCommandParameters commandParameters = (DeviceCodeFlowCommandParameters) getParameters();
// Call deviceCodeFlowAuthRequest to get authorization result (Part 1 of DCF)
@SuppressWarnings(WarningType.rawtype_warning) final AuthorizationResult authorizationResult = controller.deviceCodeFlowAuthRequest(commandParameters);
// Fetch the authorization response
final MicrosoftStsAuthorizationResponse authorizationResponse = (MicrosoftStsAuthorizationResponse) authorizationResult.getAuthorizationResponse();
final Date expiredDate = new Date();
try {
long expiredInInMilliseconds = TimeUnit.SECONDS.toMillis(Long.parseLong(authorizationResponse.getExpiresIn()));
expiredDate.setTime(expiredDate.getTime() + expiredInInMilliseconds);
} catch (final NumberFormatException e) {
// Shouldn't happen, but if it does, we don't want to fail the request because of this.
Logger.error(TAG + methodName, "Failed to parse authorizationResponse.getExpiresIn()", e);
}
// Communicate with user app and provide authentication information
@SuppressWarnings(WarningType.rawtype_warning) final DeviceCodeFlowCommandCallback deviceCodeFlowCommandCallback = (DeviceCodeFlowCommandCallback) getCallback();
deviceCodeFlowCommandCallback.onUserCodeReceived(authorizationResponse.getVerificationUri(), authorizationResponse.getUserCode(), authorizationResponse.getMessage(), expiredDate);
// Call acquireDeviceCodeFlowToken to get token result (Part 2 of DCF)
final AcquireTokenResult tokenResult = controller.acquireDeviceCodeFlowToken(authorizationResult, commandParameters);
Logger.verbose(TAG + methodName, "Device Code Flow command exiting with token...");
return tokenResult;
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrowserAuthorizationStrategy method completeAuthorization.
@Override
public void completeAuthorization(int requestCode, int resultCode, Intent data) {
if (requestCode == AuthenticationConstants.UIRequest.BROWSER_FLOW) {
dispose();
// 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.warnPII(TAG, "Unknown request code " + requestCode);
}
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class CurrentTaskBrowserAuthorizationStrategy method completeAuthorization.
@Override
public void completeAuthorization(int requestCode, int resultCode, Intent data) {
if (requestCode == AuthenticationConstants.UIRequest.BROWSER_FLOW) {
// 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);
dispose();
} else {
Logger.warnPII(TAG, "Unknown request code " + requestCode);
}
}
use of com.microsoft.identity.common.internal.providers.oauth2.AuthorizationResult in project microsoft-authentication-library-common-for-android by AzureAD.
the class MockTestStrategy method requestAuthorization.
/**
* Template method for executing an OAuth2 authorization request.
*
* @param request microsoft sts authorization request.
* @param authorizationStrategy authorization strategy.
* @return GenericAuthorizationResponse
*/
@Override
public Future<AuthorizationResult> requestAuthorization(final MicrosoftStsAuthorizationRequest request, final AuthorizationStrategy authorizationStrategy) {
final MockSuccessAuthorizationResultMockedTests authorizationResult = new MockSuccessAuthorizationResultMockedTests();
final ResultFuture<AuthorizationResult> future = new ResultFuture<>();
future.setResult(authorizationResult);
return future;
}
Aggregations