An online markdown blog and knowledge repository.
Read the sections on Getting Started and Sign In.
Android SDK API Level 16 or higher required.
Provision authentication resources in Amplify
amplify add auth
amplify push
implementation 'com.amplifyframework:aws-auth-cognito:1.36.1;
Add the auth plugin:
Amplify.addPlugin(new AWSCognitoAuthPlugin());
Amplify.configure(getApplicationContext());
Check current Auth session (could be run from Main Activity 'onCreate()' method):
Amplify.Auth.fetchAuthSession(
result -> Log.i("AmplifyQuickstart", result.toString()),
error -> Log.e("AmplifyQuickstart", error.toString())
);
// code snippet care of docs.amplify.aws
AuthSession has a property 'isSignedIn' that is used to determine if user is ...signed in... or not. In the above code example from docs.amplify.com, no user will be signed in.
Dev Prerequisites: Previous subsections must be completed.
User Requirements: Username, password, and email address for registration.
AuthSignUpOptions options = AuthSignUpOptions.builder()
.userAttribute(AuthUserAttributeKey.email(), "my@email.com")
.build();
Amplify.Auth.signUp("username", "Password123", options,
result -> Log.i("AuthQuickStart", "Result: " + result.toString()),
error -> Log.e("AuthQuickStart", "Sign up failed", error)
);
// above code snippet from docs.amplify.aws
The above code invokes the API to do the registration work.
User Confirmation is required before signin is allowed.
Confirmation Code will be sent to user's email ID, and that confirmation code must be added to the confirmSignUp
call in code.
// console/terminal window will output result of this call.
Amplify.Auth.confirmSignUp(
"username",
"the code you received via email",
result -> Log.i("AuthQuickstart", result.isSignUpComplete() ? "Confirm signUp succeeded" : "Confirm sign up not complete"),
error -> Log.e("AuthQuickstart", error.toString())
);
// above code snippet from docs.amplify.aws
A UI is necessary to allow a user to login with a registered username and password.
Once username and password have been entered, call the signIn()
flow to authenticate and 'log in' the user.
Amplify.Auth.signIn(
"username",
"password",
result -> Log.i("AuthQuickstart", result.isSignInComplete() ? "Sign in succeeded" : "Sign in not complete"),
error -> Log.e("AuthQuickstart", error.toString())
);
// above code snippet from docs.amplify.aws
Multi-factor Auth.
More later, but this will require running Amplify Add Auth
again and answering 'Manual Configuration' during initial Q&A.
Of course, follow-up with Amplify Push
.
Return to Root README