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());
}
};
}
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);
}
});
}
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);
}
});
}
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");
}
}
Aggregations