Search in sources :

Example 1 with IHasExtraParameters

use of com.microsoft.identity.common.internal.commands.parameters.IHasExtraParameters in project microsoft-authentication-library-common-for-android by AzureAD.

the class BaseController method performTokenRequest.

protected TokenResult performTokenRequest(@SuppressWarnings(WarningType.rawtype_warning) @NonNull final OAuth2Strategy strategy, @SuppressWarnings(WarningType.rawtype_warning) @NonNull final AuthorizationRequest request, @NonNull final AuthorizationResponse response, @NonNull final InteractiveTokenCommandParameters parameters) throws IOException, ClientException {
    final String methodName = ":performTokenRequest";
    HttpWebRequest.throwIfNetworkNotAvailable(parameters.getAndroidApplicationContext(), parameters.isPowerOptCheckEnabled());
    // Suppressing unchecked warnings due to casting of type AuthorizationRequest to GenericAuthorizationRequest and AuthorizationResponse to GenericAuthorizationResponse in arguments of method call to createTokenRequest
    @SuppressWarnings(WarningType.unchecked_warning) final TokenRequest tokenRequest = strategy.createTokenRequest(request, response, parameters.getAuthenticationScheme());
    if (tokenRequest instanceof MicrosoftTokenRequest) {
        ((MicrosoftTokenRequest) tokenRequest).setClientAppName(parameters.getApplicationName());
        ((MicrosoftTokenRequest) tokenRequest).setClientAppVersion(parameters.getApplicationVersion());
    }
    if (tokenRequest instanceof IHasExtraParameters && parameters instanceof IHasExtraParameters) {
        ((IHasExtraParameters) tokenRequest).setExtraParameters(((IHasExtraParameters) parameters).getExtraParameters());
    }
    logExposedFieldsOfObject(TAG + methodName, tokenRequest);
    // Suppressing unchecked warnings due to casting of type TokenRequest to GenericTokenRequest in argument of method call to requestToken
    @SuppressWarnings(WarningType.unchecked_warning) final TokenResult tokenResult = strategy.requestToken(tokenRequest);
    logResult(TAG, tokenResult);
    return tokenResult;
}
Also used : TokenResult(com.microsoft.identity.common.internal.providers.oauth2.TokenResult) AcquireTokenResult(com.microsoft.identity.common.internal.result.AcquireTokenResult) MicrosoftTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest) TokenRequest(com.microsoft.identity.common.internal.providers.oauth2.TokenRequest) MicrosoftTokenRequest(com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest) IHasExtraParameters(com.microsoft.identity.common.internal.commands.parameters.IHasExtraParameters)

Example 2 with IHasExtraParameters

use of com.microsoft.identity.common.internal.commands.parameters.IHasExtraParameters in project microsoft-authentication-library-common-for-android by AzureAD.

the class ObjectMapper method constuctMapFromObject.

/**
 * Method for converting the contents of an object into a map.  Important to the implementation of
 * this method is the behavior of GSON which excludes null fields from the resulting JSON.  A
 * TreeMap was chosen to simplify testing, and the resulting map is in key order.
 *
 * @param object the object to convert.
 * @return a map representation of the object.
 */
public static Map<String, String> constuctMapFromObject(Object object) {
    String json = ObjectMapper.serializeObjectToJsonString(object);
    Type stringMap = new TypeToken<TreeMap<String, String>>() {
    }.getType();
    TreeMap<String, String> fields = new Gson().fromJson(json, stringMap);
    if (object instanceof IHasExtraParameters) {
        final IHasExtraParameters params = (IHasExtraParameters) object;
        if (params.getExtraParameters() != null) {
            for (final Map.Entry<String, String> e : params.getExtraParameters()) {
                if (e.getKey() != null) {
                    fields.put(e.getKey(), e.getValue());
                }
            }
        }
    }
    return fields;
}
Also used : WarningType(com.microsoft.identity.common.WarningType) Type(java.lang.reflect.Type) Gson(com.google.gson.Gson) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) IHasExtraParameters(com.microsoft.identity.common.internal.commands.parameters.IHasExtraParameters)

Aggregations

IHasExtraParameters (com.microsoft.identity.common.internal.commands.parameters.IHasExtraParameters)2 Gson (com.google.gson.Gson)1 WarningType (com.microsoft.identity.common.WarningType)1 MicrosoftTokenRequest (com.microsoft.identity.common.internal.providers.microsoft.MicrosoftTokenRequest)1 TokenRequest (com.microsoft.identity.common.internal.providers.oauth2.TokenRequest)1 TokenResult (com.microsoft.identity.common.internal.providers.oauth2.TokenResult)1 AcquireTokenResult (com.microsoft.identity.common.internal.result.AcquireTokenResult)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1