Search in sources :

Example 6 with BrokerRequest

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

the class MsalBrokerRequestAdapter method brokerInteractiveParametersFromActivity.

@Override
public BrokerInteractiveTokenCommandParameters brokerInteractiveParametersFromActivity(@NonNull final Activity callingActivity) {
    Logger.info(TAG, "Constructing BrokerAcquireTokenOperationParameters from calling activity");
    final Intent intent = callingActivity.getIntent();
    final BrokerRequest brokerRequest = brokerRequestFromBundle(intent.getExtras());
    if (brokerRequest == null) {
        Logger.error(TAG, "Broker Result is null, returning empty parameters, " + "validation is expected to fail", null);
        return BrokerInteractiveTokenCommandParameters.builder().build();
    }
    int callingAppUid = intent.getIntExtra(CALLER_INFO_UID, 0);
    List<Pair<String, String>> extraQP = QueryParamsAdapter._fromJson(brokerRequest.getExtraQueryStringParameter());
    List<Pair<String, String>> extraOptions = QueryParamsAdapter._fromJson(brokerRequest.getExtraOptions());
    ;
    final AzureActiveDirectoryAuthority authority = AdalBrokerRequestAdapter.getRequestAuthorityWithExtraQP(brokerRequest.getAuthority(), extraQP);
    if (authority != null) {
        authority.setMultipleCloudsSupported(brokerRequest.isMultipleCloudsSupported());
    }
    String correlationIdString = brokerRequest.getCorrelationId();
    if (TextUtils.isEmpty(correlationIdString)) {
        UUID correlationId = UUID.randomUUID();
        correlationIdString = correlationId.toString();
    }
    final String negotiatedBrokerProtocolVersion = intent.getStringExtra(NEGOTIATED_BP_VERSION_KEY);
    Logger.info(TAG, "Authorization agent passed in by MSAL: " + brokerRequest.getAuthorizationAgent());
    @SuppressWarnings("rawtypes") final BrokerInteractiveTokenCommandParameters.BrokerInteractiveTokenCommandParametersBuilder commandParametersBuilder = BrokerInteractiveTokenCommandParameters.builder().authenticationScheme(getAuthenticationScheme(callingActivity, brokerRequest)).activity(callingActivity).androidApplicationContext(callingActivity.getApplicationContext()).sdkType(brokerRequest.getSdkType() == null ? SdkType.MSAL : brokerRequest.getSdkType()).sdkVersion(brokerRequest.getMsalVersion()).callerUid(callingAppUid).applicationName(brokerRequest.getApplicationName()).applicationVersion(brokerRequest.getApplicationVersion()).callerPackageName(brokerRequest.getApplicationName()).callerAppVersion(brokerRequest.getApplicationVersion()).extraQueryStringParameters(extraQP).authority(authority).extraOptions(extraOptions).scopes(getScopesAsSet(brokerRequest.getScope())).clientId(brokerRequest.getClientId()).redirectUri(brokerRequest.getRedirect()).loginHint(brokerRequest.getUserName()).correlationId(correlationIdString).claimsRequestJson(brokerRequest.getClaims()).prompt(brokerRequest.getPrompt() != null ? OpenIdConnectPromptParameter.valueOf(brokerRequest.getPrompt()) : OpenIdConnectPromptParameter.UNSET).negotiatedBrokerProtocolVersion(negotiatedBrokerProtocolVersion).powerOptCheckEnabled(brokerRequest.isPowerOptCheckEnabled());
    if (AuthorizationAgent.BROWSER.name().equalsIgnoreCase(brokerRequest.getAuthorizationAgent()) && isCallingPackageIntune(brokerRequest.getApplicationName())) {
        // TODO : Remove this whenever we enable System Browser support in Broker for apps.
        Logger.info(TAG, "Setting Authorization Agent to Browser for Intune app");
        buildCommandParameterBuilder(commandParametersBuilder);
    } else {
        commandParametersBuilder.authorizationAgent(AuthorizationAgent.WEBVIEW);
    }
    // Set Global environment variable for instance discovery if present
    if (!TextUtils.isEmpty(brokerRequest.getEnvironment())) {
        AzureActiveDirectory.setEnvironment(Environment.valueOf(brokerRequest.getEnvironment()));
    }
    return commandParametersBuilder.build();
}
Also used : AzureActiveDirectoryAuthority(com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority) Intent(android.content.Intent) BrokerRequest(com.microsoft.identity.common.internal.broker.BrokerRequest) GzipUtil.compressString(com.microsoft.identity.common.internal.util.GzipUtil.compressString) GzipUtil.decompressBytesToString(com.microsoft.identity.common.internal.util.GzipUtil.decompressBytesToString) UUID(java.util.UUID) BrokerInteractiveTokenCommandParameters(com.microsoft.identity.common.internal.commands.parameters.BrokerInteractiveTokenCommandParameters) Pair(android.util.Pair)

