Search in sources :

Example 1 with GetDeviceRequest

use of com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest in project aws-sdk-android by aws-amplify.

the class DeviceOperations method _getDevice.

private ReturningRunnable<Device> _getDevice(final String deviceKey) {
    return new ReturningRunnable<Device>() {

        @Override
        public Device run() throws Exception {
            CognitoDevice cognitoDevice = getCognitoDevice(deviceKey);
            final GetDeviceRequest getDeviceRequest = new GetDeviceRequest();
            getDeviceRequest.setAccessToken(mobileClient.getTokens().getAccessToken().getTokenString());
            getDeviceRequest.setDeviceKey(cognitoDevice.getDeviceKey());
            final GetDeviceResult getDeviceResult = userpoolLL.getDevice(getDeviceRequest);
            return marshallDeviceTypeToDevice(getDeviceResult.getDevice());
        }
    };
}
Also used : ReturningRunnable(com.amazonaws.mobile.client.internal.ReturningRunnable) GetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest) GetDeviceResult(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceResult) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)

Example 2 with GetDeviceRequest

use of com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderDevicesTest method getDeviceDetailsInCurrentThread.

@Test
public void getDeviceDetailsInCurrentThread() {
    CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Store tokens in shared preferences
    final String testAccessToken = getValidJWT(3600L);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + ".idToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_GET_DEVICE_RESPONSE).when(mockCSIClient).getDevice(any(GetDeviceRequest.class));
    CognitoDevice cachedDevice = testUser.thisDevice();
    cachedDevice.getDevice(new GenericHandler() {

        @Override
        public void onSuccess() {
            ArgumentCaptor<GetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(GetDeviceRequest.class);
            verify(mockCSIClient).getDevice(argumentCaptor.capture());
            GetDeviceRequest requestSent = argumentCaptor.getValue();
            assertEquals(testAccessToken, requestSent.getAccessToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) GetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) Test(org.junit.Test)

Example 3 with GetDeviceRequest

use of com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderDevicesTest method getDeviceDetailsInBackgroundThread.

@Test
public void getDeviceDetailsInBackgroundThread() {
    CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
    testUser = testPool.getUser(TEST_USER_NAME);
    // Store tokens in shared preferences
    final String testAccessToken = getValidJWT(3600L);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + ".idToken", getValidJWT(3600L));
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
    awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
    // Set mock result for the change password request API call
    doReturn(TEST_VALID_GET_DEVICE_RESPONSE).when(mockCSIClient).getDevice(any(GetDeviceRequest.class));
    CognitoDevice cachedDevice = testUser.thisDevice();
    cachedDevice.getDeviceInBackground(new GenericHandler() {

        @Override
        public void onSuccess() {
            ArgumentCaptor<GetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(GetDeviceRequest.class);
            verify(mockCSIClient).getDevice(argumentCaptor.capture());
            GetDeviceRequest requestSent = argumentCaptor.getValue();
            assertEquals(testAccessToken, requestSent.getAccessToken());
        }

        @Override
        public void onFailure(Exception exception) {
            assertNotNull(exception);
        }
    });
}
Also used : GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) GetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) Test(org.junit.Test)

Example 4 with GetDeviceRequest

use of com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest in project aws-sdk-android by aws-amplify.

the class CognitoDevice method getDeviceInternal.

/**
 * Internal method to fetch device details.
 *
 * @param session              REQUIRED: A valid {@link CognitoUserSession}.
 * @return
 */
private GetDeviceResult getDeviceInternal(CognitoUserSession session) {
    if (session != null && session.isValid()) {
        if (this.deviceKey != null) {
            final GetDeviceRequest getDeviceRequest = new GetDeviceRequest();
            getDeviceRequest.setAccessToken(session.getAccessToken().getJWTToken());
            getDeviceRequest.setDeviceKey(this.deviceKey);
            return user.getCognitoIdentityProviderClient().getDevice(getDeviceRequest);
        } else {
            throw new CognitoParameterInvalidException("Device key is null");
        }
    } else {
        throw new CognitoNotAuthorizedException("User is not authorized");
    }
}
Also used : CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) GetDeviceRequest(com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Aggregations

GetDeviceRequest (com.amazonaws.services.cognitoidentityprovider.model.GetDeviceRequest)4 CognitoDevice (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)3 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 ReturningRunnable (com.amazonaws.mobile.client.internal.ReturningRunnable)1 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)1 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)1 GetDeviceResult (com.amazonaws.services.cognitoidentityprovider.model.GetDeviceResult)1