Search in sources :

Example 46 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class AWSAppSyncClients method withIAMFromAWSConfiguration.

@NonNull
public static AWSAppSyncClient withIAMFromAWSConfiguration(boolean subscriptionsAutoReconnect, long credentialsDelay) {
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_AWS_IAM");
    JSONObject ccpConfig = awsConfiguration.optJsonObject("CredentialsProvider");
    String cognitoIdentityPoolID = JsonExtract.stringValue(ccpConfig, "CognitoIdentity.Default.PoolId");
    String cognitoRegion = JsonExtract.stringValue(ccpConfig, "CognitoIdentity.Default.Region");
    DelayedCognitoCredentialsProvider credentialsProvider = new DelayedCognitoCredentialsProvider(cognitoIdentityPoolID, Regions.fromName(cognitoRegion), credentialsDelay);
    AmazonS3Client s3Client = new AmazonS3Client(credentialsProvider, Region.getRegion("us-west-2"));
    S3ObjectManager s3ObjectManager = new S3ObjectManagerImplementation(s3Client);
    return AWSAppSyncClient.builder().context(getTargetContext()).credentialsProvider(credentialsProvider).awsConfiguration(awsConfiguration).conflictResolver(new TestConflictResolver()).s3ObjectManager(s3ObjectManager).subscriptionsAutoReconnect(subscriptionsAutoReconnect).mutationQueueExecutionTimeout(TimeUnit.SECONDS.toMillis(30)).persistentMutationsCallback(LoggingPersistentMutationsCallback.instance()).useClientDatabasePrefix(true).build();
}
Also used : S3ObjectManager(com.apollographql.apollo.api.S3ObjectManager) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) JSONObject(org.json.JSONObject) DelayedCognitoCredentialsProvider(com.amazonaws.mobileconnectors.appsync.identity.DelayedCognitoCredentialsProvider) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) S3ObjectManagerImplementation(com.amazonaws.mobileconnectors.appsync.S3ObjectManagerImplementation) NonNull(androidx.annotation.NonNull)

Example 47 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class AWSAppSyncClients method withUserPoolsFromAWSConfiguration.

@NonNull
public static AWSAppSyncClient withUserPoolsFromAWSConfiguration(ResponseFetcher responseFetcher) {
    // Amazon Cognito User Pools
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS");
    return AWSAppSyncClient.builder().context(getTargetContext()).awsConfiguration(awsConfiguration).cognitoUserPoolsAuthProvider(() -> {
        try {
            String idToken = TestAWSMobileClient.instance(getTargetContext()).getTokens().getIdToken().getTokenString();
            Log.d(TAG, "idToken = " + idToken);
            return idToken;
        } catch (Exception exception) {
            exception.printStackTrace();
            return null;
        }
    }).useClientDatabasePrefix(true).defaultResponseFetcher(responseFetcher).build();
}
Also used : AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) JSONException(org.json.JSONException) NonNull(androidx.annotation.NonNull)

Example 48 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project aws-mobile-appsync-sdk-android by awslabs.

the class AWSAppSyncClients method withUserPools2FromAWSConfiguration.

@NonNull
public static AWSAppSyncClient withUserPools2FromAWSConfiguration(String idTokenStringForCustomCognitoUserPool, ResponseFetcher responseFetcher) {
    // Amazon Cognito User Pools - Custom CognitoUserPool
    String clientDatabasePrefix = null;
    String clientName = null;
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS_2");
    try {
        clientDatabasePrefix = awsConfiguration.optJsonObject("AppSync").getString("ClientDatabasePrefix");
        clientName = awsConfiguration.optJsonObject("AppSync").getString("AuthMode");
    } catch (JSONException e) {
        e.printStackTrace();
    }
    AWSAppSyncClient.Builder awsAppSyncClientBuilder4 = AWSAppSyncClient.builder().context(getTargetContext()).cognitoUserPoolsAuthProvider(() -> idTokenStringForCustomCognitoUserPool).awsConfiguration(awsConfiguration).useClientDatabasePrefix(true).defaultResponseFetcher(responseFetcher);
    AWSAppSyncClient awsAppSyncClient4 = awsAppSyncClientBuilder4.build();
    validateAppSyncClient(awsAppSyncClient4, clientDatabasePrefix, clientName);
    return awsAppSyncClient4;
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) JSONException(org.json.JSONException) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) NonNull(androidx.annotation.NonNull)

Aggregations

AWSConfiguration (com.amazonaws.mobile.config.AWSConfiguration)48 JSONObject (org.json.JSONObject)28 Test (org.junit.Test)26 JSONException (org.json.JSONException)16 Context (android.content.Context)13 NonNull (androidx.annotation.NonNull)11 BasicAPIKeyAuthProvider (com.amazonaws.mobileconnectors.appsync.sigv4.BasicAPIKeyAuthProvider)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 BeforeClass (org.junit.BeforeClass)7 AWSAppSyncClient (com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient)6 UserStateDetails (com.amazonaws.mobile.client.UserStateDetails)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 SignInResult (com.amazonaws.mobile.client.results.SignInResult)3 CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool)3 UserNotConfirmedException (com.amazonaws.services.cognitoidentityprovider.model.UserNotConfirmedException)3 Nullable (androidx.annotation.Nullable)2 ApplicationProvider.getApplicationContext (androidx.test.core.app.ApplicationProvider.getApplicationContext)2 AWSMobileClient (com.amazonaws.mobile.client.AWSMobileClient)2 Callback (com.amazonaws.mobile.client.Callback)2