Example 7 with BrokerRequest

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

the class MsalBrokerRequestAdapter method brokerRequestFromAcquireTokenParameters.

@Override
public BrokerRequest brokerRequestFromAcquireTokenParameters(@NonNull final InteractiveTokenCommandParameters parameters) {
    Logger.info(TAG, "Constructing result bundle from AcquireTokenOperationParameters.");
    final String extraQueryStringParameter = parameters.getExtraQueryStringParameters() != null ? QueryParamsAdapter._toJson(parameters.getExtraQueryStringParameters()) : null;
    final String extraOptions = parameters.getExtraOptions() != null ? QueryParamsAdapter._toJson(parameters.getExtraOptions()) : null;
    final BrokerRequest brokerRequest = BrokerRequest.builder().authority(parameters.getAuthority().getAuthorityURL().toString()).scope(TextUtils.join(" ", parameters.getScopes())).redirect(getRedirectUri(parameters)).clientId(parameters.getClientId()).userName(parameters.getLoginHint()).extraQueryStringParameter(extraQueryStringParameter).extraOptions(extraOptions).prompt((OpenIdConnectPromptParameter.UNSET.name().equals(parameters.getPrompt().name())) ? null : parameters.getPrompt().name()).claims(parameters.getClaimsRequestJson()).forceRefresh(parameters.isForceRefresh()).correlationId(parameters.getCorrelationId()).applicationName(parameters.getApplicationName()).applicationVersion(parameters.getApplicationVersion()).msalVersion(parameters.getSdkVersion()).sdkType(parameters.getSdkType()).environment(AzureActiveDirectory.getEnvironment().name()).multipleCloudsSupported(getMultipleCloudsSupported(parameters)).authorizationAgent(parameters.isBrokerBrowserSupportEnabled() ? AuthorizationAgent.BROWSER.name() : AuthorizationAgent.WEBVIEW.name()).authenticationScheme(parameters.getAuthenticationScheme()).powerOptCheckEnabled(parameters.isPowerOptCheckEnabled()).build();
    return brokerRequest;
}
Also used : BrokerRequest(com.microsoft.identity.common.internal.broker.BrokerRequest) GzipUtil.compressString(com.microsoft.identity.common.internal.util.GzipUtil.compressString) GzipUtil.decompressBytesToString(com.microsoft.identity.common.internal.util.GzipUtil.decompressBytesToString)

Aggregations

BrokerRequest (com.microsoft.identity.common.internal.broker.BrokerRequest)7 GzipUtil.compressString (com.microsoft.identity.common.internal.util.GzipUtil.compressString)6 GzipUtil.decompressBytesToString (com.microsoft.identity.common.internal.util.GzipUtil.decompressBytesToString)6 Bundle (android.os.Bundle)2 Pair (android.util.Pair)2 AzureActiveDirectoryAuthority (com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 Intent (android.content.Intent)1 Nullable (androidx.annotation.Nullable)1 Authority (com.microsoft.identity.common.internal.authorities.Authority)1 BrokerInteractiveTokenCommandParameters (com.microsoft.identity.common.internal.commands.parameters.BrokerInteractiveTokenCommandParameters)1 BrokerSilentTokenCommandParameters (com.microsoft.identity.common.internal.commands.parameters.BrokerSilentTokenCommandParameters)1