Search in sources :

Example 1 with IClockSkewManager

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

the class MsalBrokerRequestAdapter method getAuthenticationScheme.

@NonNull
private static AbstractAuthenticationScheme getAuthenticationScheme(@NonNull final Context context, @NonNull final BrokerRequest request) {
    final AbstractAuthenticationScheme requestScheme = request.getAuthenticationScheme();
    if (null == requestScheme) {
        // Default assumes the scheme is Bearer
        return new BearerAuthenticationSchemeInternal();
    } else {
        if (requestScheme instanceof PopAuthenticationSchemeInternal) {
            final IClockSkewManager clockSkewManager = new ClockSkewManager(context);
            ((PopAuthenticationSchemeInternal) requestScheme).setClockSkewManager(clockSkewManager);
        }
        return requestScheme;
    }
}
Also used : AbstractAuthenticationScheme(com.microsoft.identity.common.internal.authscheme.AbstractAuthenticationScheme) BearerAuthenticationSchemeInternal(com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) PopAuthenticationSchemeInternal(com.microsoft.identity.common.internal.authscheme.PopAuthenticationSchemeInternal) NonNull(androidx.annotation.NonNull)

Example 2 with IClockSkewManager

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

the class LocalMSALController method generateSignedHttpRequest.

@Override
public GenerateShrResult generateSignedHttpRequest(@NonNull final GenerateShrCommandParameters parameters) throws Exception {
    final Context context = parameters.getAndroidApplicationContext();
    final IClockSkewManager clockSkewManager = new ClockSkewManager(context);
    final OAuth2TokenCache cache = parameters.getOAuth2TokenCache();
    final String clientId = parameters.getClientId();
    final String homeAccountId = parameters.getHomeAccountId();
    final IPoPAuthenticationSchemeParams popSchemeParams = parameters.getPopParameters();
    final GenerateShrResult result;
    if (userHasLocalAccountRecord(cache, clientId, homeAccountId)) {
        // Perform the signing locally...
        result = DevicePoPUtils.generateSignedHttpRequest(context, clockSkewManager, popSchemeParams);
    } else {
        // Populate the error on the result and return...
        result = new GenerateShrResult();
        result.setErrorCode(GenerateShrResult.Errors.NO_ACCOUNT_FOUND);
        result.setErrorMessage("Account does not exist.");
    }
    return result;
}
Also used : Context(android.content.Context) OAuth2TokenCache(com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache) GenerateShrResult(com.microsoft.identity.common.internal.result.GenerateShrResult) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) IPoPAuthenticationSchemeParams(com.microsoft.identity.common.internal.authscheme.IPoPAuthenticationSchemeParams)

Example 3 with IClockSkewManager

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

the class AuthenticationSchemeFactory method createScheme.

/**
 * Gets the internal scheme equivalent for the provided public api scheme.
 *
 * @param nameable The nameable public scheme representation.
 * @return The internal scheme representation.
 */
public static AbstractAuthenticationScheme createScheme(@NonNull final Context context, @Nullable final INameable nameable) {
    if (null == nameable) {
        // If null, choose Bearer for backcompat
        return new BearerAuthenticationSchemeInternal();
    }
    switch(nameable.getName()) {
        case BearerAuthenticationSchemeInternal.SCHEME_BEARER:
            Logger.verbose(TAG, "Constructing Bearer Authentication Scheme.");
            return new BearerAuthenticationSchemeInternal();
        case PopAuthenticationSchemeInternal.SCHEME_POP:
            if (nameable instanceof IPoPAuthenticationSchemeParams) {
                Logger.verbose(TAG, "Constructing PoP Authentication Scheme.");
                final IPoPAuthenticationSchemeParams params = (IPoPAuthenticationSchemeParams) nameable;
                final IClockSkewManager clockSkewManager = new ClockSkewManager(context);
                return new PopAuthenticationSchemeInternal(clockSkewManager, params.getHttpMethod(), params.getUrl(), params.getNonce(), params.getClientClaims());
            } else {
                throw new IllegalStateException("Unrecognized parameter type.");
            }
        default:
            throw new UnsupportedOperationException("Unknown or unsupported scheme: " + nameable.getName());
    }
}
Also used : IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager) ClockSkewManager(com.microsoft.identity.common.internal.util.ClockSkewManager) IClockSkewManager(com.microsoft.identity.common.internal.util.IClockSkewManager)

Aggregations

ClockSkewManager (com.microsoft.identity.common.internal.util.ClockSkewManager)3 IClockSkewManager (com.microsoft.identity.common.internal.util.IClockSkewManager)3 Context (android.content.Context)1 NonNull (androidx.annotation.NonNull)1 AbstractAuthenticationScheme (com.microsoft.identity.common.internal.authscheme.AbstractAuthenticationScheme)1 BearerAuthenticationSchemeInternal (com.microsoft.identity.common.internal.authscheme.BearerAuthenticationSchemeInternal)1 IPoPAuthenticationSchemeParams (com.microsoft.identity.common.internal.authscheme.IPoPAuthenticationSchemeParams)1 PopAuthenticationSchemeInternal (com.microsoft.identity.common.internal.authscheme.PopAuthenticationSchemeInternal)1 OAuth2TokenCache (com.microsoft.identity.common.internal.providers.oauth2.OAuth2TokenCache)1 GenerateShrResult (com.microsoft.identity.common.internal.result.GenerateShrResult)1