2

我在我的 android 应用程序中使用 Amazon Cognito 进行身份管理,该应用程序使用 Fragment 进行 Facebook 身份验证。
在 adb 中使用应用程序时,使用提供的凭据不会在 Cognito 中创建任何身份。

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

这是我的 IAM 角色与 cognito 身份池的策略

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

        }
    }
4

1 回答 1

0

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

于 2014-08-07T22:11:47.243 回答