use of com.microsoft.identity.common.internal.broker.BrokerResultFuture in project microsoft-authentication-library-common-for-android by AzureAD.
the class BrokerMsalController method acquireToken.
/**
* Performs interactive acquire token with Broker.
*
* @param parameters a {@link InteractiveTokenCommandParameters}
* @return an {@link AcquireTokenResult}.
*/
@Override
public AcquireTokenResult acquireToken(@NonNull final InteractiveTokenCommandParameters parameters) throws BaseException, InterruptedException {
Telemetry.emit(new ApiStartEvent().putProperties(parameters).putApiId(TelemetryEventStrings.Api.BROKER_ACQUIRE_TOKEN_INTERACTIVE));
// Create BrokerResultFuture to block on response from the broker... response will be return as an activity result
// BrokerActivity will receive the result and ask the API dispatcher to complete the request
// In completeAcquireToken below we will set the result on the future and unblock the flow.
mBrokerResultFuture = new BrokerResultFuture();
// Get the broker interactive parameters intent
final Intent interactiveRequestIntent = getBrokerAuthorizationIntent(parameters);
// Pass this intent to the BrokerActivity which will be used to start this activity
final Intent brokerActivityIntent = new Intent(parameters.getAndroidApplicationContext(), BrokerActivity.class);
brokerActivityIntent.putExtra(BrokerActivity.BROKER_INTENT, interactiveRequestIntent);
if (null == parameters.getActivity()) {
// To support calling from OneAuth-MSAL, which may be initialized without an Activity
// add Flags to start as a NEW_TASK if we are launching from an application Context
brokerActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mApplicationContext.startActivity(brokerActivityIntent);
} else {
// Start the BrokerActivity using our existing Activity
parameters.getActivity().startActivity(brokerActivityIntent);
}
// Wait to be notified of the result being returned... we could add a timeout here if we want to
final Bundle resultBundle = mBrokerResultFuture.get();
// If the request is from MSALCPP , OAuth2TokenCache will be null.
if (parameters.getOAuth2TokenCache() != null) {
saveMsaAccountToCache(resultBundle, (MsalOAuth2TokenCache) parameters.getOAuth2TokenCache());
}
final AcquireTokenResult result;
try {
result = new MsalBrokerResultAdapter().getAcquireTokenResultFromResultBundle(resultBundle);
} catch (BaseException e) {
Telemetry.emit(new ApiEndEvent().putException(e).putApiId(TelemetryEventStrings.Api.BROKER_ACQUIRE_TOKEN_INTERACTIVE));
throw e;
}
Telemetry.emit(new ApiEndEvent().putResult(result).putApiId(TelemetryEventStrings.Api.BROKER_ACQUIRE_TOKEN_INTERACTIVE));
return result;
}
Aggregations