Search in sources :

Example 1 with AWSKeyValueStore

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 username, final long expiryFromNow) {
    // Store tokens in shared preferences
    final AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(appContext, "CognitoIdentityProviderCache", true);
    String storeFieldPrefix = "CognitoIdentityProvider." + clientId + "." + username + ".";
    awsKeyValueStore.put("CognitoIdentityProvider." + clientId + ".LastAuthUser", username);
    awsKeyValueStore.put(storeFieldPrefix + "idToken", getValidJWT(expiryFromNow));
    awsKeyValueStore.put(storeFieldPrefix + "accessToken", getValidJWT(expiryFromNow));
    awsKeyValueStore.put(storeFieldPrefix + "refreshToken", "DummyRefresh");
}
Also used : AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)

Example 2 with AWSKeyValueStore

use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.

the class AWSMobileClientTestBase method setAccessToken.

public static void setAccessToken(final Context appContext, final String clientId, final String username, final String accessToken) {
    final AWSKeyValueStore awsKeyValueStore = new AWSKeyValueStore(appContext, "CognitoIdentityProviderCache", true);
    String storeFieldPrefix = "CognitoIdentityProvider." + clientId + "." + username + ".";
    awsKeyValueStore.put(storeFieldPrefix + "accessToken", accessToken);
}
Also used : AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)

Example 3 with AWSKeyValueStore

use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.

the class CognitoCachingCredentialsProvider method initialize.

/**
 * @param context the Android application context
 */
private void initialize(Context context) {
    awsKeyValueStore = new AWSKeyValueStore(context, AWS_KEY_VALUE_STORE_NAMESPACE_IDENTIFIER, isPersistenceEnabled);
    checkUpgrade();
    this.identityId = getCachedIdentityId();
    loadCachedCredentials();
    registerIdentityChangedListener(listener);
}
Also used : AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)

Example 4 with AWSKeyValueStore

use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.

the class CognitoUserPool method initialize.

private void initialize(final Context context) {
    this.awsKeyValueStore = new AWSKeyValueStore(context, DEFAULT_SHARED_PREFERENCES_NAME, isPersistenceEnabled);
    CognitoDeviceHelper.setPersistenceEnabled(isPersistenceEnabled);
}
Also used : AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)

Example 5 with AWSKeyValueStore

use of com.amazonaws.internal.keyvaluestore.AWSKeyValueStore in project aws-sdk-android by aws-amplify.

the class CognitoDeviceHelper method cacheDeviceGroupKey.

/**
 * This method caches the device group key. 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 deviceGroupKey    REQUIRED: Cognito assigned device group key.
 * @param context           REQUIRED: App context, needed to access device datastore.
 */
public static void cacheDeviceGroupKey(String username, String userPoolId, String deviceGroupKey, Context context) {
    try {
        final AWSKeyValueStore awsKeyValueStore = getAWSKeyValueStore(context, username, userPoolId);
        awsKeyValueStore.put(COGNITO_DEVICE_GROUP_KEY, deviceGroupKey);
    } catch (final Exception e) {
        LOGGER.error("Error accessing SharedPreferences", e);
    }
}
Also used : AWSKeyValueStore(com.amazonaws.internal.keyvaluestore.AWSKeyValueStore) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

AWSKeyValueStore (com.amazonaws.internal.keyvaluestore.AWSKeyValueStore)17 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Test (org.junit.Test)4 AmazonClientException (com.amazonaws.AmazonClientException)2 AmazonServiceException (com.amazonaws.AmazonServiceException)2 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)2 UnknownHostException (java.net.UnknownHostException)2 JSONException (org.json.JSONException)2 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AuthUserSession (com.amazonaws.mobileconnectors.cognitoauth.AuthUserSession)1 AccessToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.AccessToken)1 IdToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.IdToken)1 RefreshToken (com.amazonaws.mobileconnectors.cognitoauth.tokens.RefreshToken)1 CognitoUser (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUser)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 JSONObject (org.json.JSONObject)1