use of com.amazonaws.mobile.config.AWSConfiguration in project aws-sdk-android by aws-amplify.
the class SignUpActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_up);
signUpView = (SignUpView) findViewById(R.id.signup_view);
Context appContext = getApplicationContext();
mUserPool = new CognitoUserPool(appContext, new AWSConfiguration(appContext));
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
}
use of com.amazonaws.mobile.config.AWSConfiguration in project amplify-android by aws-amplify.
the class AuthComponentConfigureTest method testConfigure.
/**
* Tests that the configure method of the Auth wrapper of AWSMobileClient (AMC) calls AMC.initialize() with the
* passed in context, a new AWSConfiguration object containing the passed in JSONObject, and a callback object
* which causes configure to complete successfully in the onResult case.
* @throws AmplifyException an exception wrapping the exception returned in onError of AMC.initialize()
* @throws JSONException has to be declared as part of creating a test JSON object
*/
@Test
public void testConfigure() throws AmplifyException, JSONException {
UserStateDetails userStateDetails = new UserStateDetails(UserState.SIGNED_OUT, null);
Context context = getApplicationContext();
JSONObject pluginConfig = new JSONObject().put("TestKey", "TestVal");
pluginConfig.put("UserAgentOverride", UserAgent.string());
JSONObject json = new JSONObject().put("plugins", new JSONObject().put(PLUGIN_KEY, pluginConfig));
AuthCategoryConfiguration authConfig = new AuthCategoryConfiguration();
authConfig.populateFromJSON(json);
doAnswer(invocation -> {
Callback<UserStateDetails> callback = invocation.getArgument(2);
callback.onResult(userStateDetails);
return null;
}).when(mobileClient).initialize(any(), any(), any());
authCategory.configure(authConfig, context);
ArgumentCaptor<AWSConfiguration> awsConfigCaptor = ArgumentCaptor.forClass(AWSConfiguration.class);
verify(mobileClient).initialize(eq(context), awsConfigCaptor.capture(), any());
String returnedConfig = awsConfigCaptor.getValue().toString();
String inputConfig = pluginConfig.toString();
// Strip the opening and closing braces from the test input and ensure that the key/value pair is included
// in the returned aws config.
assertTrue(returnedConfig.contains(inputConfig.substring(1, inputConfig.length() - 1)));
}
use of com.amazonaws.mobile.config.AWSConfiguration in project amplify-android by aws-amplify.
the class SynchronousMobileClient method initialize.
/**
* Initialize the client for use, in a synchronous way, by delegating to
* {@link AWSMobileClient#initialize(Context, Callback)}.
* @param context An Android Context
* @param awsConfiguration custom AWS configuration to use for initializing Mobile Client
* @return The result received by {@link AWSMobileClient#initialize(Context, Callback)}, if successful
* @throws MobileClientException A wrapped form of the error received by the async callback.
*/
@NonNull
public UserStateDetails initialize(@NonNull Context context, @NonNull AWSConfiguration awsConfiguration) throws MobileClientException {
Objects.requireNonNull(context);
Objects.requireNonNull(awsConfiguration);
final UserStateDetails userStateDetails;
try {
userStateDetails = Await.<UserStateDetails, Exception>result((onResult, onError) -> {
Callback<UserStateDetails> callback = DelegatingCallback.with(onResult, onError);
awsMobileClient.initialize(context, awsConfiguration, callback);
});
} catch (Exception initializationError) {
throw new MobileClientException("Failed to initialize Mobile Client", initializationError);
}
return Objects.requireNonNull(userStateDetails);
}
use of com.amazonaws.mobile.config.AWSConfiguration in project amplify-android by aws-amplify.
the class SynchronousMobileClient method initialize.
/**
* Initialize the client for use, in a synchronous way, by delegating to
* {@link AWSMobileClient#initialize(Context, Callback)}. It constructs a default
* instance of {@link AWSConfiguration} using the provided context to locate
* awsconfiguration.json file.
* @param context An Android Context
* @return The result received by {@link AWSMobileClient#initialize(Context, Callback)}, if successful
* @throws MobileClientException A wrapped form of the error received by the async callback.
*/
@NonNull
public UserStateDetails initialize(@NonNull Context context) throws MobileClientException {
Objects.requireNonNull(context);
AWSConfiguration configuration = new AWSConfiguration(context);
return initialize(context, configuration);
}
use of com.amazonaws.mobile.config.AWSConfiguration in project aws-sdk-android by aws-amplify.
the class AWSMobileClientTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
setUpCredentials();
Context appContext = ApplicationProvider.getApplicationContext();
final CountDownLatch latch = new CountDownLatch(1);
AWSMobileClient.getInstance().initialize(appContext, new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails result) {
latch.countDown();
}
@Override
public void onError(Exception e) {
latch.countDown();
}
});
latch.await();
final AWSConfiguration awsConfiguration = AWSMobileClient.getInstance().getConfiguration();
JSONObject userPoolConfig = awsConfiguration.optJsonObject("CognitoUserPool");
assertNotNull(userPoolConfig);
clientRegion = Regions.fromName(userPoolConfig.getString("Region"));
userPoolId = userPoolConfig.getString("PoolId");
clientId = userPoolConfig.getString("AppClientId");
clientSecret = userPoolConfig.optString("AppClientSecret");
JSONObject identityPoolConfig = awsConfiguration.optJsonObject("CredentialsProvider").getJSONObject("CognitoIdentity").getJSONObject("Default");
assertNotNull(identityPoolConfig);
identityPoolId = identityPoolConfig.getString("PoolId");
userPool = new CognitoUserPool(appContext, userPoolId, clientId, clientSecret, clientRegion);
deleteAllUsers(userPoolId);
createUserViaAdminAPI(userPoolId, USERNAME_ADMIN_API_USER, EMAIL_ADMIN_API_USER);
}
Aggregations