use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class CognitoDeviceHelper method cacheDeviceVerifier.
/**
* This method caches the device verifier. Device verifier is generated locally by the SDK and
* it is used to authenticate the device through device SRP authentication.
*
* @param username REQUIRED: The current user.
* @param userPoolId REQUIRED: Client ID of the device.
* @param deviceSecret REQUIRED: Cognito assigned device key.
* @param context REQUIRED: App context, needed to access device datastore.
*/
public static void cacheDeviceVerifier(String username, String userPoolId, String deviceSecret, Context context) {
try {
final AWSKeyValueStore awsKeyValueStore = getAWSKeyValueStore(context, username, userPoolId);
awsKeyValueStore.put(COGNITO_DEVICE_SECRET, deviceSecret);
} catch (final Exception e) {
LOGGER.error("Error accessing SharedPreferences", e);
}
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class CognitoDeviceHelper method setPersistenceEnabled.
/**
* Set the flag that indicates if the persistence is enabled or not.
* @param isPersistenceEnabled flag that indicates if the persistence is enabled or not.
*/
public static void setPersistenceEnabled(boolean isPersistenceEnabled) {
synchronized (LOCK) {
try {
CognitoDeviceHelper.isPersistenceEnabled = isPersistenceEnabled;
for (String sharedPreferencesName : awsKeyValueStoreMap.keySet()) {
AWSKeyValueStore awsKeyValueStore = awsKeyValueStoreMap.get(sharedPreferencesName);
awsKeyValueStore.setPersistenceEnabled(isPersistenceEnabled);
}
} catch (Exception ex) {
LOGGER.error("Error in setting the isPersistenceEnabled flag in the key-value store.", ex);
}
}
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class AWSMobileClientTestBase method setTokensDirectly.
public static void setTokensDirectly(final Context appContext, final String providerKey, final String token, final String identityId) {
final AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(appContext, AWSMobileClient.SHARED_PREFERENCES_KEY, true);
awsKeyValueStore.put(AWSMobileClient.PROVIDER_KEY, providerKey);
awsKeyValueStore.put(AWSMobileClient.TOKEN_KEY, token);
awsKeyValueStore.put(AWSMobileClient.IDENTITY_ID_KEY, identityId);
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class AWSMobileClientTestBase method writeUserPoolsTokens.
public static void writeUserPoolsTokens(final Context appContext, final String clientId, final String userId, final String accessToken, final String idToken, final String refreshToken) {
final AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(appContext, "CognitoIdentityProviderCache", true);
// Create keys to look for cached tokens
final String csiIdTokenKey = "CognitoIdentityProvider." + clientId + "." + userId + ".idToken";
final String csiAccessTokenKey = "CognitoIdentityProvider." + clientId + "." + userId + ".accessToken";
final String csiRefreshTokenKey = "CognitoIdentityProvider." + clientId + "." + userId + ".refreshToken";
final String csiLastUserKey = "CognitoIdentityProvider." + clientId + ".LastAuthUser";
// Store the data in Shared Preferences
awsKeyValueStore.put(csiAccessTokenKey, accessToken);
awsKeyValueStore.put(csiIdTokenKey, idToken);
awsKeyValueStore.put(csiRefreshTokenKey, refreshToken);
awsKeyValueStore.put(csiLastUserKey, userId);
}
use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.
the class AWSMobileClientNetworkIssueTest method testNetworkExceptionPropagation_getTokens.
@Test
public void testNetworkExceptionPropagation_getTokens() throws Exception {
reinitialize();
final AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(appContext, AWSMobileClient.SHARED_PREFERENCES_KEY, true);
awsKeyValueStore.put(AWSMobileClient.PROVIDER_KEY, AWSMobileClient.getInstance().getLoginKey());
awsKeyValueStore.put(AWSMobileClient.TOKEN_KEY, getValidJWT(-3600L));
awsKeyValueStore.put(AWSMobileClient.IDENTITY_ID_KEY, "");
writeUserPoolsTokens(appContext, auth.getConfiguration().optJsonObject("CognitoUserPool").getString("AppClientId"), username, -3600L);
Field f1 = CognitoUserPool.class.getDeclaredField("client");
f1.setAccessible(true);
f1.set(auth.userpool, mockLowLevel);
try {
auth.getTokens();
fail("Should throw exception for network issue");
} catch (Exception e) {
assertTrue("Deep cause should be network exception", e.getCause().getCause().getCause() instanceof UnknownHostException);
}
}
Aggregations