Search in sources :

Example 11 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) {
    // Amazon Cognito User Pools - Custom CognitoUserPool
    AWSConfiguration awsConfiguration = new AWSConfiguration(getTargetContext());
    awsConfiguration.setConfiguration("MultiAuthAndroidIntegTestApp_AMAZON_COGNITO_USER_POOLS_2");
    JSONObject appSyncConfig = awsConfiguration.optJsonObject("AppSync");
    String clientDatabasePrefix = JsonExtract.stringValue(appSyncConfig, "ClientDatabasePrefix");
    String clientName = JsonExtract.stringValue(appSyncConfig, "AuthMode");
    AWSAppSyncClient.Builder awsAppSyncClientBuilder4 = AWSAppSyncClient.builder().context(getTargetContext()).cognitoUserPoolsAuthProvider(() -> idTokenStringForCustomCognitoUserPool).awsConfiguration(awsConfiguration).useClientDatabasePrefix(true);
    AWSAppSyncClient awsAppSyncClient4 = awsAppSyncClientBuilder4.build();
    validateAppSyncClient(awsAppSyncClient4, clientDatabasePrefix, clientName);
    return awsAppSyncClient4;
}
Also used : AWSAppSyncClient(com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient) JSONObject(org.json.JSONObject) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) NonNull(androidx.annotation.NonNull)

Example 12 with AWSConfiguration

use of com.amazonaws.mobile.config.AWSConfiguration in project amplify-android by aws-amplify.

the class AnalyticsPinpointInstrumentedTest method setUp.

/**
 * Configure the Amplify framework.
 *
 * @throws AmplifyException From Amplify configuration.
 */
@BeforeClass
public static void setUp() throws AmplifyException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Exception> asyncException = new AtomicReference<>();
    Context context = getApplicationContext();
    AWSMobileClient.getInstance().initialize(context, new AWSConfiguration(context), new Callback<UserStateDetails>() {

        @Override
        public void onResult(UserStateDetails result) {
            latch.countDown();
        }

        @Override
        public void onError(Exception exception) {
            asyncException.set(exception);
            latch.countDown();
        }
    });
    try {
        if (latch.await(AUTH_TIMEOUT, TimeUnit.SECONDS)) {
            if (asyncException.get() != null) {
                fail("Failed to instantiate AWSMobileClient");
            }
        } else {
            fail("Failed to instantiate AWSMobileClient within " + AUTH_TIMEOUT + " seconds");
        }
    } catch (InterruptedException error) {
        fail("Failed to instantiate AWSMobileClient");
    }
    AWSPinpointAnalyticsPlugin plugin = new AWSPinpointAnalyticsPlugin((Application) context, AWSMobileClient.getInstance());
    Amplify.addPlugin(plugin);
    Amplify.configure(context);
    analyticsClient = plugin.getAnalyticsClient();
    targetingClient = plugin.getTargetingClient();
}
Also used : Context(android.content.Context) ApplicationProvider.getApplicationContext(androidx.test.core.app.ApplicationProvider.getApplicationContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) UserStateDetails(com.amazonaws.mobile.client.UserStateDetails) AmplifyException(com.amplifyframework.AmplifyException) JSONException(org.json.JSONException) BeforeClass(org.junit.BeforeClass)

Example 13 with AWSConfiguration

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

the class AWSMobileClientTest method testAWSConfigurationForCognitoUserPool.

@Test
public void testAWSConfigurationForCognitoUserPool() throws Exception {
    // Context of the app under test.
    Context appContext = ApplicationProvider.getApplicationContext();
    final AWSConfiguration awsConfiguration = new AWSConfiguration(appContext);
    assertNotNull(awsConfiguration.optJsonObject("CognitoUserPool"));
    assertEquals("us-west-2", awsConfiguration.optJsonObject("CognitoUserPool").getString("Region"));
    assertEquals("com.amazonaws.mobile.client.test", appContext.getPackageName());
}
Also used : Context(android.content.Context) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) Test(org.junit.Test)

Example 14 with AWSConfiguration

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

the class OAuth2Utils method initialize.

@AnyThread
public void initialize(final Context context, final Callback<UserStateDetails> callback) {
    final Context applicationContext = context.getApplicationContext();
    initialize(applicationContext, new AWSConfiguration(applicationContext), callback);
}
Also used : CognitoPinpointSharedContext(com.amazonaws.mobileconnectors.cognitoidentityprovider.util.CognitoPinpointSharedContext) Context(android.content.Context) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) AnyThread(androidx.annotation.AnyThread)

Example 15 with AWSConfiguration

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

the class AWSMobileClientCustomAuthTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    appContext = ApplicationProvider.getApplicationContext();
    final CountDownLatch latch = new CountDownLatch(1);
    final AWSConfiguration awsConfiguration = new AWSConfiguration(appContext);
    awsConfiguration.setConfiguration("Auth1");
    assert awsConfiguration.optJsonObject("Auth").has("authenticationFlowType");
    AWSMobileClient.getInstance().initialize(appContext, awsConfiguration, new Callback<UserStateDetails>() {

        @Override
        public void onResult(UserStateDetails result) {
            latch.countDown();
        }

        @Override
        public void onError(Exception e) {
            Log.e(TAG, "onError: ", e);
            latch.countDown();
        }
    });
    latch.await();
    auth = AWSMobileClient.getInstance();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AWSConfiguration(com.amazonaws.mobile.config.AWSConfiguration) BeforeClass(org.junit.BeforeClass)

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