Android Google Auth how to recover/refresh user token when app removed from Google account setting(Setting->Security->Manage third-party access)?-ThrowExceptions

Exception or error:

I have implemented google login inside app, so far login is working well.

The problem is that suppose i have logged in my app and then i closed app and go to Google and go to Settings -> Security -> Manager third-party access -> MY_APP_NAME and then there is button which says “REMOVE ACCESS” which removes access to google account to my app and all logins will become invalid. but now whenever i call GoogleAuthUtil.getToken(context, account, DriveScopes.DRIVE) this method first time throws exception UserRecoverableAuthException(with help of this exception user can grant permission again) but now problem is that i think this exception is only thrown one time suppose if user again “REMOVE ACCESS”(by above process again) then if we call getToken then it won’t throws that exception again and returns token but if i use this token for Google Drive then google drive says 401 Unauthorized.
{
"code": 401,
"errors": [
{
"domain": "global",
"location": "Authorization",
"locationType": "header",
"message": "Invalid Credentials",
"reason": "authError"
}
],
"message": "Invalid Credentials"
}

So what would be best way to handle REMOVE ACCESS, is handling it with UserRecoverableAuthException or there is other way to handle it ?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *