To keep my app simple for now, I decided to use the drop-in auth flow by AWS Amplify, instead of creating my own sign-up/sign-in flow.
This is how my app AuthenticationActivity looks, using the drop-in auth for Android when creating a new user:

This is the AuthenticationActivity code:
package com.aws.tool;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.amazonaws.mobile.client.AWSMobileClient;
import com.amazonaws.mobile.client.Callback;
import com.amazonaws.mobile.client.SignInUIOptions;
import com.amazonaws.mobile.client.UserStateDetails;
public class AuthenticationActivity extends AppCompatActivity {
private final String TAG = AuthenticationActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_authentication);
AWSMobileClient.getInstance().initialize(getApplicationContext(), new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails userStateDetails) {
Log.i(TAG, userStateDetails.getUserState().toString());
switch (userStateDetails.getUserState()){
case SIGNED_IN:
Intent i = new Intent(AuthenticationActivity.this, MainActivity.class);
startActivity(i);
break;
case SIGNED_OUT:
showSignIn();
break;
default:
AWSMobileClient.getInstance().signOut();
showSignIn();
break;
}
}
@Override
public void onError(Exception e) {
Log.e(TAG, e.toString());
}
});
}
private void showSignIn() {
try {
AWSMobileClient.getInstance().showSignIn(this,
SignInUIOptions.builder()
.nextActivity(MainActivity.class).build()
);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
}
In my case, I only need an email + password, so these are the rules I set up on AWS Cognito.
However, you can see that I have a few extra attributes generated by drop-in auth UI:
- USERNAME
- Given name
- Phone number
I tried to leave these fields blank and register, but I get UI errors, of course. If I try to fill all the fields, I get an error, indicating that I am trying to send unauthorized attributes to AWS cognito.
So I went back to the Auth-drop documentation, but I figured out it is only possible to customize the drop-in auth background color and background image.
You can see it from AWS documentation:
https://aws-amplify.github.io/docs/android/authentication#customization
I found no way to edit the attributes as to my liking for a simple use case like mine, and therefore I am forced to either:
- Change my AWS Cognito rules, forcing me to use a phone, name attribute, and username
- Write my own sign-in/sign-up
Am I missing something? Is there a way around it?
