vendredi 6 mars 2015

Issues with Amazon Cognito and Android SDK NotAuthorizedException: Invalid login token.

I am currently unable to authorize with google+ with the Amazon SDK. I can get both a Cognito ID and a Google+ Token, and in my identity pool I can see an unauthenticated user. In my Cognito setup I have set the server to the right service clientID.


Here's my code:


public class cognitoID extends AsyncTask{



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

}


} I'm not sure if its my setup on the AWS Developer Console, or whether its the code.


This is the role policy for the identity pools:


{ "Version": "2012-10-17", "Statement": [{ "Action": [ "mobileanalytics:PutEvents", "cognito-sync:" ], "Effect": "Allow", "Resource": [ "" ] }] }


Here are the errors:


Android:


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)


I'm sure I'm missing something, but I can't even find where to start troubleshooting the error.





Aucun commentaire:

Enregistrer un commentaire