bnoguchi/everyauth — Issue #159: Google OAuth: Invalid token
Author: christophlsa
Created: 2012-01-17 22:28:46+00:00
State: open

The user @rahulkgupta posted in issue #16 (I get the same error):

>Hi I'm currently receiving an error using google Oauth running the example on my localhost.
>
>```
>starting step - getAuthUri
>...finished step
>starting step - requestAuthUri
>...finished step
>starting step - getCode
>...finished step
>starting step - getAccessToken
>...finished step
>starting step - fetchOAuthUser
>
>/home/rahulgupta/Pektus1/node_modules/everyauth/lib/modules/google.js:47
> return new Error(data.data.match(/H1>(.+)<\/H1/)[1]);
> ^
>TypeError: Cannot call method 'match' of undefined
> at /home/rahulgupta/Pektus1/node_modules/everyauth/lib/modules/google.js:47:32
> at /home/rahulgupta/Pektus1/node_modules/everyauth/lib/step.js:98:21
> at [object Object].fail (/home/rahulgupta/Pektus1/node_modules/everyauth/lib/promise.js:53:24)
> at EventEmitter. (/home/rahulgupta/Pektus1/node_modules/everyauth/lib/modules/google.js:57:15)
> at EventEmitter.emit (events.js:88:20)
> at EventEmitter._respond (/home/rahulgupta/Pektus1/node_modules/everyauth/node_modules/restler/lib/restler.js:155:12)
> at EventEmitter._fireEvents (/home/rahulgupta/Pektus1/node_modules/everyauth/node_modules/restler/lib/restler.js:159:52)
> at /home/rahulgupta/Pektus1/node_modules/everyauth/node_modules/restler/lib/restler.js:124:18
> at IncomingMessage. (/home/rahulgupta/Pektus1/node_modules/everyauth/node_modules/restler/lib/restler.js:238:5)
> at IncomingMessage. (/home/rahulgupta/Pektus1/node_modules/everyauth/node_modules/restler/lib/restler.js:230:49)
>```
>
>Here is the various npm info. Node is at v0.6.7
>
>[...]
>
>When I click the "g" button, it takes me to the http://localhost:3000/auth/google/callback?code=blah page.
>```

I fixed this by replacing lines 46-48 of "lib/modules/google.js" with:

```javascript
.convertErr( function (data) {
if (data.data)
return new Error(data.data.match(/H1>(.+)<\/H1/)[1]);
else
return new Error(data.error.message);
})
```
an now I get this error:

```
starting step - getAuthUri
...finished step
starting step - requestAuthUri
...finished step
starting step - getCode
...finished step
starting step - getAccessToken
...finished step
starting step - fetchOAuthUser

/home/chris/AeroFS/nodejs/everyauth/lib/modules/everymodule.js:352
throw err;
^
Error: invalid token
at /home/chris/AeroFS/nodejs/everyauth/lib/modules/google.js:50:13
at /home/chris/AeroFS/nodejs/everyauth/lib/step.js:98:21
at [object Object].fail (/home/chris/AeroFS/nodejs/everyauth/lib/promise.js:53:24)
at EventEmitter. (/home/chris/AeroFS/nodejs/everyauth/lib/modules/google.js:60:15)
at EventEmitter.emit (events.js:88:20)
at EventEmitter._respond (/home/chris/AeroFS/nodejs/everyauth/node_modules/restler/lib/restler.js:155:12)
at EventEmitter._fireEvents (/home/chris/AeroFS/nodejs/everyauth/node_modules/restler/lib/restler.js:159:52)
at /home/chris/AeroFS/nodejs/everyauth/node_modules/restler/lib/restler.js:124:18
at IncomingMessage. (/home/chris/AeroFS/nodejs/everyauth/node_modules/restler/lib/restler.js:238:5)
at IncomingMessage. (/home/chris/AeroFS/nodejs/everyauth/node_modules/restler/lib/restler.js:230:49)
```

If I look for the error message "invalid token" I find many errors with wrong encoding of tokens generated by Google, e.g.: https://groups.google.com/forum/#!msg/oauth2-dev/5JPc-1Fy-LE/5XC3s5YxoZQJ

Any ideas?