繁体   English   中英

使用Facebook身份验证的Amazon Cognito身份管理

[英]Amazon cognito identity management with facebook authentication

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

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

这是我与Cognito Identitypool一起使用的IAM角色的策略

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

        }
    }

您如何检查自己是否获得了Cognito ID? 您提供的摘录仅配置凭据提供程序,您实际上如何使用它? 您是否正在向您的dynamodb客户拨打电话?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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