Search in sources :

Example 1 with IDevicePopManager

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

the class MicrosoftStsOAuth2Strategy method getDeviceAtPopThumbprint.

/**
 * Gets the at/pop device credential's thumbprint.
 *
 * @return The at/pop device credential thumbprint.
 */
@Nullable
public String getDeviceAtPopThumbprint() {
    String atPoPKid = null;
    IDevicePopManager devicePopManager = null;
    try {
        devicePopManager = Device.getDevicePoPManagerInstance();
    } catch (final ClientException e) {
        Logger.error(TAG, e.getMessage(), e);
    }
    if (null != devicePopManager) {
        if (devicePopManager.asymmetricKeyExists()) {
            try {
                atPoPKid = devicePopManager.getAsymmetricKeyThumbprint();
            } catch (final ClientException e) {
                Logger.error(TAG, "Key exists. But failed to load thumbprint.", e);
                throw new RuntimeException(e);
            }
        } else {
            // something has gone seriously wrong.
            throw new RuntimeException("Symmetric keys do not exist.");
        }
    } else {
        Logger.warn(TAG, "DevicePopManager does not exist.");
    }
    return atPoPKid;
}
Also used : IDevicePopManager(com.microsoft.identity.common.internal.platform.IDevicePopManager) ClientException(com.microsoft.identity.common.exception.ClientException) Nullable(androidx.annotation.Nullable)

Example 2 with IDevicePopManager

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

the class MicrosoftStsOAuth2Strategy method createTokenRequest.

@Override
public MicrosoftStsTokenRequest createTokenRequest(@NonNull final MicrosoftStsAuthorizationRequest request, @NonNull final MicrosoftStsAuthorizationResponse response, @NonNull final AbstractAuthenticationScheme authScheme) throws ClientException {
    final String methodName = ":createTokenRequest";
    Logger.verbose(TAG + methodName, "Creating TokenRequest...");
    if (mConfig.getMultipleCloudsSupported() || request.getMultipleCloudAware()) {
        Logger.verbose(TAG, "get cloud specific authority based on authorization response.");
        setTokenEndpoint(getCloudSpecificTokenEndpoint(response));
    }
    final MicrosoftStsTokenRequest tokenRequest = new MicrosoftStsTokenRequest();
    tokenRequest.setCodeVerifier(request.getPkceChallenge().getCodeVerifier());
    tokenRequest.setCode(response.getCode());
    tokenRequest.setRedirectUri(request.getRedirectUri());
    tokenRequest.setClientId(request.getClientId());
    tokenRequest.setScope(request.getTokenScope());
    tokenRequest.setClaims(request.getClaims());
    setTokenRequestCorrelationId(tokenRequest);
    // Existence of a device code inside of the response object implies Device Code Flow is being used
    if (response.getDeviceCode() != null) {
        tokenRequest.setGrantType(TokenRequest.GrantTypes.DEVICE_CODE);
        tokenRequest.setDeviceCode(response.getDeviceCode());
    } else {
        // If device code doesn't exist, continue with auth_code configuration
        tokenRequest.setGrantType(TokenRequest.GrantTypes.AUTHORIZATION_CODE);
    }
    if (SCHEME_POP.equals(authScheme.getName())) {
        if (null == mStrategyParameters.getContext()) {
            throw new ClientException(MicrosoftStsOAuth2Strategy.class.getSimpleName() + "Cannot execute PoP request sans Context");
        }
        // Add a token_type
        tokenRequest.setTokenType(TokenRequest.TokenType.POP);
        final IDevicePopManager devicePopManager = Device.getDevicePoPManagerInstance();
        // Generate keys if they don't already exist...
        if (!devicePopManager.asymmetricKeyExists()) {
            final String thumbprint = devicePopManager.generateAsymmetricKey(mStrategyParameters.getContext());
            Logger.verbosePII(TAG, "Generated new PoP asymmetric key with thumbprint: " + thumbprint);
        }
        final String reqCnf = devicePopManager.getRequestConfirmation();
        // Set the req_cnf
        tokenRequest.setRequestConfirmation(reqCnf);
    }
    return tokenRequest;
}
Also used : IDevicePopManager(com.microsoft.identity.common.internal.platform.IDevicePopManager) ClientException(com.microsoft.identity.common.exception.ClientException)

Example 3 with IDevicePopManager

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

the class MicrosoftStsOAuth2Strategy method createRefreshTokenRequest.

@Override
public MicrosoftStsTokenRequest createRefreshTokenRequest(@NonNull final AbstractAuthenticationScheme authScheme) throws ClientException {
    final String methodName = ":createRefreshTokenRequest";
    Logger.verbose(TAG + methodName, "Creating refresh token request");
    final MicrosoftStsTokenRequest request = new MicrosoftStsTokenRequest();
    request.setGrantType(TokenRequest.GrantTypes.REFRESH_TOKEN);
    if (SCHEME_POP.equals(authScheme.getName())) {
        request.setTokenType(TokenRequest.TokenType.POP);
        final IDevicePopManager devicePopManager = Device.getDevicePoPManagerInstance();
        if (!devicePopManager.asymmetricKeyExists()) {
            devicePopManager.generateAsymmetricKey(mStrategyParameters.getContext());
        }
        request.setRequestConfirmation(devicePopManager.getRequestConfirmation());
    }
    return request;
}
Also used : IDevicePopManager(com.microsoft.identity.common.internal.platform.IDevicePopManager)

Aggregations

IDevicePopManager (com.microsoft.identity.common.internal.platform.IDevicePopManager)3 ClientException (com.microsoft.identity.common.exception.ClientException)2 Nullable (androidx.annotation.Nullable)1