Search in sources :

Example 1 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 brokerSilentParametersFromBundle.

@Override
public BrokerSilentTokenCommandParameters brokerSilentParametersFromBundle(@NonNull final Bundle bundle, @NonNull final Context context, @NonNull final Account account) {
    Logger.info(TAG, "Constructing BrokerAcquireTokenSilentOperationParameters from result bundle");
    final BrokerRequest brokerRequest = brokerRequestFromBundle(bundle);
    if (brokerRequest == null) {
        Logger.error(TAG, "Broker Result is null, returning empty parameters, " + "validation is expected to fail", null);
        return BrokerSilentTokenCommandParameters.builder().build();
    }
    int callingAppUid = bundle.getInt(CALLER_INFO_UID);
    final Authority authority = Authority.getAuthorityFromAuthorityUrl(brokerRequest.getAuthority());
    if (authority instanceof AzureActiveDirectoryAuthority) {
        ((AzureActiveDirectoryAuthority) authority).setMultipleCloudsSupported(brokerRequest.isMultipleCloudsSupported());
    }
    String correlationIdString = brokerRequest.getCorrelationId();
    if (TextUtils.isEmpty(correlationIdString)) {
        UUID correlationId = UUID.randomUUID();
        correlationIdString = correlationId.toString();
    }
    final String negotiatedBrokerProtocolVersion = bundle.getString(NEGOTIATED_BP_VERSION_KEY);
    List<Pair<String, String>> extraOptions = QueryParamsAdapter._fromJson(brokerRequest.getExtraOptions());
    final BrokerSilentTokenCommandParameters commandParameters = BrokerSilentTokenCommandParameters.builder().authenticationScheme(getAuthenticationScheme(context, brokerRequest)).androidApplicationContext(context).accountManagerAccount(account).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()).authority(authority).correlationId(correlationIdString).scopes(getScopesAsSet(brokerRequest.getScope())).redirectUri(brokerRequest.getRedirect()).extraOptions(extraOptions).clientId(brokerRequest.getClientId()).forceRefresh(brokerRequest.isForceRefresh()).claimsRequestJson(brokerRequest.getClaims()).loginHint(brokerRequest.getUserName()).homeAccountId(brokerRequest.getHomeAccountId()).localAccountId(brokerRequest.getLocalAccountId()).negotiatedBrokerProtocolVersion(negotiatedBrokerProtocolVersion).powerOptCheckEnabled(brokerRequest.isPowerOptCheckEnabled()).build();
    // Set Global environment variable for instance discovery if present
    if (!TextUtils.isEmpty(brokerRequest.getEnvironment())) {
        AzureActiveDirectory.setEnvironment(Environment.valueOf(brokerRequest.getEnvironment()));
    }
    return commandParameters;
}
Also used : BrokerSilentTokenCommandParameters(com.microsoft.identity.common.internal.commands.parameters.BrokerSilentTokenCommandParameters) AzureActiveDirectoryAuthority(com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority) Authority(com.microsoft.identity.common.internal.authorities.Authority) AzureActiveDirectoryAuthority(com.microsoft.identity.common.internal.authorities.AzureActiveDirectoryAuthority) 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) Pair(android.util.Pair)

Example 2 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 brokerRequestFromSilentOperationParameters.

@Override
public BrokerRequest brokerRequestFromSilentOperationParameters(@NonNull final SilentTokenCommandParameters parameters) {
    Logger.info(TAG, "Constructing result bundle from AcquireTokenSilentOperationParameters.");
    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)).extraOptions(extraOptions).clientId(parameters.getClientId()).homeAccountId(parameters.getAccount().getHomeAccountId()).localAccountId(parameters.getAccount().getLocalAccountId()).userName(parameters.getAccount().getUsername()).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)).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)

Example 3 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 getRequestBundleForAcquireTokenSilent.

/**
 * Method to construct a request bundle for broker acquireTokenSilent request.
 *
 * @param parameters                      input parameters
 * @param negotiatedBrokerProtocolVersion protocol version returned by broker hello.
 * @return request Bundle
 */
public Bundle getRequestBundleForAcquireTokenSilent(@NonNull final SilentTokenCommandParameters parameters, @Nullable final String negotiatedBrokerProtocolVersion) {
    final MsalBrokerRequestAdapter msalBrokerRequestAdapter = new MsalBrokerRequestAdapter();
    final BrokerRequest brokerRequest = msalBrokerRequestAdapter.brokerRequestFromSilentOperationParameters(parameters);
    final Bundle requestBundle = getRequestBundleFromBrokerRequest(brokerRequest, negotiatedBrokerProtocolVersion);
    requestBundle.putInt(CALLER_INFO_UID, parameters.getAndroidApplicationContext().getApplicationInfo().uid);
    return requestBundle;
}
Also used : Bundle(android.os.Bundle) BrokerRequest(com.microsoft.identity.common.internal.broker.BrokerRequest)

Example 4 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 getRequestBundleFromBrokerRequest.

private Bundle getRequestBundleFromBrokerRequest(@NonNull BrokerRequest brokerRequest, @Nullable String negotiatedBrokerProtocolVersion) {
    final Bundle requestBundle = new Bundle();
    if (BrokerProtocolVersionUtil.canCompressBrokerPayloads(negotiatedBrokerProtocolVersion)) {
        try {
            final String jsonString = sRequestAdapterGsonInstance.toJson(brokerRequest, BrokerRequest.class);
            byte[] compressedBytes = compressString(jsonString);
            Logger.info(TAG, "Broker Result, raw payload size:" + jsonString.getBytes().length + " ,compressed bytes size: " + compressedBytes.length);
            requestBundle.putByteArray(BROKER_REQUEST_V2_COMPRESSED, compressedBytes);
        } catch (IOException e) {
            Logger.error(TAG, "Compression to bytes failed, sending broker request as json String", e);
            requestBundle.putString(BROKER_REQUEST_V2, sRequestAdapterGsonInstance.toJson(brokerRequest, BrokerRequest.class));
        }
    } else {
        Logger.info(TAG, "Broker protocol version: " + negotiatedBrokerProtocolVersion + " lower than compression changes, sending as string");
        requestBundle.putString(BROKER_REQUEST_V2, sRequestAdapterGsonInstance.toJson(brokerRequest, BrokerRequest.class));
    }
    requestBundle.putString(NEGOTIATED_BP_VERSION_KEY, negotiatedBrokerProtocolVersion);
    return requestBundle;
}
Also used : Bundle(android.os.Bundle) 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) IOException(java.io.IOException)

Example 5 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 brokerRequestFromBundle.

@Nullable
public BrokerRequest brokerRequestFromBundle(@NonNull final Bundle requestBundle) {
    BrokerRequest brokerRequest = null;
    if (requestBundle.containsKey(BROKER_REQUEST_V2_COMPRESSED)) {
        try {
            final String deCompressedString = decompressBytesToString(requestBundle.getByteArray(BROKER_REQUEST_V2_COMPRESSED));
            brokerRequest = sRequestAdapterGsonInstance.fromJson(deCompressedString, BrokerRequest.class);
        } catch (final IOException e) {
            // We would ideally never run into this case as compression would always work as expected.
            // The caller should handle the null value of broker request.
            Logger.error(TAG, "Decompression of Broker Request failed," + " unable to continue with Broker Request", e);
        }
    } else {
        brokerRequest = sRequestAdapterGsonInstance.fromJson(requestBundle.getString(BROKER_REQUEST_V2), BrokerRequest.class);
    }
    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) IOException(java.io.IOException) Nullable(androidx.annotation.Nullable)

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