ejci / Google-Auth-for-Titanium

Google Auth for Titanium
GNU General Public License v2.0
66 stars 28 forks source link

refreshToken() does not work #9

Open quochuy opened 9 years ago

quochuy commented 9 years ago

The fix is at line 24 add: refreshUrl: 'https://www.googleapis.com/oauth2/v3/token',

Then at line 259 change: xhr.open("POST", _opt.url);

to: xhr.open("POST", _opt.refreshUrl);

ejci commented 9 years ago

Can you describe in details whats not working?

quochuy commented 9 years ago

The first time you auth, it's OK, you get the access token and can access the API. But when the token expires, you should be able to request a token refresh but instead the script failed with an HTTP error (bad request) and it then redo the auth thing where it opens a webview and ask your permission.

The problem was that your refreshToken function is posting the request to the wrong URL. https://accounts.google.com/o/oauth2/auth should be use for first time authentication. For token refresh it should be https://www.googleapis.com/oauth2/v3/token as per: https://developers.google.com/identity/protocols/OAuth2WebServer#refresh

And I've applied this to my copy of the file and it works

ejci commented 9 years ago

Thanks for explanation! I will update the code.