reading-notes-ma


Project maintained by mohnalkhateeb Hosted on GitHub Pages — Theme by mattgraham

Cognito

AUTHENTICATION

Goal

Prerequisites

Configure Auth Category

Install Amplify Libraries

Initialize Amplify Auth

Add the Auth plugin before calling Amplify.configure

    // Add this line, to include the Auth plugin.
    Amplify.addPlugin(new AWSCognitoAuthPlugin());
    Amplify.configure(getApplicationContext());

Check the current auth session

We can now check the current auth session.

For testing purposes, you can run this from your MainActivity’s onCreate method.

    Amplify.Auth.fetchAuthSession(
        result -> Log.i("AmplifyQuickstart", result.toString()),
        error -> Log.e("AmplifyQuickstart", error.toString())
    );

Register a user

Sign in a user

Implement a UI to get the username and password from the user. After the user enters the username and password you can start the sign in flow by calling the following method:

Amplify.Auth.signIn(
    "username",
    "password",
    result -> Log.i("AuthQuickstart", result.isSignInComplete() ? "Sign in succeeded" : "Sign in not complete"),
    error -> Log.e("AuthQuickstart", error.toString())
);