3
votes

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: Signup Screen

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.

UI errors on Signup Screen

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:

  1. Change my AWS Cognito rules, forcing me to use a phone, name attribute, and username
  2. Write my own sign-in/sign-up

Am I missing something? Is there a way around it?

2

2 Answers

1
votes

Username is mandatory but once you update your userpool settings from console to use email as the username, you can specify the email in the username field, set password and should be able to skip other fields while signing up.

0
votes

@Ofir Bar - I believe you have set the username to be a mandatory field while creating the user pool. Check what's your selection under the section "How do you want your end users to sign in?" If you have checked username, then this is expected behavior. and "Which standard attributes are required?" - Uncheck everything if you just need email and password