首页 文章

亚马逊认知身份管理与Facebook身份验证

提问于
浏览
2

我在我的Android应用程序中使用Amazon Cognito进行身份管理,该应用程序使用片段进行Facebook身份验证 .
使用凭据时,如果在adb中使用应用程序,则不会在Cognito中创建任何标识 .

我参考了这个教程: - http://mobile.awsblog.com/post/TxR1UCU80YEJJZ/Using-the-Amazon-Cognito-Credentials-Provider

这里是我的IAM角色与cognito identitypool的政策

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

和MainActivity.java中的代码oncreate函数

@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();

}

我在MainActivity.java中的SessionStateChange函数是

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);
        }

        }
    }

1 回答

  • 0

    你是如何检查你是否获得了Cognito id?您提供的代码段仅配置凭据提供程序,您实际上是如何使用它的?你是否打电话给你的dynamodb客户端?

相关问题