3
votes

I'm having issues with Google OAuth2 in iOS; I'm getting an "invalid_grant" error. I am doing the following steps:

  1. I created the project and Credential ( iOS app ) Google Console;
  2. I did request the CODE;
  3. I did request the access token (working well);
  4. 10 minutes before the expiry of the access token , I do request a refresh token.

The problem is intermittent . Sometimes the request for refresh ( refresh_token ) returns " invalid_grant " and so the access_token becomes invalid and my application just stops .

If forcing the user login to generate a new access_token and refresh_token not work. I have to revoke the permissions of the account and try again.   What I need is access to IMAP and SMTP Gmail . If I check the access_token ( https://www.googleapis.com/oauth2/v1/tokeninfo ) is active and valid , but the IMAP and SMTP denies access.

I'm actually thinking of going back to the login username and password . The service is very unstable for not having the same reaction . I'm sure I'm not bursting any limitations and been the message " invalid_grant " would at least not appropriate.

Please , any employee of Google, HELP ME !

Thank you.

1
I have also faced the same problem in my app , try this: stackoverflow.com/questions/21873323/… - Rahul Mathur
afaik, may be u need to sync epoch maintained by google APIs; I once been through such case. - bhavesh369

1 Answers

0
votes

I was facing this problem as well. I wasn't doing anything with IMAP, but I was getting an invalid_grant pretty frequently when trying to handle auth. Eventually I got things working using the following settings:

authentication.refreshToken = savedRefreshToken;
authentication.accessToken = savedAccessToken;
authentication.additionalTokenRequestParameters = @{@"access_type":@"offline"};

I think it was mainly that last one that did the trick. I found it somewhere in the Google documentation, but I didn't save where. Their docs are pretty messy.