Amazon Cognito User Pool And Facebook Login in Android

390 Views Asked by At

I am using CognitoUserPool (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool) and I use the method getSessionInBackground for login CognitoUsers and signUpInBackground for create users.

For example, for login:

    CognitoUser me = userPool.getUser(email);
    me.getSessionInBackground(new AuthenticationHandler() {
        @Override
        public void onSuccess(CognitoUserSession userSession, CognitoDevice newDevice) {
            //OK
        }

        @Override
        public void getAuthenticationDetails(AuthenticationContinuation authenticationContinuation, String userId) {
            String password = "mypassword";
            AuthenticationDetails details = new AuthenticationDetails(userId, password, null);
            authenticationContinuation.setAuthenticationDetails(details);
            authenticationContinuation.continueTask();
        }

        @Override
        public void getMFACode(MultiFactorAuthenticationContinuation continuation) {

        }

        @Override
        public void authenticationChallenge(ChallengeContinuation continuation) {
            ...
        }

        @Override
        public void onFailure(Exception exception) {
            //ERROR
        }
    });

and for signUp:

    CognitoUserAttributes userAttributes = getAttributesFromUser(ctx, u);

    SignUpHandler signupCallback = new SignUpHandler() {

        @Override
        public void onSuccess(CognitoUser user, SignUpResult signUpResult) {
            // Sign-up was successful
        }

        @Override
        public void onFailure(Exception exception) {
            // Sign-up failed, check exception for the cause

        }
    };

    userPool.signUpInBackground(u.email, "mypassword", userAttributes, null, signupCallback);

I want to add Facebook support (I already have a facebook login in the app and I want to integrate facebook logged users in cognito pool. The docs says that I have to add a Logins object in the AWSCredentials, but I create my userpool as:

    userPool = new CognitoUserPool(ctx, POOL_ID, CLIENT_ID, CLIENT_SECRET, clientConfiguration, Regions.EU_CENTRAL_1);

and I have not found any constructor with AWSCredentials as input parameter.

I want to store users logged with facebook in my Amazon User Pool, I already have my custom server with facebook login, I am migrating the users to Amazon but I still have my regular and facebook login/register APIs.

Thanks in advance

0

There are 0 best solutions below