From 1db2d98fdfd5428c49f79647e0f31809b686ca78 Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Sat, 3 Oct 2015 12:00:07 +0300 Subject: [PATCH] General improvements --- README.md | 17 +++++++++++++++-- package.json | 8 ++++---- src/index.js | 23 ++++++++++------------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ab02abf..f8c78b0 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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, @@ -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= +``` ## Issues diff --git a/package.json b/package.json index c2b9715..6246fa7 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -25,6 +25,9 @@ "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", @@ -32,8 +35,5 @@ "istanbul": "0.3.21", "mocha": "2.3.3", "sinon": "1.17.1" - }, - "dependencies": { - "passport-oauth": "1.0.0" } } diff --git a/src/index.js b/src/index.js index bc5f6b8..0e26e9a 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { @@ -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); }