How to use Cognito identity pool with UnAuthenticatd users in Amplify for Android

Question:

I’ve been going through the AWS Amplify docs and tutorials for how to use Amplify and Cognito identity pools together with UNauthenticated users. The example given by the Amplify docs is:

But in practice when I use this code – I get an error printed out in LogCat:

Note: I did configure AWS Cognito to support Unauthenticaed users!

I’ve also looked everywhere for the Amplify Android API doc to see what other APIs are supported – couldn’t find any Android API docs.
And looking into the AWS Amplify.Auth methods i could not find ANY function that deals with unauthenticated users

Question:

Any clue how can i use Amplify (Android) and have AWS credentials via AWS Cognito for unauthenticated users ???

Answer:

This is David from the Amplify Android team. I was actually just looking into this the other day and currently there’s a hack that’s required to make unauth users work.

After setting up unauth/guest users through the CLI (as you mentioned you had) you have to call the getAWSCredentials method on the underlying escape hatch once for the app to get it to work.

Here’s a code snippet I’d written that you can run after Amplify.configure (and again, this only needs to be run once per app install):

I’m working on a solution to avoid this hack right now and adding a documentation section on Unauth users to our site but in the meantime this should get it working for you.

Again note you only have to do this once and from then on out, it should just work when you call fetchAuthSession.

UPDATE: The non patched (official) version:

Leave a Reply