Amazon SDK を使用して google+ で認証できません。Cognito ID と Google+ トークンの両方を取得でき、ID プールで認証されていないユーザーを確認できます。私のCognitoセットアップでは、サーバーを正しいサービスclientIDに設定しました。
これが私のコードです:
public class cognitoID extends AsyncTask<String, Void, Void>{
@Override
protected Void doInBackground(String ... id){
credentialsProvider = new CognitoCachingCredentialsProvider(
MainActivity.this, /* Current Activity Context */
"us-east-1:XXXXXXXX", /* Identity Pool ID */
Regions.US_EAST_1 /* Region */
);
credentialsProvider.getCredentials();
cognitoID = credentialsProvider.getIdentityId();
Log.i("Cognito", credentialsProvider.getIdentityId());
if(accessToken =="") {
mGoogleApiClient.connect();
Log.i("Getting me a token", "allright");
}
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
AccountManager am = AccountManager.get(getApplicationContext());
android.accounts.Account[] accounts = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
try{
accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
scope = "oauth2:" + Scopes.PLUS_LOGIN;
accessToken = GoogleAuthUtil.getToken(
getApplicationContext(), accountName, scope);
} catch (UserRecoverableAuthException recoverableException) {
Log.e("URAE", recoverableException.toString());
startActivityForResult(recoverableException.getIntent(), REQUEST_AUTHORIZATION);
} catch (GoogleAuthException authEx) {
Log.e("GAE", authEx.toString());
} catch (IOException ioEx) {
Log.e("IOE", ioEx.toString());
}
Map<String, String> logins = new HashMap<String, String>();
logins.put("accounts.google.com", accessToken);
credentialsProvider.setLogins(logins);
Log.i("everything set", accessToken.toString() + " cognito " + cognitoID.toString());
credentialsProvider.withLogins(logins);
credentialsProvider.refresh();
Log.i("logins", credentialsProvider.getLogins().toString());
return null;
}
}
AWS 開発者コンソールでのセットアップなのか、それともコードなのかはわかりません。
これは、ID プールのロール ポリシーです。
{
"Version": "2012-10-17",
"Statement": [{
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Effect": "Allow",
"Resource": [
"*"
]
}]
}
エラーは次のとおりです。
アンドロイド:
03-03 22:41:33.106 1970-2366/com.brillada.comicsareus E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #2
Process: com.brillada.comicsareus, PID: 1970
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:300)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
Caused by: com.amazonaws.services.cognitoidentity.model.NotAuthorizedException: Invalid login token. (Service: AmazonCognitoIdentity; Status Code: 400; Error Code: NotAuthorizedException; Request ID: 5a30d834-c220-11e4-8aed-791c85399196)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:818)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:437)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:243)
at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.invoke(AmazonCognitoIdentityClient.java:1079)
at com.amazonaws.services.cognitoidentity.AmazonCognitoIdentityClient.getCredentialsForIdentity(AmazonCognitoIdentityClient.java:499)
at com.amazonaws.auth.CognitoCredentialsProvider.populateCredentialsWithCognito(CognitoCredentialsProvider.java:622)
at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:549)
at com.amazonaws.auth.CognitoCredentialsProvider.refresh(CognitoCredentialsProvider.java:499)
at com.amazonaws.auth.CognitoCachingCredentialsProvider.getIdentityId(CognitoCachingCredentialsProvider.java:418)
at com.amazonaws.auth.CognitoCredentialsProvider.populateCredentialsWithCognito(CognitoCredentialsProvider.java:615)
at com.amazonaws.auth.CognitoCredentialsProvider.startSession(CognitoCredentialsProvider.java:549)
at com.amazonaws.auth.CognitoCredentialsProvider.refresh(CognitoCredentialsProvider.java:499)
at com.brillada.comicsareus.MainActivity$cognitoID.doInBackground(MainActivity.java:408)
at com.brillada.comicsareus.MainActivity$cognitoID.doInBackground(MainActivity.java:352)
at android.os.AsyncTask$2.call(AsyncTask.java:288)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
何かが足りないと確信していますが、エラーのトラブルシューティングを開始する場所さえ見つかりません。