我在我的android应用程序中使用Amazon Cognito进行身份管理,该应用程序使用fragment使用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();
}
和我的SessionStateChange函数在MainActivity.java是
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客户打电话吗?