I got the google cloud endpoints working with an android app and backend written in python app engine. When I uninstalled and re-installed my app during development, I started running into a 401 error from the backend. This is without any changes in backend after I got it to work the first time. So,
I cleaned up debug.keystore file in C:\Users\username\.android and also other files in the same directory.Regenerated the debug.keystore file again and got the new sha1 footprint
Deleted the API project in google apps console and regenerated web client_id & android client_id with new sha1 footprint
Used the new web client_id and android client_id in server side code
Also updated the android cliend_id in audience scope in android code
After I installed the app now, still see the same 401 error. My app engine logs show this,
I 2013-04-07 16:45:27.297 Checking for id_token.
W 2013-04-07 16:45:27.299 id_token verification failed: Invalid token signature: eyJhbGciOiJSUzI1NiIsImtpZCI6IjMzMTJkNDc0ZWUzNWRjNWU4YzFhMDE4OTkzOGZkN2E3YmUzYmRlZjYifQ.eyJpc3Mi
I 2013-04-07 16:45:27.299 Checking for oauth token.
I was able to gather more information based on Cloud endpoints oauth2 error and http://android-developers.blogspot.com/2013/01/verifying-back-end-calls-from-android.html,
I decoded the id_token being sent to the app_engine server and found that it has these fields,
cid = Android app client_id that I registered in app console for
azp = Android app client_id
aud = web client_id for App engine
iss = accounts.google.com
verified_email = true
email_verified = true
email = account i selected in account picker in android app
exp = a datetime having a value in the future
first_segment = {u'alg': u'RS256', u'kid': u'3312d474ee35dc5e8c1a0189938fd7a7be3bdef6'}
Above values seem right, but id_verification fails. Not sure why.
Had the issue again. Happens, when I reinstall my app after uninstalling. Cloudend points service threw invalid token error. Used the token and verified it using the url. Get an output like below which means the token is valid.
"issuer": "accounts.google.com",
"issued_to": "172895167251-1prp5r093hf2nro5bei2cmc1tqf4aasdu.apps.googleusercontent.com",
"audience": "172895167251.apps.googleusercontent.com",
"user_id": "myuserid",
"expires_in": 3086,
"issued_at": 1365644284,
"email": "emailIselectedinadroidapp",
"verified_email": true