Skip to content

Commit

Permalink
General improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaiklor committed Oct 3, 2015
1 parent 45ff057 commit 1db2d98
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# passport-github-token

![Build Status](https://img.shields.io/travis/ghaiklor/passport-github-token.svg) ![Coverage](https://img.shields.io/coveralls/ghaiklor/passport-github-token.svg) ![Downloads](https://img.shields.io/npm/dm/passport-github-token.svg) ![npm version](https://img.shields.io/npm/v/passport-github-token.svg) ![dependencies](https://img.shields.io/david/ghaiklor/passport-github-token.svg) ![dev dependencies](https://img.shields.io/david/dev/ghaiklor/passport-github-token.svg) ![License](https://img.shields.io/npm/l/passport-github-token.svg)
![Build Status](https://img.shields.io/travis/ghaiklor/passport-github-token.svg)
![Coverage](https://img.shields.io/coveralls/ghaiklor/passport-github-token.svg)
![Downloads](https://img.shields.io/npm/dm/passport-github-token.svg)
![Downloads](https://img.shields.io/npm/dt/passport-github-token.svg)
![npm version](https://img.shields.io/npm/v/passport-github-token.svg)
![dependencies](https://img.shields.io/david/ghaiklor/passport-github-token.svg)
![dev dependencies](https://img.shields.io/david/dev/ghaiklor/passport-github-token.svg)
![License](https://img.shields.io/npm/l/passport-github-token.svg)

[Passport](http://passportjs.org/) strategy for authenticating with GitHub access tokens using the OAuth 2.0 API.

Expand All @@ -21,6 +28,8 @@ The GitHub authentication strategy authenticates users using a GitHub account an
The strategy requires a `verify` callback, which accepts these credentials and calls `next` providing a user, as well as `options` specifying a app ID and app secret.

```javascript
var GitHubTokenStrategy = require('passport-github-token');

passport.use(new GitHubTokenStrategy({
clientID: GITHUB_CLIENT_ID,
clientSecret: GITHUB_CLIENT_SECRET,
Expand Down Expand Up @@ -57,7 +66,11 @@ module.exports = {
};
```

The POST request to this route should include a JSON object with the keys `access_token` and optionally, `refresh_token` set to the credentials you receive from GitHub.
The request to this route should include a GET or POST data with the keys `access_token` and optionally, `refresh_token` set to the credentials you receive from GitHub.

```
GET /auth/github?access_token=<TOKEN>
```

## Issues

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "passport-github-token",
"version": "2.0.0",
"version": "2.0.1",
"description": "Passport strategy for authenticating with GitHub via OAuth2 access tokens",
"main": "lib/index.js",
"scripts": {
Expand All @@ -25,15 +25,15 @@
"url": "https://github.com/ghaiklor/passport-github-token/issues"
},
"homepage": "https://github.com/ghaiklor/passport-github-token",
"dependencies": {
"passport-oauth": "1.0.0"
},
"devDependencies": {
"babel": "5.8.23",
"chai": "2.3.0",
"chai-passport-strategy": "0.2.0",
"istanbul": "0.3.21",
"mocha": "2.3.3",
"sinon": "1.17.1"
},
"dependencies": {
"passport-oauth": "1.0.0"
}
}
23 changes: 10 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ import { OAuth2Strategy, InternalOAuthError } from 'passport-oauth';
* - clientSecret Secret used to establish ownership of the consumer key
* - passReqToCallback If need, pass req to verify callback
*
* Example:
* passport.use(new GitHubTokenStrategy({
* clientID: '123-456-789',
* clientSecret: 'shhh-its-a-secret',
* passReqToCallback: true
* }, function(req, accessToken, refreshToken, profile, next) {
* User.findOrCreate(..., function (error, user) {
* next(error, user);
* });
* }
* ));
*
* @param {Object} _options
* @param {Function} _verify
* @constructor
* @example
* passport.use(new GitHubTokenStrategy({
* clientID: '123456789',
* clientSecret: 'shhh-its-a-secret'
* }), function(accessToken, refreshToken, profile, next) {
* User.findOrCreate({githubId: profile.id}, function(error, user) {
* next(error, user);
* })
* })
*/
export default class GitHubTokenStrategy extends OAuth2Strategy {
constructor(_options, _verify) {
Expand All @@ -43,6 +39,7 @@ export default class GitHubTokenStrategy extends OAuth2Strategy {
this._refreshTokenField = options.refreshTokenField || 'refresh_token';
this._profileURL = options.profileURL || 'https://api.github.com/user';
this._passReqToCallback = options.passReqToCallback;

this._oauth2.useAuthorizationHeaderforGET(true);
}

Expand Down

0 comments on commit 1db2d98

Please sign in to comment.