jaredhanson/passport-oauth2 — pull request #6 by suprememoocow (2013-12-06 12:34:35+00:00)
Title: Additional error checks for certain errors on exchange

We have experienced some problems with GitHub OAuth during the exchange process where:

The provider:
* Returns a 200 status code
* Does not return accessToken/refreshTokens
* The params contains an error message.

For example, when an invalid or used code is used for token exchange:
`curl -X POST -i https://github.com/login/oauth/access_token -F client_id=xxxx -F client_secret=xxxx -F code=1234567890 -F redirect_uri=xxxx`
(replace, the xxxx's with appropriate values of course)

GitHub will return:
```
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Server: GitHub.com
Date: Fri, 06 Dec 2013 12:30:05 GMT
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Status: 200 OK
Cache-Control: private, max-age=0, must-revalidate
Strict-Transport-Security: max-age=2592000
X-Frame-Options: deny
Content-Length: 27
Vary: Accept-Encoding

error=bad_verification_code
```
At the moment, this situation is treated as a success (access_code=undefined).

This change allows `passport-oauth2` to spot the error and fail accordingly. I would prefer to keep this in the `passport-github` module, but the strategy does not allow it to be handled at that level as far as I can see.