Example usage for com.amazonaws.services.cognitoidp.model ConfirmDeviceRequest ConfirmDeviceRequest

List of usage examples for com.amazonaws.services.cognitoidp.model ConfirmDeviceRequest ConfirmDeviceRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.cognitoidp.model ConfirmDeviceRequest ConfirmDeviceRequest.

Prototype

ConfirmDeviceRequest

Source Link

Usage

From source file:io.fineo.client.auth.cognito.CognitoUser.java

License:Open Source License

/**
 * Internal method to confirm a device.//from   ww w.j a v a 2 s.c om
 *
 * @param session                           REQUIRED: A valid {@link CognitoUserSession}.
 * @param deviceKey                         REQUIRED: This is the device-key assigned the new device.
 * @param passwordVerifier                  REQUIRED: Random string generated by the SDK.
 * @param salt                              REQUIRED: Generated by the SDK to set the device verifier.
 * @param deviceName                        REQUIRED: A user identifiable string assigned to the device.
 * @return {@link ConfirmDeviceResult}, service response.
 */
private ConfirmDeviceResult confirmDeviceInternal(CognitoUserSession session, String deviceKey,
        String passwordVerifier, String salt, String deviceName) {
    if (session != null && session.isValid()) {
        if (deviceKey != null && deviceName != null) {
            DeviceSecretVerifierConfigType deviceConfig = new DeviceSecretVerifierConfigType();
            deviceConfig.setPasswordVerifier(passwordVerifier);
            deviceConfig.setSalt(salt);
            ConfirmDeviceRequest confirmDeviceRequest = new ConfirmDeviceRequest();
            confirmDeviceRequest.setAccessToken(session.getAccessToken().getJWTToken());
            confirmDeviceRequest.setDeviceKey(deviceKey);
            confirmDeviceRequest.setDeviceName(deviceName);
            confirmDeviceRequest.setDeviceSecretVerifierConfig(deviceConfig);
            return cognitoIdentityProviderClient.confirmDevice(confirmDeviceRequest);
        } else {
            if (deviceKey == null) {
                throw new CognitoParameterInvalidException("Device key is null");
            } else {
                throw new CognitoParameterInvalidException("Device name is null");
            }
        }
    } else {
        throw new CognitoNotAuthorizedException("User is not authorized");
    }
}