简体   繁体   中英

Amazon cognito identity management with facebook authentication

I am using Amazon Cognito for identity management in my android application which uses Facebook authentication using fragment.
With credentials provided it is not creating any identity in Cognito when application is used in adb.

I referred to this tutorial:- http://mobile.awsblog.com/post/TxR1UCU80YEJJZ/Using-the-Amazon-Cognito-Credentials-Provider

Here the policy of my IAM role with cognito identitypool

{
"Statement": [{
    "Action": [
        "cognito-sync:*"
    ],
    "Effect": "Allow",
    "Resource":                                                                                      ["arn:aws:cognito-sync:us-east-1:*****************************:identitypool/*"]
    }]
}

and the code oncreate function in MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    FragmentManager fm = getSupportFragmentManager();
    fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
    fragments[SEARCH] = fm.findFragmentById(R.id.searchFragment);
    fragments[SETTINGS] = fm.findFragmentById(R.id.userSettingsFragment);


    credentialsProvider = new CognitoCredentialsProvider(
            getBaseContext(), // get the context for the current activity        
            "************", // your AWS Account id     
            "us-east-1:**************************", // your identity pool id    
            "arn:aws:iam::************:role/Cognito_******_DefaultRole",// an authenticated role ARN
            "arn:aws:iam::************:role/Cognito_******_DefaultRole" // an unauthenticated role ARN
        );
    client=  new AmazonDynamoDBClient(credentialsProvider);

    FragmentTransaction transaction = fm.beginTransaction();
    for(int i = 0; i < fragments.length; i++) {
        transaction.hide(fragments[i]);
    }
    transaction.commit();

}

and my SessionStateChange function in MainActivity.java is

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        if (isResumed) {
            FragmentManager manager = getSupportFragmentManager();
            // Get the number of entries in the back stack
            int backStackSize = manager.getBackStackEntryCount();
            // Clear the back stack
            for (int i = 0; i < backStackSize; i++) {
                manager.popBackStack();
            }
        if (state.isOpened()) {

                Map<String, String> logins = new HashMap<String, String>();
                logins.put("graph.facebook.com", Session.getActiveSession()
                        .getAccessToken());
                credentialsProvider.withLogins(logins);
                /*login dispatch check*/
                showFragment(SEARCH, false);

        } else if (state.isClosed()) {
             showFragment(SPLASH, false);
        }

        }
    }

How did you check if you were getting a Cognito id? The snippets you provided only configure the credentials provider, how are you actually using it? Are you making calls against your dynamodb client?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM