mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Added node-modules
This commit is contained in:
5
node_modules/passport-google-oauth/.travis.yml
generated
vendored
Normal file
5
node_modules/passport-google-oauth/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
language: "node_js"
|
||||
node_js:
|
||||
- 0.4
|
||||
- 0.6
|
||||
- 0.8
|
20
node_modules/passport-google-oauth/LICENSE
generated
vendored
Normal file
20
node_modules/passport-google-oauth/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012-2013 Jared Hanson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
114
node_modules/passport-google-oauth/README.md
generated
vendored
Normal file
114
node_modules/passport-google-oauth/README.md
generated
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
# Passport-Google-OAuth
|
||||
|
||||
[Passport](http://passportjs.org/) strategies for authenticating with [Google](http://www.google.com/)
|
||||
using OAuth 1.0a and OAuth 2.0.
|
||||
|
||||
This module lets you authenticate using Google in your Node.js applications.
|
||||
By plugging into Passport, Google authentication can be easily and
|
||||
unobtrusively integrated into any application or framework that supports
|
||||
[Connect](http://www.senchalabs.org/connect/)-style middleware, including
|
||||
[Express](http://expressjs.com/).
|
||||
|
||||
## Install
|
||||
|
||||
$ npm install passport-google-oauth
|
||||
|
||||
## Usage of OAuth 1.0
|
||||
|
||||
#### Configure Strategy
|
||||
|
||||
The Google OAuth 1.0 authentication strategy authenticates users using a Google
|
||||
account and OAuth tokens. The strategy requires a `verify` callback, which
|
||||
accepts these credentials and calls `done` providing a user, as well as `options`
|
||||
specifying a consumer key, consumer secret, and callback URL.
|
||||
|
||||
passport.use(new GoogleStrategy({
|
||||
consumerKey: GOOGLE_CONSUMER_KEY,
|
||||
consumerSecret: GOOGLE_CONSUMER_SECRET,
|
||||
callbackURL: "http://127.0.0.1:3000/auth/google/callback"
|
||||
},
|
||||
function(token, tokenSecret, profile, done) {
|
||||
User.findOrCreate({ googleId: profile.id }, function (err, user) {
|
||||
return done(err, user);
|
||||
});
|
||||
}
|
||||
));
|
||||
|
||||
#### Authenticate Requests
|
||||
|
||||
Use `passport.authenticate()`, specifying the `'google'` strategy, to
|
||||
authenticate requests.
|
||||
|
||||
For example, as route middleware in an [Express](http://expressjs.com/)
|
||||
application:
|
||||
|
||||
app.get('/auth/google',
|
||||
passport.authenticate('google', { scope: 'https://www.google.com/m8/feeds' }));
|
||||
|
||||
app.get('/auth/google/callback',
|
||||
passport.authenticate('google', { failureRedirect: '/login' }),
|
||||
function(req, res) {
|
||||
// Successful authentication, redirect home.
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
## Usage of OAuth 2.0
|
||||
|
||||
#### Configure Strategy
|
||||
|
||||
The Google OAuth 2.0 authentication strategy authenticates users using a Google
|
||||
account and OAuth 2.0 tokens. The strategy requires a `verify` callback, which
|
||||
accepts these credentials and calls `done` providing a user, as well as
|
||||
`options` specifying a client ID, client secret, and callback URL.
|
||||
|
||||
passport.use(new GoogleStrategy({
|
||||
clientID: GOOGLE_CLIENT_ID,
|
||||
clientSecret: GOOGLE_CLIENT_SECRET,
|
||||
callbackURL: "http://127.0.0.1:3000/auth/google/callback"
|
||||
},
|
||||
function(accessToken, refreshToken, profile, done) {
|
||||
User.findOrCreate({ googleId: profile.id }, function (err, user) {
|
||||
return done(err, user);
|
||||
});
|
||||
}
|
||||
));
|
||||
|
||||
#### Authenticate Requests
|
||||
|
||||
Use `passport.authenticate()`, specifying the `'google'` strategy, to
|
||||
authenticate requests.
|
||||
|
||||
For example, as route middleware in an [Express](http://expressjs.com/)
|
||||
application:
|
||||
|
||||
app.get('/auth/google',
|
||||
passport.authenticate('google'));
|
||||
|
||||
app.get('/auth/google/callback',
|
||||
passport.authenticate('google', { failureRedirect: '/login' }),
|
||||
function(req, res) {
|
||||
// Successful authentication, redirect home.
|
||||
res.redirect('/');
|
||||
});
|
||||
|
||||
## Examples
|
||||
|
||||
For a complete, working example, refer to the [OAuth 1.0 example](https://github.com/jaredhanson/passport-google-oauth/tree/master/examples/oauth)
|
||||
and the [OAuth 2.0 example](https://github.com/jaredhanson/passport-google-oauth/tree/master/examples/oauth2).
|
||||
|
||||
## Tests
|
||||
|
||||
$ npm install --dev
|
||||
$ make test
|
||||
|
||||
[](http://travis-ci.org/jaredhanson/passport-google-oauth)
|
||||
|
||||
## Credits
|
||||
|
||||
- [Jared Hanson](http://github.com/jaredhanson)
|
||||
|
||||
## License
|
||||
|
||||
[The MIT License](http://opensource.org/licenses/MIT)
|
||||
|
||||
Copyright (c) 2012-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>
|
18
node_modules/passport-google-oauth/lib/passport-google-oauth/index.js
generated
vendored
Normal file
18
node_modules/passport-google-oauth/lib/passport-google-oauth/index.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var OAuthStrategy = require('./oauth');
|
||||
var OAuth2Strategy = require('./oauth2');
|
||||
|
||||
|
||||
/**
|
||||
* Framework version.
|
||||
*/
|
||||
require('pkginfo')(module, 'version');
|
||||
|
||||
/**
|
||||
* Expose constructors.
|
||||
*/
|
||||
exports.Strategy =
|
||||
exports.OAuthStrategy = OAuthStrategy;
|
||||
exports.OAuth2Strategy = OAuth2Strategy;
|
118
node_modules/passport-google-oauth/lib/passport-google-oauth/oauth.js
generated
vendored
Normal file
118
node_modules/passport-google-oauth/lib/passport-google-oauth/oauth.js
generated
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var util = require('util')
|
||||
, OAuthStrategy = require('passport-oauth').OAuthStrategy
|
||||
, InternalOAuthError = require('passport-oauth').InternalOAuthError;
|
||||
|
||||
|
||||
/**
|
||||
* `Strategy` constructor.
|
||||
*
|
||||
* The Google authentication strategy authenticates requests by delegating to
|
||||
* Google using the OAuth protocol.
|
||||
*
|
||||
* Applications must supply a `verify` callback which accepts a `token`,
|
||||
* `tokenSecret` and service-specific `profile`, and then calls the `done`
|
||||
* callback supplying a `user`, which should be set to `false` if the
|
||||
* credentials are not valid. If an exception occured, `err` should be set.
|
||||
*
|
||||
* Options:
|
||||
* - `consumerKey` identifies client to Google
|
||||
* - `consumerSecret` secret used to establish ownership of the consumer key
|
||||
* - `callbackURL` URL to which Google will redirect the user after obtaining authorization
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* passport.use(new GoogleStrategy({
|
||||
* consumerKey: '123-456-789',
|
||||
* consumerSecret: 'shhh-its-a-secret'
|
||||
* callbackURL: 'https://www.example.net/auth/google/callback'
|
||||
* },
|
||||
* function(token, tokenSecret, profile, done) {
|
||||
* User.findOrCreate(..., function (err, user) {
|
||||
* done(err, user);
|
||||
* });
|
||||
* }
|
||||
* ));
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} verify
|
||||
* @api public
|
||||
*/
|
||||
function Strategy(options, verify) {
|
||||
options = options || {};
|
||||
options.requestTokenURL = options.requestTokenURL || 'https://www.google.com/accounts/OAuthGetRequestToken';
|
||||
options.accessTokenURL = options.accessTokenURL || 'https://www.google.com/accounts/OAuthGetAccessToken';
|
||||
options.userAuthorizationURL = options.userAuthorizationURL || 'https://www.google.com/accounts/OAuthAuthorizeToken';
|
||||
options.sessionKey = options.sessionKey || 'oauth:google';
|
||||
|
||||
OAuthStrategy.call(this, options, verify);
|
||||
this.name = 'google';
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `OAuthStrategy`.
|
||||
*/
|
||||
util.inherits(Strategy, OAuthStrategy);
|
||||
|
||||
/**
|
||||
* Retrieve user profile from Google.
|
||||
*
|
||||
* This function constructs a normalized profile, with the following properties:
|
||||
*
|
||||
* - `id`
|
||||
* - `displayName`
|
||||
*
|
||||
* @param {String} token
|
||||
* @param {String} tokenSecret
|
||||
* @param {Object} params
|
||||
* @param {Function} done
|
||||
* @api protected
|
||||
*/
|
||||
Strategy.prototype.userProfile = function(token, tokenSecret, params, done) {
|
||||
this._oauth.get('https://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json', token, tokenSecret, function (err, body, res) {
|
||||
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
|
||||
|
||||
try {
|
||||
var json = JSON.parse(body);
|
||||
|
||||
var profile = { provider: 'google' };
|
||||
profile.id = json.feed.id['$t']
|
||||
profile.displayName = json.feed.author[0].name['$t'];
|
||||
profile.emails = [{ value: json.feed.author[0].email['$t'] }];
|
||||
|
||||
profile._raw = body;
|
||||
profile._json = json;
|
||||
|
||||
done(null, profile);
|
||||
} catch(e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extra Google-specific parameters to be included in the request token
|
||||
* request.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Object}
|
||||
* @api protected
|
||||
*/
|
||||
Strategy.prototype.requestTokenParams = function(options) {
|
||||
var params = options || {};
|
||||
|
||||
var scope = options.scope;
|
||||
if (scope) {
|
||||
if (Array.isArray(scope)) { scope = scope.join(' '); }
|
||||
params['scope'] = scope;
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expose `Strategy`.
|
||||
*/
|
||||
module.exports = Strategy;
|
144
node_modules/passport-google-oauth/lib/passport-google-oauth/oauth2.js
generated
vendored
Normal file
144
node_modules/passport-google-oauth/lib/passport-google-oauth/oauth2.js
generated
vendored
Normal file
@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var util = require('util')
|
||||
, OAuth2Strategy = require('passport-oauth').OAuth2Strategy
|
||||
, InternalOAuthError = require('passport-oauth').InternalOAuthError;
|
||||
|
||||
|
||||
/**
|
||||
* `Strategy` constructor.
|
||||
*
|
||||
* The Google authentication strategy authenticates requests by delegating to
|
||||
* Google using the OAuth 2.0 protocol.
|
||||
*
|
||||
* Applications must supply a `verify` callback which accepts an `accessToken`,
|
||||
* `refreshToken` and service-specific `profile`, and then calls the `done`
|
||||
* callback supplying a `user`, which should be set to `false` if the
|
||||
* credentials are not valid. If an exception occured, `err` should be set.
|
||||
*
|
||||
* Options:
|
||||
* - `clientID` your Google application's client id
|
||||
* - `clientSecret` your Google application's client secret
|
||||
* - `callbackURL` URL to which Google will redirect the user after granting authorization
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* passport.use(new GoogleStrategy({
|
||||
* clientID: '123-456-789',
|
||||
* clientSecret: 'shhh-its-a-secret'
|
||||
* callbackURL: 'https://www.example.net/auth/google/callback'
|
||||
* },
|
||||
* function(accessToken, refreshToken, profile, done) {
|
||||
* User.findOrCreate(..., function (err, user) {
|
||||
* done(err, user);
|
||||
* });
|
||||
* }
|
||||
* ));
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} verify
|
||||
* @api public
|
||||
*/
|
||||
function Strategy(options, verify) {
|
||||
options = options || {};
|
||||
options.authorizationURL = options.authorizationURL || 'https://accounts.google.com/o/oauth2/auth';
|
||||
options.tokenURL = options.tokenURL || 'https://accounts.google.com/o/oauth2/token';
|
||||
|
||||
OAuth2Strategy.call(this, options, verify);
|
||||
this.name = 'google';
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `OAuth2Strategy`.
|
||||
*/
|
||||
util.inherits(Strategy, OAuth2Strategy);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve user profile from Google.
|
||||
*
|
||||
* This function constructs a normalized profile, with the following properties:
|
||||
*
|
||||
* - `provider` always set to `google`
|
||||
* - `id`
|
||||
* - `username`
|
||||
* - `displayName`
|
||||
*
|
||||
* @param {String} accessToken
|
||||
* @param {Function} done
|
||||
* @api protected
|
||||
*/
|
||||
Strategy.prototype.userProfile = function(accessToken, done) {
|
||||
this._oauth2.get('https://www.googleapis.com/oauth2/v1/userinfo', accessToken, function (err, body, res) {
|
||||
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
|
||||
|
||||
try {
|
||||
var json = JSON.parse(body);
|
||||
|
||||
var profile = { provider: 'google' };
|
||||
profile.id = json.id;
|
||||
profile.displayName = json.name;
|
||||
profile.name = { familyName: json.family_name,
|
||||
givenName: json.given_name };
|
||||
profile.emails = [{ value: json.email }];
|
||||
|
||||
profile._raw = body;
|
||||
profile._json = json;
|
||||
|
||||
done(null, profile);
|
||||
} catch(e) {
|
||||
done(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extra Google-specific parameters to be included in the authorization
|
||||
* request.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Object}
|
||||
* @api protected
|
||||
*/
|
||||
Strategy.prototype.authorizationParams = function(options) {
|
||||
var params = {};
|
||||
if (options.accessType) {
|
||||
params['access_type'] = options.accessType;
|
||||
}
|
||||
if (options.approvalPrompt) {
|
||||
params['approval_prompt'] = options.approvalPrompt;
|
||||
}
|
||||
if (options.prompt) {
|
||||
// This parameter is undocumented in Google's official documentation.
|
||||
// However, it was detailed by Breno de Medeiros (who works at Google) in
|
||||
// this Stack Overflow answer:
|
||||
// http://stackoverflow.com/questions/14384354/force-google-account-chooser/14393492#14393492
|
||||
params['prompt'] = options.prompt;
|
||||
}
|
||||
if (options.loginHint) {
|
||||
// This parameter is derived from OpenID Connect, and supported by Google's
|
||||
// OAuth 2.0 endpoint.
|
||||
// https://github.com/jaredhanson/passport-google-oauth/pull/8
|
||||
// https://bitbucket.org/openid/connect/commits/970a95b83add
|
||||
params['login_hint'] = options.loginHint;
|
||||
}
|
||||
if (options.userID) {
|
||||
// Undocumented, but supported by Google's OAuth 2.0 endpoint. Appears to
|
||||
// be equivalent to `login_hint`.
|
||||
params['user_id'] = options.userID;
|
||||
}
|
||||
if (options.hostedDomain || options.hd) {
|
||||
// This parameter is derived from Google's OAuth 1.0 endpoint, and (although
|
||||
// undocumented) is supported by Google's OAuth 2.0 endpoint was well.
|
||||
// https://developers.google.com/accounts/docs/OAuth_ref
|
||||
params['hd'] = options.hostedDomain || options.hd;
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expose `Strategy`.
|
||||
*/
|
||||
module.exports = Strategy;
|
5
node_modules/passport-google-oauth/node_modules/passport-oauth/.travis.yml
generated
vendored
Normal file
5
node_modules/passport-google-oauth/node_modules/passport-oauth/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
language: "node_js"
|
||||
node_js:
|
||||
- 0.4
|
||||
- 0.6
|
||||
- 0.8
|
20
node_modules/passport-google-oauth/node_modules/passport-oauth/LICENSE
generated
vendored
Normal file
20
node_modules/passport-google-oauth/node_modules/passport-oauth/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2011-2013 Jared Hanson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
89
node_modules/passport-google-oauth/node_modules/passport-oauth/README.md
generated
vendored
Normal file
89
node_modules/passport-google-oauth/node_modules/passport-oauth/README.md
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
# Passport-OAuth
|
||||
|
||||
General-purpose OAuth 1.0 and OAuth 2.0 authentication strategies for [Passport](https://github.com/jaredhanson/passport).
|
||||
|
||||
This module lets you authenticate using OAuth in your Node.js applications.
|
||||
By plugging into Passport, OAuth authentication can be easily and unobtrusively
|
||||
integrated into any application or framework that supports
|
||||
[Connect](http://www.senchalabs.org/connect/)-style middleware, including
|
||||
[Express](http://expressjs.com/).
|
||||
|
||||
Note that this strategy provides generic OAuth support. In many cases, a
|
||||
provider-specific strategy can be used instead, which cuts down on unnecessary
|
||||
configuration, and accommodates any provider-specific quirks. See the list
|
||||
below for supported providers.
|
||||
|
||||
Developers who need to implement authentication against an OAuth provider that
|
||||
is not already supported are encouraged to sub-class this strategy. If you
|
||||
choose to open source the new provider-specific strategy, send me a message and
|
||||
I will update the list.
|
||||
|
||||
## Installation
|
||||
|
||||
$ npm install passport-oauth
|
||||
|
||||
## Strategies using OAuth
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr><th>Strategy</th><th>OAuth Version</th>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-37signals">37signals</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/allplayers/passport-allplayers">AllPlayers.com</a></td><td>1.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-angellist">AngelList</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-bitbucket">Bitbucket</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/rajaraodv/passport-cloudfoundry">Cloud Foundry (UAA)</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-digg">Digg</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-dropbox">Dropbox</a></td><td>1.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-dwolla">Dwolla</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-evernote">Evernote</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-facebook">Facebook</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-fitbit">Fitbit</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-flickr">Flickr</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-foursquare">Foursquare</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-geoloqi">Geoloqi</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-github">GitHub</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-goodreads">Goodreads</a></td><td>1.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-google-oauth">Google</a></td><td>1.0a, 2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-gowalla">Gowalla</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-instagram">Instagram</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-justintv">Justin.tv</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-linkedin">LinkedIn</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-meetup">Meetup</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-netflix">Netflix</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-ohloh">Ohloh</a></td><td>1.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-openstreetmap">OpenStreetMap</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-picplz">picplz</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-rdio">Rdio</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-readability">Readability</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-runkeeper">RunKeeper</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-smugmug">SmugMug</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-soundcloud">SoundCloud</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-tripit">TripIt</a></td><td>1.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-tumblr">Tumblr</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-twitter">Twitter</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-vimeo">Vimeo</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-windowslive">Windows Live</a></td><td>2.0</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-yahoo-oauth">Yahoo!</a></td><td>1.0a</td></tr>
|
||||
<tr><td><a href="https://github.com/jaredhanson/passport-yammer">Yammer</a></td><td>2.0</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
## Tests
|
||||
|
||||
$ npm install --dev
|
||||
$ make test
|
||||
|
||||
[](http://travis-ci.org/jaredhanson/passport-oauth)
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
- [Jared Hanson](http://github.com/jaredhanson)
|
||||
|
||||
## License
|
||||
|
||||
[The MIT License](http://opensource.org/licenses/MIT)
|
||||
|
||||
Copyright (c) 2011-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>
|
46
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/errors/internaloautherror.js
generated
vendored
Normal file
46
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/errors/internaloautherror.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* `InternalOAuthError` error.
|
||||
*
|
||||
* InternalOAuthError wraps errors generated by node-oauth. By wrapping these
|
||||
* objects, error messages can be formatted in a manner that aids in debugging
|
||||
* OAuth issues.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
function InternalOAuthError(message, err) {
|
||||
Error.call(this);
|
||||
Error.captureStackTrace(this, arguments.callee);
|
||||
this.name = 'InternalOAuthError';
|
||||
this.message = message;
|
||||
this.oauthError = err;
|
||||
};
|
||||
|
||||
/**
|
||||
* Inherit from `Error`.
|
||||
*/
|
||||
InternalOAuthError.prototype.__proto__ = Error.prototype;
|
||||
|
||||
/**
|
||||
* Returns a string representing the error.
|
||||
*
|
||||
* @return {String}
|
||||
* @api public
|
||||
*/
|
||||
InternalOAuthError.prototype.toString = function() {
|
||||
var m = this.message;
|
||||
if (this.oauthError) {
|
||||
if (this.oauthError instanceof Error) {
|
||||
m += ' (' + this.oauthError + ')';
|
||||
}
|
||||
else if (this.oauthError.statusCode && this.oauthError.data) {
|
||||
m += ' (status: ' + this.oauthError.statusCode + ' data: ' + this.oauthError.data + ')';
|
||||
}
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expose `InternalOAuthError`.
|
||||
*/
|
||||
module.exports = InternalOAuthError;
|
20
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/index.js
generated
vendored
Normal file
20
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/index.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var OAuthStrategy = require('./strategies/oauth');
|
||||
var OAuth2Strategy = require('./strategies/oauth2');
|
||||
var InternalOAuthError = require('./errors/internaloautherror');
|
||||
|
||||
|
||||
/**
|
||||
* Framework version.
|
||||
*/
|
||||
require('pkginfo')(module, 'version');
|
||||
|
||||
/**
|
||||
* Expose constructors.
|
||||
*/
|
||||
exports.OAuthStrategy = OAuthStrategy;
|
||||
exports.OAuth2Strategy = OAuth2Strategy;
|
||||
|
||||
exports.InternalOAuthError = InternalOAuthError;
|
300
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth.js
generated
vendored
Normal file
300
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth.js
generated
vendored
Normal file
@ -0,0 +1,300 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var passport = require('passport')
|
||||
, url = require('url')
|
||||
, util = require('util')
|
||||
, utils = require('./utils')
|
||||
, OAuth = require('oauth').OAuth
|
||||
, InternalOAuthError = require('../errors/internaloautherror');
|
||||
|
||||
|
||||
/**
|
||||
* `OAuthStrategy` constructor.
|
||||
*
|
||||
* The OAuth authentication strategy authenticates requests using the OAuth
|
||||
* protocol.
|
||||
*
|
||||
* OAuth provides a facility for delegated authentication, whereby users can
|
||||
* authenticate using a third-party service such as Twitter. Delegating in this
|
||||
* manner involves a sequence of events, including redirecting the user to the
|
||||
* third-party service for authorization. Once authorization has been obtained,
|
||||
* the user is redirected back to the application and a token can be used to
|
||||
* obtain credentials.
|
||||
*
|
||||
* Applications must supply a `verify` callback which accepts a `token`,
|
||||
* `tokenSecret` and service-specific `profile`, and then calls the `done`
|
||||
* callback supplying a `user`, which should be set to `false` if the
|
||||
* credentials are not valid. If an exception occured, `err` should be set.
|
||||
*
|
||||
* Options:
|
||||
* - `requestTokenURL` URL used to obtain an unauthorized request token
|
||||
* - `accessTokenURL` URL used to exchange a user-authorized request token for an access token
|
||||
* - `userAuthorizationURL` URL used to obtain user authorization
|
||||
* - `consumerKey` identifies client to service provider
|
||||
* - `consumerSecret` secret used to establish ownership of the consumer key
|
||||
* - `callbackURL` URL to which the service provider will redirect the user after obtaining authorization
|
||||
* - `passReqToCallback` when `true`, `req` is the first argument to the verify callback (default: `false`)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* passport.use(new OAuthStrategy({
|
||||
* requestTokenURL: 'https://www.example.com/oauth/request_token',
|
||||
* accessTokenURL: 'https://www.example.com/oauth/access_token',
|
||||
* userAuthorizationURL: 'https://www.example.com/oauth/authorize',
|
||||
* consumerKey: '123-456-789',
|
||||
* consumerSecret: 'shhh-its-a-secret'
|
||||
* callbackURL: 'https://www.example.net/auth/example/callback'
|
||||
* },
|
||||
* function(token, tokenSecret, profile, done) {
|
||||
* User.findOrCreate(..., function (err, user) {
|
||||
* done(err, user);
|
||||
* });
|
||||
* }
|
||||
* ));
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} verify
|
||||
* @api public
|
||||
*/
|
||||
function OAuthStrategy(options, verify) {
|
||||
options = options || {}
|
||||
passport.Strategy.call(this);
|
||||
this.name = 'oauth';
|
||||
this._verify = verify;
|
||||
|
||||
if (!options.requestTokenURL) throw new Error('OAuthStrategy requires a requestTokenURL option');
|
||||
if (!options.accessTokenURL) throw new Error('OAuthStrategy requires a accessTokenURL option');
|
||||
if (!options.userAuthorizationURL) throw new Error('OAuthStrategy requires a userAuthorizationURL option');
|
||||
if (!options.consumerKey) throw new Error('OAuthStrategy requires a consumerKey option');
|
||||
if (options.consumerSecret === undefined) throw new Error('OAuthStrategy requires a consumerSecret option');
|
||||
if (!verify) throw new Error('OAuth authentication strategy requires a verify function');
|
||||
|
||||
// NOTE: The _oauth property is considered "protected". Subclasses are
|
||||
// allowed to use it when making protected resource requests to retrieve
|
||||
// the user profile.
|
||||
this._oauth = new OAuth(options.requestTokenURL, options.accessTokenURL,
|
||||
options.consumerKey, options.consumerSecret,
|
||||
"1.0", null, options.signatureMethod || "HMAC-SHA1",
|
||||
null, options.customHeaders);
|
||||
|
||||
this._userAuthorizationURL = options.userAuthorizationURL;
|
||||
this._callbackURL = options.callbackURL;
|
||||
this._passReqToCallback = options.passReqToCallback;
|
||||
this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile;
|
||||
this._key = options.sessionKey || 'oauth';
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `passport.Strategy`.
|
||||
*/
|
||||
util.inherits(OAuthStrategy, passport.Strategy);
|
||||
|
||||
|
||||
/**
|
||||
* Authenticate request by delegating to a service provider using OAuth.
|
||||
*
|
||||
* @param {Object} req
|
||||
* @api protected
|
||||
*/
|
||||
OAuthStrategy.prototype.authenticate = function(req, options) {
|
||||
options = options || {};
|
||||
if (!req.session) { return this.error(new Error('OAuth authentication requires session support')); }
|
||||
|
||||
var self = this;
|
||||
|
||||
if (req.query && req.query['oauth_token']) {
|
||||
// The request being authenticated contains an oauth_token parameter in the
|
||||
// query portion of the URL. This indicates that the service provider has
|
||||
// redirected the user back to the application, after authenticating the
|
||||
// user and obtaining their authorization.
|
||||
//
|
||||
// The value of the oauth_token parameter is the request token. Together
|
||||
// with knowledge of the token secret (stored in the session), the request
|
||||
// token can be exchanged for an access token and token secret.
|
||||
//
|
||||
// This access token and token secret, along with the optional ability to
|
||||
// fetch profile information from the service provider, is sufficient to
|
||||
// establish the identity of the user.
|
||||
|
||||
// Bail if the session does not contain the request token and corresponding
|
||||
// secret. If this happens, it is most likely caused by initiating OAuth
|
||||
// from a different host than that of the callback endpoint (for example:
|
||||
// initiating from 127.0.0.1 but handling callbacks at localhost).
|
||||
if (!req.session[self._key]) { return self.error(new Error('failed to find request token in session')); }
|
||||
|
||||
var oauthToken = req.query['oauth_token'];
|
||||
var oauthVerifier = req.query['oauth_verifier'] || null;
|
||||
var oauthTokenSecret = req.session[self._key]["oauth_token_secret"];
|
||||
|
||||
// NOTE: The oauth_verifier parameter will be supplied in the query portion
|
||||
// of the redirect URL, if the server supports OAuth 1.0a.
|
||||
|
||||
this._oauth.getOAuthAccessToken(oauthToken, oauthTokenSecret, oauthVerifier, function(err, token, tokenSecret, params) {
|
||||
if (err) { return self.error(new InternalOAuthError('failed to obtain access token', err)); }
|
||||
|
||||
// The request token has been exchanged for an access token. Since the
|
||||
// request token is a single-use token, that data can be removed from the
|
||||
// session.
|
||||
delete req.session[self._key]['oauth_token'];
|
||||
delete req.session[self._key]['oauth_token_secret'];
|
||||
if (Object.keys(req.session[self._key]).length == 0) {
|
||||
delete req.session[self._key];
|
||||
}
|
||||
|
||||
self._loadUserProfile(token, tokenSecret, params, function(err, profile) {
|
||||
if (err) { return self.error(err); };
|
||||
|
||||
function verified(err, user, info) {
|
||||
if (err) { return self.error(err); }
|
||||
if (!user) { return self.fail(info); }
|
||||
self.success(user, info);
|
||||
}
|
||||
|
||||
if (self._passReqToCallback) {
|
||||
var arity = self._verify.length;
|
||||
if (arity == 6) {
|
||||
self._verify(req, token, tokenSecret, params, profile, verified);
|
||||
} else { // arity == 5
|
||||
self._verify(req, token, tokenSecret, profile, verified);
|
||||
}
|
||||
} else {
|
||||
var arity = self._verify.length;
|
||||
if (arity == 5) {
|
||||
self._verify(token, tokenSecret, params, profile, verified);
|
||||
} else { // arity == 4
|
||||
self._verify(token, tokenSecret, profile, verified);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// In order to authenticate via OAuth, the application must obtain a request
|
||||
// token from the service provider and redirect the user to the service
|
||||
// provider to obtain their authorization. After authorization has been
|
||||
// approved the user will be redirected back the application, at which point
|
||||
// the application can exchange the request token for an access token.
|
||||
//
|
||||
// In order to successfully exchange the request token, its corresponding
|
||||
// token secret needs to be known. The token secret will be temporarily
|
||||
// stored in the session, so that it can be retrieved upon the user being
|
||||
// redirected back to the application.
|
||||
|
||||
var params = this.requestTokenParams(options);
|
||||
var callbackURL = options.callbackURL || this._callbackURL;
|
||||
if (callbackURL) {
|
||||
var parsed = url.parse(callbackURL);
|
||||
if (!parsed.protocol) {
|
||||
// The callback URL is relative, resolve a fully qualified URL from the
|
||||
// URL of the originating request.
|
||||
callbackURL = url.resolve(utils.originalURL(req), callbackURL);
|
||||
}
|
||||
}
|
||||
params['oauth_callback'] = callbackURL;
|
||||
|
||||
this._oauth.getOAuthRequestToken(params, function(err, token, tokenSecret, params) {
|
||||
if (err) { return self.error(new InternalOAuthError('failed to obtain request token', err)); }
|
||||
|
||||
// NOTE: params will contain an oauth_callback_confirmed property set to
|
||||
// true, if the server supports OAuth 1.0a.
|
||||
// { oauth_callback_confirmed: 'true' }
|
||||
|
||||
if (!req.session[self._key]) { req.session[self._key] = {}; }
|
||||
req.session[self._key]['oauth_token'] = token;
|
||||
req.session[self._key]['oauth_token_secret'] = tokenSecret;
|
||||
|
||||
var parsed = url.parse(self._userAuthorizationURL, true);
|
||||
parsed.query['oauth_token'] = token;
|
||||
utils.merge(parsed.query, self.userAuthorizationParams(options))
|
||||
delete parsed.search;
|
||||
var location = url.format(parsed);
|
||||
self.redirect(location);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve user profile from service provider.
|
||||
*
|
||||
* OAuth-based authentication strategies can overrride this function in order to
|
||||
* load the user's profile from the service provider. This assists applications
|
||||
* (and users of those applications) in the initial registration process by
|
||||
* automatically submitting required information.
|
||||
*
|
||||
* @param {String} accessToken
|
||||
* @param {Function} done
|
||||
* @api protected
|
||||
*/
|
||||
OAuthStrategy.prototype.userProfile = function(token, tokenSecret, params, done) {
|
||||
return done(null, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extra parameters to be included in the request token request.
|
||||
*
|
||||
* Some OAuth providers require additional parameters to be included when
|
||||
* issuing a request token. Since these parameters are not standardized by the
|
||||
* OAuth specification, OAuth-based authentication strategies can overrride this
|
||||
* function in order to populate these parameters as required by the provider.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Object}
|
||||
* @api protected
|
||||
*/
|
||||
OAuthStrategy.prototype.requestTokenParams = function(options) {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extra parameters to be included in the user authorization request.
|
||||
*
|
||||
* Some OAuth providers allow additional, non-standard parameters to be included
|
||||
* when requesting authorization. Since these parameters are not standardized
|
||||
* by the OAuth specification, OAuth-based authentication strategies can
|
||||
* overrride this function in order to populate these parameters as required by
|
||||
* the provider.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Object}
|
||||
* @api protected
|
||||
*/
|
||||
OAuthStrategy.prototype.userAuthorizationParams = function(options) {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load user profile, contingent upon options.
|
||||
*
|
||||
* @param {String} accessToken
|
||||
* @param {Function} done
|
||||
* @api private
|
||||
*/
|
||||
OAuthStrategy.prototype._loadUserProfile = function(token, tokenSecret, params, done) {
|
||||
var self = this;
|
||||
|
||||
function loadIt() {
|
||||
return self.userProfile(token, tokenSecret, params, done);
|
||||
}
|
||||
function skipIt() {
|
||||
return done(null);
|
||||
}
|
||||
|
||||
if (typeof this._skipUserProfile == 'function' && this._skipUserProfile.length > 1) {
|
||||
// async
|
||||
this._skipUserProfile(token, tokenSecret, function(err, skip) {
|
||||
if (err) { return done(err); }
|
||||
if (!skip) { return loadIt(); }
|
||||
return skipIt();
|
||||
});
|
||||
} else {
|
||||
var skip = (typeof this._skipUserProfile == 'function') ? this._skipUserProfile() : this._skipUserProfile;
|
||||
if (!skip) { return loadIt(); }
|
||||
return skipIt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expose `OAuthStrategy`.
|
||||
*/
|
||||
module.exports = OAuthStrategy;
|
248
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth2.js
generated
vendored
Normal file
248
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/strategies/oauth2.js
generated
vendored
Normal file
@ -0,0 +1,248 @@
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
var passport = require('passport')
|
||||
, url = require('url')
|
||||
, util = require('util')
|
||||
, utils = require('./utils')
|
||||
, OAuth2 = require('oauth').OAuth2
|
||||
, InternalOAuthError = require('../errors/internaloautherror');
|
||||
|
||||
|
||||
/**
|
||||
* `OAuth2Strategy` constructor.
|
||||
*
|
||||
* The OAuth 2.0 authentication strategy authenticates requests using the OAuth
|
||||
* 2.0 protocol.
|
||||
*
|
||||
* OAuth 2.0 provides a facility for delegated authentication, whereby users can
|
||||
* authenticate using a third-party service such as Facebook. Delegating in
|
||||
* this manner involves a sequence of events, including redirecting the user to
|
||||
* the third-party service for authorization. Once authorization has been
|
||||
* granted, the user is redirected back to the application and an authorization
|
||||
* code can be used to obtain credentials.
|
||||
*
|
||||
* Applications must supply a `verify` callback which accepts an `accessToken`,
|
||||
* `refreshToken` and service-specific `profile`, and then calls the `done`
|
||||
* callback supplying a `user`, which should be set to `false` if the
|
||||
* credentials are not valid. If an exception occured, `err` should be set.
|
||||
*
|
||||
* Options:
|
||||
* - `authorizationURL` URL used to obtain an authorization grant
|
||||
* - `tokenURL` URL used to obtain an access token
|
||||
* - `clientID` identifies client to service provider
|
||||
* - `clientSecret` secret used to establish ownership of the client identifer
|
||||
* - `callbackURL` URL to which the service provider will redirect the user after obtaining authorization
|
||||
* - `passReqToCallback` when `true`, `req` is the first argument to the verify callback (default: `false`)
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* passport.use(new OAuth2Strategy({
|
||||
* authorizationURL: 'https://www.example.com/oauth2/authorize',
|
||||
* tokenURL: 'https://www.example.com/oauth2/token',
|
||||
* clientID: '123-456-789',
|
||||
* clientSecret: 'shhh-its-a-secret'
|
||||
* callbackURL: 'https://www.example.net/auth/example/callback'
|
||||
* },
|
||||
* function(accessToken, refreshToken, profile, done) {
|
||||
* User.findOrCreate(..., function (err, user) {
|
||||
* done(err, user);
|
||||
* });
|
||||
* }
|
||||
* ));
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {Function} verify
|
||||
* @api public
|
||||
*/
|
||||
function OAuth2Strategy(options, verify) {
|
||||
options = options || {}
|
||||
passport.Strategy.call(this);
|
||||
this.name = 'oauth2';
|
||||
this._verify = verify;
|
||||
|
||||
if (!options.authorizationURL) throw new Error('OAuth2Strategy requires a authorizationURL option');
|
||||
if (!options.tokenURL) throw new Error('OAuthStrategy requires a tokenURL option');
|
||||
if (!options.clientID) throw new Error('OAuth2Strategy requires a clientID option');
|
||||
if (!options.clientSecret) throw new Error('OAuth2Strategy requires a clientSecret option');
|
||||
|
||||
// NOTE: The _oauth2 property is considered "protected". Subclasses are
|
||||
// allowed to use it when making protected resource requests to retrieve
|
||||
// the user profile.
|
||||
this._oauth2 = new OAuth2(options.clientID, options.clientSecret,
|
||||
'', options.authorizationURL, options.tokenURL, options.customHeaders);
|
||||
|
||||
this._callbackURL = options.callbackURL;
|
||||
this._scope = options.scope;
|
||||
this._scopeSeparator = options.scopeSeparator || ' ';
|
||||
this._passReqToCallback = options.passReqToCallback;
|
||||
this._skipUserProfile = (options.skipUserProfile === undefined) ? false : options.skipUserProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit from `passport.Strategy`.
|
||||
*/
|
||||
util.inherits(OAuth2Strategy, passport.Strategy);
|
||||
|
||||
|
||||
/**
|
||||
* Authenticate request by delegating to a service provider using OAuth 2.0.
|
||||
*
|
||||
* @param {Object} req
|
||||
* @api protected
|
||||
*/
|
||||
OAuth2Strategy.prototype.authenticate = function(req, options) {
|
||||
options = options || {};
|
||||
var self = this;
|
||||
|
||||
if (req.query && req.query.error) {
|
||||
// TODO: Error information pertaining to OAuth 2.0 flows is encoded in the
|
||||
// query parameters, and should be propagated to the application.
|
||||
return this.fail();
|
||||
}
|
||||
|
||||
// HACK - Make this better
|
||||
var callbackURL = 'http://' + req.headers['x-forwarded-host'] + '/auth/callback';
|
||||
// var callbackURL = options.callbackURL || this._callbackURL;
|
||||
if (callbackURL) {
|
||||
var parsed = url.parse(callbackURL);
|
||||
if (!parsed.protocol) {
|
||||
// The callback URL is relative, resolve a fully qualified URL from the
|
||||
// URL of the originating request.
|
||||
callbackURL = url.resolve(utils.originalURL(req), callbackURL);
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query && req.query.code) {
|
||||
var code = req.query.code;
|
||||
|
||||
// NOTE: The module oauth (0.9.5), which is a dependency, automatically adds
|
||||
// a 'type=web_server' parameter to the percent-encoded data sent in
|
||||
// the body of the access token request. This appears to be an
|
||||
// artifact from an earlier draft of OAuth 2.0 (draft 22, as of the
|
||||
// time of this writing). This parameter is not necessary, but its
|
||||
// presence does not appear to cause any issues.
|
||||
this._oauth2.getOAuthAccessToken(code, { grant_type: 'authorization_code', redirect_uri: callbackURL },
|
||||
function(err, accessToken, refreshToken, params) {
|
||||
if (err) { return self.error(new InternalOAuthError('failed to obtain access token', err)); }
|
||||
|
||||
self._loadUserProfile(accessToken, function(err, profile) {
|
||||
if (err) { return self.error(err); };
|
||||
|
||||
function verified(err, user, info) {
|
||||
if (err) { return self.error(err); }
|
||||
if (!user) { return self.fail(info); }
|
||||
self.success(user, info);
|
||||
}
|
||||
|
||||
if (self._passReqToCallback) {
|
||||
var arity = self._verify.length;
|
||||
if (arity == 6) {
|
||||
self._verify(req, accessToken, refreshToken, params, profile, verified);
|
||||
} else { // arity == 5
|
||||
self._verify(req, accessToken, refreshToken, profile, verified);
|
||||
}
|
||||
} else {
|
||||
var arity = self._verify.length;
|
||||
if (arity == 5) {
|
||||
self._verify(accessToken, refreshToken, params, profile, verified);
|
||||
} else { // arity == 4
|
||||
self._verify(accessToken, refreshToken, profile, verified);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// NOTE: The module oauth (0.9.5), which is a dependency, automatically adds
|
||||
// a 'type=web_server' parameter to the query portion of the URL.
|
||||
// This appears to be an artifact from an earlier draft of OAuth 2.0
|
||||
// (draft 22, as of the time of this writing). This parameter is not
|
||||
// necessary, but its presence does not appear to cause any issues.
|
||||
|
||||
var params = this.authorizationParams(options);
|
||||
params['response_type'] = 'code';
|
||||
params['redirect_uri'] = callbackURL;
|
||||
var scope = options.scope || this._scope;
|
||||
if (scope) {
|
||||
if (Array.isArray(scope)) { scope = scope.join(this._scopeSeparator); }
|
||||
params.scope = scope;
|
||||
}
|
||||
var state = options.state;
|
||||
if (state) { params.state = state; }
|
||||
|
||||
var location = this._oauth2.getAuthorizeUrl(params);
|
||||
this.redirect(location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve user profile from service provider.
|
||||
*
|
||||
* OAuth 2.0-based authentication strategies can overrride this function in
|
||||
* order to load the user's profile from the service provider. This assists
|
||||
* applications (and users of those applications) in the initial registration
|
||||
* process by automatically submitting required information.
|
||||
*
|
||||
* @param {String} accessToken
|
||||
* @param {Function} done
|
||||
* @api protected
|
||||
*/
|
||||
OAuth2Strategy.prototype.userProfile = function(accessToken, done) {
|
||||
return done(null, {});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extra parameters to be included in the authorization request.
|
||||
*
|
||||
* Some OAuth 2.0 providers allow additional, non-standard parameters to be
|
||||
* included when requesting authorization. Since these parameters are not
|
||||
* standardized by the OAuth 2.0 specification, OAuth 2.0-based authentication
|
||||
* strategies can overrride this function in order to populate these parameters
|
||||
* as required by the provider.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Object}
|
||||
* @api protected
|
||||
*/
|
||||
OAuth2Strategy.prototype.authorizationParams = function(options) {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Load user profile, contingent upon options.
|
||||
*
|
||||
* @param {String} accessToken
|
||||
* @param {Function} done
|
||||
* @api private
|
||||
*/
|
||||
OAuth2Strategy.prototype._loadUserProfile = function(accessToken, done) {
|
||||
var self = this;
|
||||
|
||||
function loadIt() {
|
||||
return self.userProfile(accessToken, done);
|
||||
}
|
||||
function skipIt() {
|
||||
return done(null);
|
||||
}
|
||||
|
||||
if (typeof this._skipUserProfile == 'function' && this._skipUserProfile.length > 1) {
|
||||
// async
|
||||
this._skipUserProfile(accessToken, function(err, skip) {
|
||||
if (err) { return done(err); }
|
||||
if (!skip) { return loadIt(); }
|
||||
return skipIt();
|
||||
});
|
||||
} else {
|
||||
var skip = (typeof this._skipUserProfile == 'function') ? this._skipUserProfile() : this._skipUserProfile;
|
||||
if (!skip) { return loadIt(); }
|
||||
return skipIt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expose `OAuth2Strategy`.
|
||||
*/
|
||||
module.exports = OAuth2Strategy;
|
||||
|
46
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/strategies/utils.js
generated
vendored
Normal file
46
node_modules/passport-google-oauth/node_modules/passport-oauth/lib/passport-oauth/strategies/utils.js
generated
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Reconstructs the original URL of the request.
|
||||
*
|
||||
* This function builds a URL that corresponds the original URL requested by the
|
||||
* client, including the protocol (http or https) and host.
|
||||
*
|
||||
* If the request passed through any proxies that terminate SSL, the
|
||||
* `X-Forwarded-Proto` header is used to detect if the request was encrypted to
|
||||
* the proxy.
|
||||
*
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
exports.originalURL = function(req) {
|
||||
var headers = req.headers
|
||||
, protocol = (req.connection.encrypted || req.headers['x-forwarded-proto'] == 'https')
|
||||
? 'https'
|
||||
: 'http'
|
||||
, host = headers.host
|
||||
, path = req.url || '';
|
||||
return protocol + '://' + host + path;
|
||||
};
|
||||
|
||||
/**
|
||||
* Merge object b with object a.
|
||||
*
|
||||
* var a = { foo: 'bar' }
|
||||
* , b = { bar: 'baz' };
|
||||
*
|
||||
* utils.merge(a, b);
|
||||
* // => { foo: 'bar', bar: 'baz' }
|
||||
*
|
||||
* @param {Object} a
|
||||
* @param {Object} b
|
||||
* @return {Object}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
exports.merge = function(a, b){
|
||||
if (a && b) {
|
||||
for (var key in b) {
|
||||
a[key] = b[key];
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
1
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/.npmignore
generated
vendored
Normal file
1
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
8
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/LICENSE
generated
vendored
Normal file
8
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/LICENSE
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
The MIT License (MIT)
|
||||
Copyright (c) <2010-2012> <Ciaran Jessup>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
7
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/Makefile
generated
vendored
Normal file
7
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/Makefile
generated
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
#
|
||||
# Run all tests
|
||||
#
|
||||
test:
|
||||
@@node_modules/.bin/vows tests/* --spec
|
||||
|
||||
.PHONY: test install
|
99
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/Readme.md
generated
vendored
Normal file
99
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/Readme.md
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
node-oauth
|
||||
===========
|
||||
A simple oauth API for node.js . This API allows users to authenticate against OAUTH providers, and thus act as OAuth consumers. It also has support for OAuth Echo, which is used for communicating with 3rd party media providers such as TwitPic and yFrog.
|
||||
|
||||
Tested against Twitter (http://twitter.com), term.ie (http://term.ie/oauth/example/), TwitPic, and Yahoo!
|
||||
|
||||
Also provides rudimentary OAuth2 support, tested against facebook, github, foursquare, google and Janrain. For more complete usage examples please take a look at connect-auth (http://github.com/ciaranj/connect-auth)
|
||||
|
||||
|
||||
Installation
|
||||
==============
|
||||
|
||||
$ npm install oauth
|
||||
|
||||
|
||||
Change History
|
||||
==============
|
||||
|
||||
* 0.9.10
|
||||
- OAuth2: Addresses 2 issues that came in with 0.9.9, #129 & #125 (thank you José F. Romaniello)
|
||||
* 0.9.9
|
||||
- OAuth1: Fix the mismatch between the output of querystring.stringify() and this._encodeData(). (thank you rolandboon)
|
||||
- OAuth2: Adds Authorization Header and supports extra headers by default ( thanks to Brian Park)
|
||||
* 0.9.8
|
||||
- OAuth1: Support overly-strict OAuth server's that require whitespace separating the Authorization Header parameters (e.g. 500px.com) (Thanks to Christian Schwarz)
|
||||
- OAuth1: Fix incorrect double-encoding of PLAINTEXT OAuth connections (Thanks to Joe Rozner)
|
||||
- OAuth1: Minor safety check added when checking hostnames. (Thanks to Garrick Cheung)
|
||||
* 0.9.7
|
||||
- OAuth2: Pass back any extra response data for calls to getOAuthAccessToken (Thanks to Tang Bo Hao)
|
||||
- OAuth2: Don't force a https request if given a http url (Thanks to Damien Mathieu)
|
||||
- OAuth2: Supports specifying a grant-type of 'refresh-token' (Thanks to Luke Baker)
|
||||
* 0.9.6
|
||||
- OAuth2: Support for 302 redirects (Thanks Patrick Negri).
|
||||
- OAuth1/2: Some code tidying. ( Thanks to Raoul Millais )
|
||||
* 0.9.5
|
||||
- OAuth1: Allow usage of HTTP verbs other than GET for retrieving the access and request tokens (Thanks to Raoul Millais)
|
||||
* 0.9.4
|
||||
- OAuth1/2: Support for OAuth providers that drop connections (don't send response lengths? [Google])
|
||||
- OAuth2: Change getOAuthAccessToken to POST rather than GET ( Possible Breaking change!!! ... re-tested against Google, Github, Facebook, FourSquare and Janrain and seems ok .. is closer to the spec (v20) )
|
||||
* 0.9.3
|
||||
- OAuth1: Adds support for following 301 redirects (Thanks bdickason)
|
||||
* 0.9.2
|
||||
- OAuth1: Correct content length calculated for non-ascii post bodies (Thanks selead)
|
||||
- OAuth1: Allowed for configuration of the 'access token' name used when requesting protected resources (OAuth2)
|
||||
* 0.9.1
|
||||
- OAuth1: Added support for automatically following 302 redirects (Thanks neyric)
|
||||
- OAuth1: Added support for OAuth Echo (Thanks Ryan LeFevre).
|
||||
- OAuth1: Improved handling of 2xx responses (Thanks Neil Mansilla).
|
||||
* 0.9.0
|
||||
- OAuth1/2: Compatibility fixes to bring node-oauth up to speed with node.js 0.4x [thanks to Rasmus Andersson for starting the work ]
|
||||
* 0.8.4
|
||||
- OAuth1: Fixed issue #14 (Parameter ordering ignored encodings).
|
||||
- OAuth1: Added support for repeated parameter names.
|
||||
- OAuth1/2: Implements issue #15 (Use native SHA1 if available, 10x speed improvement!).
|
||||
- OAuth2: Fixed issue #16 (Should use POST when requesting access tokens.).
|
||||
- OAuth2: Fixed Issue #17 (OAuth2 spec compliance).
|
||||
- OAuth1: Implemented enhancement #13 (Adds support for PUT & DELETE http verbs).
|
||||
- OAuth1: Fixes issue #18 (Complex/Composite url arguments [thanks novemberborn])
|
||||
* 0.8.3
|
||||
- OAuth1: Fixed an issue where the auth header code depended on the Array's toString method (Yohei Sasaki) Updated the getOAuthRequestToken method so we can access google's OAuth secured methods. Also re-implemented and fleshed out the test suite.
|
||||
* 0.8.2
|
||||
- OAuth1: The request returning methods will now write the POST body if provided (Chris Anderson), the code responsible for manipulating the headers is a bit safe now when working with other code (Paul McKellar)
|
||||
- Package: Tweaked the package.json to use index.js instead of main.js
|
||||
* 0.8.1
|
||||
- OAuth1: Added mechanism to get hold of a signed Node Request object, ready for attaching response listeners etc. (Perfect for streaming APIs)
|
||||
* 0.8.0
|
||||
- OAuth1: Standardised method capitalisation, the old getOauthAccessToken is now getOAuthAccessToken (Breaking change to existing code)
|
||||
* 0.7.7
|
||||
- OAuth1: Looks like non oauth_ parameters where appearing within the Authorization headers, which I believe to be incorrect.
|
||||
* 0.7.6
|
||||
- OAuth1: Added in oauth_verifier property to getAccessToken required for 1.0A
|
||||
* 0.7.5
|
||||
- Package: Added in a main.js to simplify the require'ing of OAuth
|
||||
* 0.7.4
|
||||
- OAuth1: Minor change to add an error listener to the OAuth client (thanks troyk)
|
||||
* 0.7.3
|
||||
- OAuth2: Now sends a Content-Length Http header to keep nginx happy :)
|
||||
* 0.7.2
|
||||
- OAuth1: Fixes some broken unit tests!
|
||||
* 0.7.0
|
||||
- OAuth1/2: Introduces support for HTTPS end points and callback URLS for OAuth 1.0A and Oauth 2 (Please be aware that this was a breaking change to the constructor arguments order)
|
||||
|
||||
Contributors (In no particular order)
|
||||
=====================================
|
||||
|
||||
* Ciaran Jessup - ciaranj@gmail.com
|
||||
* Mark Wubben - http://equalmedia.com/
|
||||
* Ryan LeFevre - http://meltingice.net
|
||||
* Raoul Millais
|
||||
* Patrick Negri - http://github.com/pnegri
|
||||
* Tang Bo Hao - http://github.com/btspoony
|
||||
* Damien Mathieu - http://42.dmathieu.com
|
||||
* Luke Baker - http://github.com/lukebaker
|
||||
* Christian Schwarz - http://github.com/chrischw/
|
||||
* Joe Rozer - http://www.deadbytes.net
|
||||
* Garrick Cheung - http://www.garrickcheung.com/
|
||||
* rolandboon - http://rolandboon.com
|
||||
* Brian Park - http://github.com/yaru22
|
||||
* José F. Romaniello - http://github.com/jfromaniello
|
168
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/server.js
generated
vendored
Normal file
168
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/server.js
generated
vendored
Normal file
@ -0,0 +1,168 @@
|
||||
var express = require('express'),
|
||||
OAuth = require('oauth').OAuth,
|
||||
querystring = require('querystring');
|
||||
|
||||
// Setup the Express.js server
|
||||
var app = express.createServer();
|
||||
app.use(express.logger());
|
||||
app.use(express.bodyParser());
|
||||
app.use(express.cookieParser());
|
||||
app.use(express.session({
|
||||
secret: "skjghskdjfhbqigohqdiouk"
|
||||
}));
|
||||
|
||||
// Home Page
|
||||
app.get('/', function(req, res){
|
||||
if(!req.session.oauth_access_token) {
|
||||
res.redirect("/google_login");
|
||||
}
|
||||
else {
|
||||
res.redirect("/google_contacts");
|
||||
}
|
||||
});
|
||||
|
||||
// Request an OAuth Request Token, and redirects the user to authorize it
|
||||
app.get('/google_login', function(req, res) {
|
||||
|
||||
var getRequestTokenUrl = "https://www.google.com/accounts/OAuthGetRequestToken";
|
||||
|
||||
// GData specifid: scopes that wa want access to
|
||||
var gdataScopes = [
|
||||
querystring.escape("https://www.google.com/m8/feeds/"),
|
||||
querystring.escape("https://www.google.com/calendar/feeds/")
|
||||
];
|
||||
|
||||
var oa = new OAuth(getRequestTokenUrl+"?scope="+gdataScopes.join('+'),
|
||||
"https://www.google.com/accounts/OAuthGetAccessToken",
|
||||
"anonymous",
|
||||
"anonymous",
|
||||
"1.0",
|
||||
"http://localhost:3000/google_cb"+( req.param('action') && req.param('action') != "" ? "?action="+querystring.escape(req.param('action')) : "" ),
|
||||
"HMAC-SHA1");
|
||||
|
||||
oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){
|
||||
if(error) {
|
||||
console.log('error');
|
||||
console.log(error);
|
||||
}
|
||||
else {
|
||||
// store the tokens in the session
|
||||
req.session.oa = oa;
|
||||
req.session.oauth_token = oauth_token;
|
||||
req.session.oauth_token_secret = oauth_token_secret;
|
||||
|
||||
// redirect the user to authorize the token
|
||||
res.redirect("https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token="+oauth_token);
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
// Callback for the authorization page
|
||||
app.get('/google_cb', function(req, res) {
|
||||
|
||||
// get the OAuth access token with the 'oauth_verifier' that we received
|
||||
|
||||
var oa = new OAuth(req.session.oa._requestUrl,
|
||||
req.session.oa._accessUrl,
|
||||
req.session.oa._consumerKey,
|
||||
req.session.oa._consumerSecret,
|
||||
req.session.oa._version,
|
||||
req.session.oa._authorize_callback,
|
||||
req.session.oa._signatureMethod);
|
||||
|
||||
console.log(oa);
|
||||
|
||||
oa.getOAuthAccessToken(
|
||||
req.session.oauth_token,
|
||||
req.session.oauth_token_secret,
|
||||
req.param('oauth_verifier'),
|
||||
function(error, oauth_access_token, oauth_access_token_secret, results2) {
|
||||
|
||||
if(error) {
|
||||
console.log('error');
|
||||
console.log(error);
|
||||
}
|
||||
else {
|
||||
|
||||
// store the access token in the session
|
||||
req.session.oauth_access_token = oauth_access_token;
|
||||
req.session.oauth_access_token_secret = oauth_access_token_secret;
|
||||
|
||||
res.redirect((req.param('action') && req.param('action') != "") ? req.param('action') : "/google_contacts");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
function require_google_login(req, res, next) {
|
||||
if(!req.session.oauth_access_token) {
|
||||
res.redirect("/google_login?action="+querystring.escape(req.originalUrl));
|
||||
return;
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
app.get('/google_contacts', require_google_login, function(req, res) {
|
||||
var oa = new OAuth(req.session.oa._requestUrl,
|
||||
req.session.oa._accessUrl,
|
||||
req.session.oa._consumerKey,
|
||||
req.session.oa._consumerSecret,
|
||||
req.session.oa._version,
|
||||
req.session.oa._authorize_callback,
|
||||
req.session.oa._signatureMethod);
|
||||
|
||||
console.log(oa);
|
||||
|
||||
// Example using GData API v3
|
||||
// GData Specific Header
|
||||
oa._headers['GData-Version'] = '3.0';
|
||||
|
||||
oa.getProtectedResource(
|
||||
"https://www.google.com/m8/feeds/contacts/default/full?alt=json",
|
||||
"GET",
|
||||
req.session.oauth_access_token,
|
||||
req.session.oauth_access_token_secret,
|
||||
function (error, data, response) {
|
||||
|
||||
var feed = JSON.parse(data);
|
||||
|
||||
res.render('google_contacts.ejs', {
|
||||
locals: { feed: feed }
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.get('/google_calendars', require_google_login, function(req, res) {
|
||||
var oa = new OAuth(req.session.oa._requestUrl,
|
||||
req.session.oa._accessUrl,
|
||||
req.session.oa._consumerKey,
|
||||
req.session.oa._consumerSecret,
|
||||
req.session.oa._version,
|
||||
req.session.oa._authorize_callback,
|
||||
req.session.oa._signatureMethod);
|
||||
// Example using GData API v2
|
||||
// GData Specific Header
|
||||
oa._headers['GData-Version'] = '2';
|
||||
|
||||
oa.getProtectedResource(
|
||||
"https://www.google.com/calendar/feeds/default/allcalendars/full?alt=jsonc",
|
||||
"GET",
|
||||
req.session.oauth_access_token,
|
||||
req.session.oauth_access_token_secret,
|
||||
function (error, data, response) {
|
||||
|
||||
var feed = JSON.parse(data);
|
||||
|
||||
res.render('google_calendars.ejs', {
|
||||
locals: { feed: feed }
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.listen(3000);
|
||||
console.log("listening on http://localhost:3000");
|
21
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/views/google_calendars.ejs
generated
vendored
Normal file
21
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/views/google_calendars.ejs
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
<p><a href="/google_contacts">Check google_contacts</a></p>
|
||||
|
||||
<h1>Google Calendars</h1>
|
||||
|
||||
<% for(var i = 0 ; i < feed.data.items.length ; i++ ) {
|
||||
|
||||
var calendar = feed.data.items[i]; %>
|
||||
<div>
|
||||
|
||||
<h2 style="color:white;background-color:<%= calendar["color"] %>"><%= calendar["title"] %></h2>
|
||||
|
||||
<p>canEdit: <%= calendar["canEdit"] %></p>
|
||||
<p>accessLevel: <%= calendar["accessLevel"] %></p>
|
||||
<p>timeZone: <%= calendar["timeZone"] %></p>
|
||||
<p>kind: <%= calendar["kind"] %></p>
|
||||
<p>updated: <%= calendar["updated"] %></p>
|
||||
<p>created: <%= calendar["created"] %></p>
|
||||
|
||||
</div>
|
||||
<% } %>
|
24
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/views/google_contacts.ejs
generated
vendored
Normal file
24
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/views/google_contacts.ejs
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
<p><a href="/google_calendars">Check google_calendars</a></p>
|
||||
|
||||
<h1>Google Contacts</h1>
|
||||
|
||||
<% for(var i = 0 ; i < feed.feed.entry.length ; i++ ) {
|
||||
|
||||
var contact = feed.feed.entry[i]; %>
|
||||
|
||||
<div>
|
||||
<!-- you can access much more ! Just a sample: -->
|
||||
<%= contact["title"]["$t"] %>
|
||||
<% emails = contact["gd$email"] %>
|
||||
|
||||
<ul>
|
||||
<% for(var j = 0 ; j < emails.length ; j++) { %>
|
||||
<li><%= emails[j]["address" ]%></li>
|
||||
<% } %>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<% } %>
|
9
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/views/layout.ejs
generated
vendored
Normal file
9
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/express-gdata/views/layout.ejs
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<%- body %>
|
||||
|
||||
</body>
|
||||
</html>
|
31
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/term.ie.oauth-HMAC-SHA1.js
generated
vendored
Normal file
31
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/examples/term.ie.oauth-HMAC-SHA1.js
generated
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
var util= require('util')
|
||||
|
||||
var OAuth= require('../lib/oauth').OAuth;
|
||||
|
||||
var oa= new OAuth("http://term.ie/oauth/example/request_token.php",
|
||||
"http://term.ie/oauth/example/access_token.php",
|
||||
"key",
|
||||
"secret",
|
||||
"1.0",
|
||||
null,
|
||||
"HMAC-SHA1")
|
||||
|
||||
oa.getOAuthRequestToken(function(error, oauth_token, oauth_token_secret, results){
|
||||
if(error) util.puts('error :' + error)
|
||||
else {
|
||||
util.puts('oauth_token :' + oauth_token)
|
||||
util.puts('oauth_token_secret :' + oauth_token_secret)
|
||||
util.puts('requestoken results :' + util.inspect(results))
|
||||
util.puts("Requesting access token")
|
||||
oa.getOAuthAccessToken(oauth_token, oauth_token_secret, function(error, oauth_access_token, oauth_access_token_secret, results2) {
|
||||
util.puts('oauth_access_token :' + oauth_access_token)
|
||||
util.puts('oauth_token_secret :' + oauth_access_token_secret)
|
||||
util.puts('accesstoken results :' + util.inspect(results2))
|
||||
util.puts("Requesting access token")
|
||||
var data= "";
|
||||
oa.getProtectedResource("http://term.ie/oauth/example/echo_api.php?foo=bar&too=roo", "GET", oauth_access_token, oauth_access_token_secret, function (error, data, response) {
|
||||
util.puts(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
3
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/index.js
generated
vendored
Normal file
3
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/index.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
exports.OAuth = require("./lib/oauth").OAuth;
|
||||
exports.OAuthEcho = require("./lib/oauth").OAuthEcho;
|
||||
exports.OAuth2 = require("./lib/oauth2").OAuth2;
|
4
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/_utils.js
generated
vendored
Normal file
4
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/_utils.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
// Returns true if this is a host that closes *before* it ends?!?!
|
||||
module.exports.isAnEarlyCloseHost= function( hostName ) {
|
||||
return hostName && hostName.match(".*google(apis)?.com$")
|
||||
}
|
556
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/oauth.js
generated
vendored
Normal file
556
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/oauth.js
generated
vendored
Normal file
@ -0,0 +1,556 @@
|
||||
var crypto= require('crypto'),
|
||||
sha1= require('./sha1'),
|
||||
http= require('http'),
|
||||
https= require('https'),
|
||||
URL= require('url'),
|
||||
querystring= require('querystring'),
|
||||
OAuthUtils= require('./_utils');
|
||||
|
||||
exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize, customHeaders) {
|
||||
this._isEcho = false;
|
||||
|
||||
this._requestUrl= requestUrl;
|
||||
this._accessUrl= accessUrl;
|
||||
this._consumerKey= consumerKey;
|
||||
this._consumerSecret= this._encodeData( consumerSecret );
|
||||
this._version= version;
|
||||
if( authorize_callback === undefined ) {
|
||||
this._authorize_callback= "oob";
|
||||
}
|
||||
else {
|
||||
this._authorize_callback= authorize_callback;
|
||||
}
|
||||
|
||||
if( signatureMethod != "PLAINTEXT" && signatureMethod != "HMAC-SHA1")
|
||||
throw new Error("Un-supported signature method: " + signatureMethod )
|
||||
this._signatureMethod= signatureMethod;
|
||||
this._nonceSize= nonceSize || 32;
|
||||
this._headers= customHeaders || {"Accept" : "*/*",
|
||||
"Connection" : "close",
|
||||
"User-Agent" : "Node authentication"}
|
||||
this._clientOptions= this._defaultClientOptions= {"requestTokenHttpMethod": "POST",
|
||||
"accessTokenHttpMethod": "POST"};
|
||||
this._oauthParameterSeperator = ",";
|
||||
};
|
||||
|
||||
exports.OAuthEcho= function(realm, verify_credentials, consumerKey, consumerSecret, version, signatureMethod, nonceSize, customHeaders) {
|
||||
this._isEcho = true;
|
||||
|
||||
this._realm= realm;
|
||||
this._verifyCredentials = verify_credentials;
|
||||
this._consumerKey= consumerKey;
|
||||
this._consumerSecret= this._encodeData( consumerSecret );
|
||||
this._version= version;
|
||||
|
||||
if( signatureMethod != "PLAINTEXT" && signatureMethod != "HMAC-SHA1")
|
||||
throw new Error("Un-supported signature method: " + signatureMethod );
|
||||
this._signatureMethod= signatureMethod;
|
||||
this._nonceSize= nonceSize || 32;
|
||||
this._headers= customHeaders || {"Accept" : "*/*",
|
||||
"Connection" : "close",
|
||||
"User-Agent" : "Node authentication"};
|
||||
this._oauthParameterSeperator = ",";
|
||||
}
|
||||
|
||||
exports.OAuthEcho.prototype = exports.OAuth.prototype;
|
||||
|
||||
exports.OAuth.prototype._getTimestamp= function() {
|
||||
return Math.floor( (new Date()).getTime() / 1000 );
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._encodeData= function(toEncode){
|
||||
if( toEncode == null || toEncode == "" ) return ""
|
||||
else {
|
||||
var result= encodeURIComponent(toEncode);
|
||||
// Fix the mismatch between OAuth's RFC3986's and Javascript's beliefs in what is right and wrong ;)
|
||||
return result.replace(/\!/g, "%21")
|
||||
.replace(/\'/g, "%27")
|
||||
.replace(/\(/g, "%28")
|
||||
.replace(/\)/g, "%29")
|
||||
.replace(/\*/g, "%2A");
|
||||
}
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._decodeData= function(toDecode) {
|
||||
if( toDecode != null ) {
|
||||
toDecode = toDecode.replace(/\+/g, " ");
|
||||
}
|
||||
return decodeURIComponent( toDecode);
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._getSignature= function(method, url, parameters, tokenSecret) {
|
||||
var signatureBase= this._createSignatureBase(method, url, parameters);
|
||||
return this._createSignature( signatureBase, tokenSecret );
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._normalizeUrl= function(url) {
|
||||
var parsedUrl= URL.parse(url, true)
|
||||
var port ="";
|
||||
if( parsedUrl.port ) {
|
||||
if( (parsedUrl.protocol == "http:" && parsedUrl.port != "80" ) ||
|
||||
(parsedUrl.protocol == "https:" && parsedUrl.port != "443") ) {
|
||||
port= ":" + parsedUrl.port;
|
||||
}
|
||||
}
|
||||
|
||||
if( !parsedUrl.pathname || parsedUrl.pathname == "" ) parsedUrl.pathname ="/";
|
||||
|
||||
return parsedUrl.protocol + "//" + parsedUrl.hostname + port + parsedUrl.pathname;
|
||||
}
|
||||
|
||||
// Is the parameter considered an OAuth parameter
|
||||
exports.OAuth.prototype._isParameterNameAnOAuthParameter= function(parameter) {
|
||||
var m = parameter.match('^oauth_');
|
||||
if( m && ( m[0] === "oauth_" ) ) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// build the OAuth request authorization header
|
||||
exports.OAuth.prototype._buildAuthorizationHeaders= function(orderedParameters) {
|
||||
var authHeader="OAuth ";
|
||||
if( this._isEcho ) {
|
||||
authHeader += 'realm="' + this._realm + '",';
|
||||
}
|
||||
|
||||
for( var i= 0 ; i < orderedParameters.length; i++) {
|
||||
// Whilst the all the parameters should be included within the signature, only the oauth_ arguments
|
||||
// should appear within the authorization header.
|
||||
if( this._isParameterNameAnOAuthParameter(orderedParameters[i][0]) ) {
|
||||
authHeader+= "" + this._encodeData(orderedParameters[i][0])+"=\""+ this._encodeData(orderedParameters[i][1])+"\""+ this._oauthParameterSeperator;
|
||||
}
|
||||
}
|
||||
|
||||
authHeader= authHeader.substring(0, authHeader.length-this._oauthParameterSeperator.length);
|
||||
return authHeader;
|
||||
}
|
||||
|
||||
// Takes an object literal that represents the arguments, and returns an array
|
||||
// of argument/value pairs.
|
||||
exports.OAuth.prototype._makeArrayOfArgumentsHash= function(argumentsHash) {
|
||||
var argument_pairs= [];
|
||||
for(var key in argumentsHash ) {
|
||||
var value= argumentsHash[key];
|
||||
if( Array.isArray(value) ) {
|
||||
for(var i=0;i<value.length;i++) {
|
||||
argument_pairs[argument_pairs.length]= [key, value[i]];
|
||||
}
|
||||
}
|
||||
else {
|
||||
argument_pairs[argument_pairs.length]= [key, value];
|
||||
}
|
||||
}
|
||||
return argument_pairs;
|
||||
}
|
||||
|
||||
// Sorts the encoded key value pairs by encoded name, then encoded value
|
||||
exports.OAuth.prototype._sortRequestParams= function(argument_pairs) {
|
||||
// Sort by name, then value.
|
||||
argument_pairs.sort(function(a,b) {
|
||||
if ( a[0]== b[0] ) {
|
||||
return a[1] < b[1] ? -1 : 1;
|
||||
}
|
||||
else return a[0] < b[0] ? -1 : 1;
|
||||
});
|
||||
|
||||
return argument_pairs;
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._normaliseRequestParams= function(arguments) {
|
||||
var argument_pairs= this._makeArrayOfArgumentsHash(arguments);
|
||||
// First encode them #3.4.1.3.2 .1
|
||||
for(var i=0;i<argument_pairs.length;i++) {
|
||||
argument_pairs[i][0]= this._encodeData( argument_pairs[i][0] );
|
||||
argument_pairs[i][1]= this._encodeData( argument_pairs[i][1] );
|
||||
}
|
||||
|
||||
// Then sort them #3.4.1.3.2 .2
|
||||
argument_pairs= this._sortRequestParams( argument_pairs );
|
||||
|
||||
// Then concatenate together #3.4.1.3.2 .3 & .4
|
||||
var args= "";
|
||||
for(var i=0;i<argument_pairs.length;i++) {
|
||||
args+= argument_pairs[i][0];
|
||||
args+= "="
|
||||
args+= argument_pairs[i][1];
|
||||
if( i < argument_pairs.length-1 ) args+= "&";
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._createSignatureBase= function(method, url, parameters) {
|
||||
url= this._encodeData( this._normalizeUrl(url) );
|
||||
parameters= this._encodeData( parameters );
|
||||
return method.toUpperCase() + "&" + url + "&" + parameters;
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._createSignature= function(signatureBase, tokenSecret) {
|
||||
if( tokenSecret === undefined ) var tokenSecret= "";
|
||||
else tokenSecret= this._encodeData( tokenSecret );
|
||||
// consumerSecret is already encoded
|
||||
var key= this._consumerSecret + "&" + tokenSecret;
|
||||
|
||||
var hash= ""
|
||||
if( this._signatureMethod == "PLAINTEXT" ) {
|
||||
hash= key;
|
||||
}
|
||||
else {
|
||||
if( crypto.Hmac ) {
|
||||
hash = crypto.createHmac("sha1", key).update(signatureBase).digest("base64");
|
||||
}
|
||||
else {
|
||||
hash= sha1.HMACSHA1(key, signatureBase);
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
exports.OAuth.prototype.NONCE_CHARS= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n',
|
||||
'o','p','q','r','s','t','u','v','w','x','y','z','A','B',
|
||||
'C','D','E','F','G','H','I','J','K','L','M','N','O','P',
|
||||
'Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3',
|
||||
'4','5','6','7','8','9'];
|
||||
|
||||
exports.OAuth.prototype._getNonce= function(nonceSize) {
|
||||
var result = [];
|
||||
var chars= this.NONCE_CHARS;
|
||||
var char_pos;
|
||||
var nonce_chars_length= chars.length;
|
||||
|
||||
for (var i = 0; i < nonceSize; i++) {
|
||||
char_pos= Math.floor(Math.random() * nonce_chars_length);
|
||||
result[i]= chars[char_pos];
|
||||
}
|
||||
return result.join('');
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._createClient= function( port, hostname, method, path, headers, sslEnabled ) {
|
||||
var options = {
|
||||
host: hostname,
|
||||
port: port,
|
||||
path: path,
|
||||
method: method,
|
||||
headers: headers
|
||||
};
|
||||
var httpModel;
|
||||
if( sslEnabled ) {
|
||||
httpModel= https;
|
||||
} else {
|
||||
httpModel= http;
|
||||
}
|
||||
return httpModel.request(options);
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._prepareParameters= function( oauth_token, oauth_token_secret, method, url, extra_params ) {
|
||||
var oauthParameters= {
|
||||
"oauth_timestamp": this._getTimestamp(),
|
||||
"oauth_nonce": this._getNonce(this._nonceSize),
|
||||
"oauth_version": this._version,
|
||||
"oauth_signature_method": this._signatureMethod,
|
||||
"oauth_consumer_key": this._consumerKey
|
||||
};
|
||||
|
||||
if( oauth_token ) {
|
||||
oauthParameters["oauth_token"]= oauth_token;
|
||||
}
|
||||
|
||||
var sig;
|
||||
if( this._isEcho ) {
|
||||
sig = this._getSignature( "GET", this._verifyCredentials, this._normaliseRequestParams(oauthParameters), oauth_token_secret);
|
||||
}
|
||||
else {
|
||||
if( extra_params ) {
|
||||
for( var key in extra_params ) {
|
||||
oauthParameters[key]= extra_params[key];
|
||||
}
|
||||
}
|
||||
var parsedUrl= URL.parse( url, false );
|
||||
|
||||
if( parsedUrl.query ) {
|
||||
var key2;
|
||||
var extraParameters= querystring.parse(parsedUrl.query);
|
||||
for(var key in extraParameters ) {
|
||||
var value= extraParameters[key];
|
||||
if( typeof value == "object" ){
|
||||
// TODO: This probably should be recursive
|
||||
for(key2 in value){
|
||||
oauthParameters[key + "[" + key2 + "]"] = value[key2];
|
||||
}
|
||||
} else {
|
||||
oauthParameters[key]= value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sig = this._getSignature( method, url, this._normaliseRequestParams(oauthParameters), oauth_token_secret);
|
||||
}
|
||||
|
||||
var orderedParameters= this._sortRequestParams( this._makeArrayOfArgumentsHash(oauthParameters) );
|
||||
orderedParameters[orderedParameters.length]= ["oauth_signature", sig];
|
||||
return orderedParameters;
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback ) {
|
||||
var orderedParameters= this._prepareParameters(oauth_token, oauth_token_secret, method, url, extra_params);
|
||||
|
||||
if( !post_content_type ) {
|
||||
post_content_type= "application/x-www-form-urlencoded";
|
||||
}
|
||||
var parsedUrl= URL.parse( url, false );
|
||||
if( parsedUrl.protocol == "http:" && !parsedUrl.port ) parsedUrl.port= 80;
|
||||
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) parsedUrl.port= 443;
|
||||
|
||||
var headers= {};
|
||||
var authorization = this._buildAuthorizationHeaders(orderedParameters);
|
||||
if ( this._isEcho ) {
|
||||
headers["X-Verify-Credentials-Authorization"]= authorization;
|
||||
}
|
||||
else {
|
||||
headers["Authorization"]= authorization;
|
||||
}
|
||||
|
||||
headers["Host"] = parsedUrl.host
|
||||
|
||||
for( var key in this._headers ) {
|
||||
if (this._headers.hasOwnProperty(key)) {
|
||||
headers[key]= this._headers[key];
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out any passed extra_params that are really to do with OAuth
|
||||
for(var key in extra_params) {
|
||||
if( this._isParameterNameAnOAuthParameter( key ) ) {
|
||||
delete extra_params[key];
|
||||
}
|
||||
}
|
||||
|
||||
if( (method == "POST" || method == "PUT") && ( post_body == null && extra_params != null) ) {
|
||||
// Fix the mismatch between the output of querystring.stringify() and this._encodeData()
|
||||
post_body= querystring.stringify(extra_params)
|
||||
.replace(/\!/g, "%21")
|
||||
.replace(/\'/g, "%27")
|
||||
.replace(/\(/g, "%28")
|
||||
.replace(/\)/g, "%29")
|
||||
.replace(/\*/g, "%2A");
|
||||
}
|
||||
|
||||
headers["Content-length"]= post_body ? Buffer.byteLength(post_body) : 0;
|
||||
headers["Content-Type"]= post_content_type;
|
||||
|
||||
var path;
|
||||
if( !parsedUrl.pathname || parsedUrl.pathname == "" ) parsedUrl.pathname ="/";
|
||||
if( parsedUrl.query ) path= parsedUrl.pathname + "?"+ parsedUrl.query ;
|
||||
else path= parsedUrl.pathname;
|
||||
|
||||
var request;
|
||||
if( parsedUrl.protocol == "https:" ) {
|
||||
request= this._createClient(parsedUrl.port, parsedUrl.hostname, method, path, headers, true);
|
||||
}
|
||||
else {
|
||||
request= this._createClient(parsedUrl.port, parsedUrl.hostname, method, path, headers);
|
||||
}
|
||||
|
||||
if( callback ) {
|
||||
var data="";
|
||||
var self= this;
|
||||
|
||||
// Some hosts *cough* google appear to close the connection early / send no content-length header
|
||||
// allow this behaviour.
|
||||
var allowEarlyClose= OAuthUtils.isAnEarlyCloseHost( parsedUrl.hostname );
|
||||
var callbackCalled= false;
|
||||
function passBackControl( response ) {
|
||||
if(!callbackCalled) {
|
||||
callbackCalled= true;
|
||||
if ( response.statusCode >= 200 && response.statusCode <= 299 ) {
|
||||
callback(null, data, response);
|
||||
} else {
|
||||
// Follow 301 or 302 redirects with Location HTTP header
|
||||
if((response.statusCode == 301 || response.statusCode == 302) && response.headers && response.headers.location) {
|
||||
self._performSecureRequest( oauth_token, oauth_token_secret, method, response.headers.location, extra_params, post_body, post_content_type, callback);
|
||||
}
|
||||
else {
|
||||
callback({ statusCode: response.statusCode, data: data }, data, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
request.on('response', function (response) {
|
||||
response.setEncoding('utf8');
|
||||
response.on('data', function (chunk) {
|
||||
data+=chunk;
|
||||
});
|
||||
response.on('end', function () {
|
||||
passBackControl( response );
|
||||
});
|
||||
response.on('close', function () {
|
||||
if( allowEarlyClose ) {
|
||||
passBackControl( response );
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
request.on("error", function(err) {
|
||||
callbackCalled= true;
|
||||
callback( err )
|
||||
});
|
||||
|
||||
if( (method == "POST" || method =="PUT") && post_body != null && post_body != "" ) {
|
||||
request.write(post_body);
|
||||
}
|
||||
request.end();
|
||||
}
|
||||
else {
|
||||
if( (method == "POST" || method =="PUT") && post_body != null && post_body != "" ) {
|
||||
request.write(post_body);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
exports.OAuth.prototype.setClientOptions= function(options) {
|
||||
var key,
|
||||
mergedOptions= {},
|
||||
hasOwnProperty= Object.prototype.hasOwnProperty;
|
||||
|
||||
for( key in this._defaultClientOptions ) {
|
||||
if( !hasOwnProperty.call(options, key) ) {
|
||||
mergedOptions[key]= this._defaultClientOptions[key];
|
||||
} else {
|
||||
mergedOptions[key]= options[key];
|
||||
}
|
||||
}
|
||||
|
||||
this._clientOptions= mergedOptions;
|
||||
};
|
||||
|
||||
exports.OAuth.prototype.getOAuthAccessToken= function(oauth_token, oauth_token_secret, oauth_verifier, callback) {
|
||||
var extraParams= {};
|
||||
if( typeof oauth_verifier == "function" ) {
|
||||
callback= oauth_verifier;
|
||||
} else {
|
||||
extraParams.oauth_verifier= oauth_verifier;
|
||||
}
|
||||
|
||||
this._performSecureRequest( oauth_token, oauth_token_secret, this._clientOptions.accessTokenHttpMethod, this._accessUrl, extraParams, null, null, function(error, data, response) {
|
||||
if( error ) callback(error);
|
||||
else {
|
||||
var results= querystring.parse( data );
|
||||
var oauth_access_token= results["oauth_token"];
|
||||
delete results["oauth_token"];
|
||||
var oauth_access_token_secret= results["oauth_token_secret"];
|
||||
delete results["oauth_token_secret"];
|
||||
callback(null, oauth_access_token, oauth_access_token_secret, results );
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
exports.OAuth.prototype.getProtectedResource= function(url, method, oauth_token, oauth_token_secret, callback) {
|
||||
this._performSecureRequest( oauth_token, oauth_token_secret, method, url, null, "", null, callback );
|
||||
}
|
||||
|
||||
exports.OAuth.prototype.delete= function(url, oauth_token, oauth_token_secret, callback) {
|
||||
return this._performSecureRequest( oauth_token, oauth_token_secret, "DELETE", url, null, "", null, callback );
|
||||
}
|
||||
|
||||
exports.OAuth.prototype.get= function(url, oauth_token, oauth_token_secret, callback) {
|
||||
return this._performSecureRequest( oauth_token, oauth_token_secret, "GET", url, null, "", null, callback );
|
||||
}
|
||||
|
||||
exports.OAuth.prototype._putOrPost= function(method, url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
|
||||
var extra_params= null;
|
||||
if( typeof post_content_type == "function" ) {
|
||||
callback= post_content_type;
|
||||
post_content_type= null;
|
||||
}
|
||||
if( typeof post_body != "string" ) {
|
||||
post_content_type= "application/x-www-form-urlencoded"
|
||||
extra_params= post_body;
|
||||
post_body= null;
|
||||
}
|
||||
return this._performSecureRequest( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback );
|
||||
}
|
||||
|
||||
|
||||
exports.OAuth.prototype.put= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
|
||||
return this._putOrPost("PUT", url, oauth_token, oauth_token_secret, post_body, post_content_type, callback);
|
||||
}
|
||||
|
||||
exports.OAuth.prototype.post= function(url, oauth_token, oauth_token_secret, post_body, post_content_type, callback) {
|
||||
return this._putOrPost("POST", url, oauth_token, oauth_token_secret, post_body, post_content_type, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a request token from the OAuth provider and passes that information back
|
||||
* to the calling code.
|
||||
*
|
||||
* The callback should expect a function of the following form:
|
||||
*
|
||||
* function(err, token, token_secret, parsedQueryString) {}
|
||||
*
|
||||
* This method has optional parameters so can be called in the following 2 ways:
|
||||
*
|
||||
* 1) Primary use case: Does a basic request with no extra parameters
|
||||
* getOAuthRequestToken( callbackFunction )
|
||||
*
|
||||
* 2) As above but allows for provision of extra parameters to be sent as part of the query to the server.
|
||||
* getOAuthRequestToken( extraParams, callbackFunction )
|
||||
*
|
||||
* N.B. This method will HTTP POST verbs by default, if you wish to override this behaviour you will
|
||||
* need to provide a requestTokenHttpMethod option when creating the client.
|
||||
*
|
||||
**/
|
||||
exports.OAuth.prototype.getOAuthRequestToken= function( extraParams, callback ) {
|
||||
if( typeof extraParams == "function" ){
|
||||
callback = extraParams;
|
||||
extraParams = {};
|
||||
}
|
||||
// Callbacks are 1.0A related
|
||||
if( this._authorize_callback ) {
|
||||
extraParams["oauth_callback"]= this._authorize_callback;
|
||||
}
|
||||
this._performSecureRequest( null, null, this._clientOptions.requestTokenHttpMethod, this._requestUrl, extraParams, null, null, function(error, data, response) {
|
||||
if( error ) callback(error);
|
||||
else {
|
||||
var results= querystring.parse(data);
|
||||
|
||||
var oauth_token= results["oauth_token"];
|
||||
var oauth_token_secret= results["oauth_token_secret"];
|
||||
delete results["oauth_token"];
|
||||
delete results["oauth_token_secret"];
|
||||
callback(null, oauth_token, oauth_token_secret, results );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.OAuth.prototype.signUrl= function(url, oauth_token, oauth_token_secret, method) {
|
||||
|
||||
if( method === undefined ) {
|
||||
var method= "GET";
|
||||
}
|
||||
|
||||
var orderedParameters= this._prepareParameters(oauth_token, oauth_token_secret, method, url, {});
|
||||
var parsedUrl= URL.parse( url, false );
|
||||
|
||||
var query="";
|
||||
for( var i= 0 ; i < orderedParameters.length; i++) {
|
||||
query+= orderedParameters[i][0]+"="+ this._encodeData(orderedParameters[i][1]) + "&";
|
||||
}
|
||||
query= query.substring(0, query.length-1);
|
||||
|
||||
return parsedUrl.protocol + "//"+ parsedUrl.host + parsedUrl.pathname + "?" + query;
|
||||
};
|
||||
|
||||
exports.OAuth.prototype.authHeader= function(url, oauth_token, oauth_token_secret, method) {
|
||||
if( method === undefined ) {
|
||||
var method= "GET";
|
||||
}
|
||||
|
||||
var orderedParameters= this._prepareParameters(oauth_token, oauth_token_secret, method, url, {});
|
||||
return this._buildAuthorizationHeaders(orderedParameters);
|
||||
};
|
197
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/oauth2.js
generated
vendored
Normal file
197
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/oauth2.js
generated
vendored
Normal file
@ -0,0 +1,197 @@
|
||||
var querystring= require('querystring'),
|
||||
crypto= require('crypto'),
|
||||
https= require('https'),
|
||||
http= require('http'),
|
||||
URL= require('url'),
|
||||
OAuthUtils= require('./_utils');
|
||||
|
||||
exports.OAuth2= function(clientId, clientSecret, baseSite, authorizePath, accessTokenPath, customHeaders) {
|
||||
this._clientId= clientId;
|
||||
this._clientSecret= clientSecret;
|
||||
this._baseSite= baseSite;
|
||||
this._authorizeUrl= authorizePath || "/oauth/authorize";
|
||||
this._accessTokenUrl= accessTokenPath || "/oauth/access_token";
|
||||
this._accessTokenName= "access_token";
|
||||
this._authMethod= "Bearer";
|
||||
this._customHeaders = customHeaders || {};
|
||||
this._useAuthorizationHeaderForGET= false;
|
||||
}
|
||||
|
||||
// This 'hack' method is required for sites that don't use
|
||||
// 'access_token' as the name of the access token (for requests).
|
||||
// ( http://tools.ietf.org/html/draft-ietf-oauth-v2-16#section-7 )
|
||||
// it isn't clear what the correct value should be atm, so allowing
|
||||
// for specific (temporary?) override for now.
|
||||
exports.OAuth2.prototype.setAccessTokenName= function ( name ) {
|
||||
this._accessTokenName= name;
|
||||
}
|
||||
|
||||
// Sets the authorization method for Authorization header.
|
||||
// e.g. Authorization: Bearer <token> # "Bearer" is the authorization method.
|
||||
exports.OAuth2.prototype.setAuthMethod = function ( authMethod ) {
|
||||
this._authMethod = authMethod;
|
||||
};
|
||||
|
||||
|
||||
// If you use the OAuth2 exposed 'get' method (and don't construct your own _request call )
|
||||
// this will specify whether to use an 'Authorize' header instead of passing the access_token as a query parameter
|
||||
exports.OAuth2.prototype.useAuthorizationHeaderforGET = function(useIt) {
|
||||
this._useAuthorizationHeaderForGET= useIt;
|
||||
}
|
||||
|
||||
exports.OAuth2.prototype._getAccessTokenUrl= function() {
|
||||
return this._baseSite + this._accessTokenUrl; /* + "?" + querystring.stringify(params); */
|
||||
}
|
||||
|
||||
// Build the authorization header. In particular, build the part after the colon.
|
||||
// e.g. Authorization: Bearer <token> # Build "Bearer <token>"
|
||||
exports.OAuth2.prototype.buildAuthHeader= function(token) {
|
||||
return this._authMethod + ' ' + token;
|
||||
};
|
||||
|
||||
exports.OAuth2.prototype._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
|
||||
var http_library= https;
|
||||
var creds = crypto.createCredentials({ });
|
||||
var parsedUrl= URL.parse( url, true );
|
||||
if( parsedUrl.protocol == "https:" && !parsedUrl.port ) {
|
||||
parsedUrl.port= 443;
|
||||
}
|
||||
|
||||
// As this is OAUth2, we *assume* https unless told explicitly otherwise.
|
||||
if( parsedUrl.protocol != "https:" ) {
|
||||
http_library= http;
|
||||
}
|
||||
|
||||
var realHeaders= {};
|
||||
for( var key in this._customHeaders ) {
|
||||
realHeaders[key]= this._customHeaders[key];
|
||||
}
|
||||
if( headers ) {
|
||||
for(var key in headers) {
|
||||
realHeaders[key] = headers[key];
|
||||
}
|
||||
}
|
||||
realHeaders['Host']= parsedUrl.host;
|
||||
|
||||
realHeaders['Content-Length']= post_body ? Buffer.byteLength(post_body) : 0;
|
||||
if( access_token && !('Authorization' in realHeaders)) {
|
||||
if( ! parsedUrl.query ) parsedUrl.query= {};
|
||||
parsedUrl.query[this._accessTokenName]= access_token;
|
||||
}
|
||||
|
||||
var queryStr= querystring.stringify(parsedUrl.query);
|
||||
if( queryStr ) queryStr= "?" + queryStr;
|
||||
var options = {
|
||||
host:parsedUrl.hostname,
|
||||
port: parsedUrl.port,
|
||||
path: parsedUrl.pathname + queryStr,
|
||||
method: method,
|
||||
headers: realHeaders
|
||||
};
|
||||
|
||||
this._executeRequest( http_library, options, post_body, callback );
|
||||
}
|
||||
|
||||
exports.OAuth2.prototype._executeRequest= function( http_library, options, post_body, callback ) {
|
||||
// Some hosts *cough* google appear to close the connection early / send no content-length header
|
||||
// allow this behaviour.
|
||||
var allowEarlyClose= OAuthUtils.isAnEarlyCloseHost(options.host);
|
||||
var callbackCalled= false;
|
||||
function passBackControl( response, result ) {
|
||||
if(!callbackCalled) {
|
||||
callbackCalled=true;
|
||||
if( response.statusCode != 200 && (response.statusCode != 301) && (response.statusCode != 302) ) {
|
||||
callback({ statusCode: response.statusCode, data: result });
|
||||
} else {
|
||||
callback(null, result, response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var result= "";
|
||||
|
||||
var request = http_library.request(options, function (response) {
|
||||
response.on("data", function (chunk) {
|
||||
result+= chunk
|
||||
});
|
||||
response.on("close", function (err) {
|
||||
if( allowEarlyClose ) {
|
||||
passBackControl( response, result );
|
||||
}
|
||||
});
|
||||
response.addListener("end", function () {
|
||||
passBackControl( response, result );
|
||||
});
|
||||
});
|
||||
request.on('error', function(e) {
|
||||
callbackCalled= true;
|
||||
callback(e);
|
||||
});
|
||||
|
||||
if( options.method == 'POST' && post_body ) {
|
||||
request.write(post_body);
|
||||
}
|
||||
request.end();
|
||||
}
|
||||
|
||||
exports.OAuth2.prototype.getAuthorizeUrl= function( params ) {
|
||||
var params= params || {};
|
||||
params['client_id'] = this._clientId;
|
||||
params['type'] = 'web_server';
|
||||
return this._baseSite + this._authorizeUrl + "?" + querystring.stringify(params);
|
||||
}
|
||||
|
||||
exports.OAuth2.prototype.getOAuthAccessToken= function(code, params, callback) {
|
||||
var params= params || {};
|
||||
params['client_id'] = this._clientId;
|
||||
params['client_secret'] = this._clientSecret;
|
||||
params['type']= 'web_server';
|
||||
var codeParam = (params.grant_type === 'refresh_token') ? 'refresh_token' : 'code';
|
||||
params[codeParam]= code;
|
||||
|
||||
var post_data= querystring.stringify( params );
|
||||
var post_headers= {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
};
|
||||
|
||||
|
||||
this._request("POST", this._getAccessTokenUrl(), post_headers, post_data, null, function(error, data, response) {
|
||||
if( error ) callback(error);
|
||||
else {
|
||||
var results;
|
||||
try {
|
||||
// As of http://tools.ietf.org/html/draft-ietf-oauth-v2-07
|
||||
// responses should be in JSON
|
||||
results= JSON.parse( data );
|
||||
}
|
||||
catch(e) {
|
||||
// .... However both Facebook + Github currently use rev05 of the spec
|
||||
// and neither seem to specify a content-type correctly in their response headers :(
|
||||
// clients of these services will suffer a *minor* performance cost of the exception
|
||||
// being thrown
|
||||
results= querystring.parse( data );
|
||||
}
|
||||
var access_token= results["access_token"];
|
||||
var refresh_token= results["refresh_token"];
|
||||
delete results["refresh_token"];
|
||||
callback(null, access_token, refresh_token, results); // callback results =-=
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
exports.OAuth2.prototype.getProtectedResource= function(url, access_token, callback) {
|
||||
this._request("GET", url, {}, "", access_token, callback );
|
||||
}
|
||||
|
||||
exports.OAuth2.prototype.get= function(url, access_token, callback) {
|
||||
if( this._useAuthorizationHeaderForGET ) {
|
||||
var headers= {'Authorization': this.buildAuthHeader(access_token) }
|
||||
access_token= null;
|
||||
}
|
||||
else {
|
||||
headers= {};
|
||||
}
|
||||
this._request("GET", url, headers, "", access_token, callback );
|
||||
}
|
334
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/sha1.js
generated
vendored
Normal file
334
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/lib/sha1.js
generated
vendored
Normal file
@ -0,0 +1,334 @@
|
||||
/*
|
||||
* A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
|
||||
* in FIPS 180-1
|
||||
* Version 2.2 Copyright Paul Johnston 2000 - 2009.
|
||||
* Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
|
||||
* Distributed under the BSD License
|
||||
* See http://pajhome.org.uk/crypt/md5 for details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Configurable variables. You may need to tweak these to be compatible with
|
||||
* the server-side, but the defaults work in most cases.
|
||||
*/
|
||||
var hexcase = 1; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||
var b64pad = "="; /* base-64 pad character. "=" for strict RFC compliance */
|
||||
|
||||
/*
|
||||
* These are the functions you'll usually want to call
|
||||
* They take string arguments and return either hex or base-64 encoded strings
|
||||
*/
|
||||
function hex_sha1(s) { return rstr2hex(rstr_sha1(str2rstr_utf8(s))); }
|
||||
function b64_sha1(s) { return rstr2b64(rstr_sha1(str2rstr_utf8(s))); }
|
||||
function any_sha1(s, e) { return rstr2any(rstr_sha1(str2rstr_utf8(s)), e); }
|
||||
function hex_hmac_sha1(k, d)
|
||||
{ return rstr2hex(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||
function b64_hmac_sha1(k, d)
|
||||
{ return rstr2b64(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d))); }
|
||||
function any_hmac_sha1(k, d, e)
|
||||
{ return rstr2any(rstr_hmac_sha1(str2rstr_utf8(k), str2rstr_utf8(d)), e); }
|
||||
|
||||
/*
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
*/
|
||||
function sha1_vm_test()
|
||||
{
|
||||
return hex_sha1("abc").toLowerCase() == "a9993e364706816aba3e25717850c26c9cd0d89d";
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the SHA1 of a raw string
|
||||
*/
|
||||
function rstr_sha1(s)
|
||||
{
|
||||
return binb2rstr(binb_sha1(rstr2binb(s), s.length * 8));
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-SHA1 of a key and some data (raw strings)
|
||||
*/
|
||||
function rstr_hmac_sha1(key, data)
|
||||
{
|
||||
var bkey = rstr2binb(key);
|
||||
if(bkey.length > 16) bkey = binb_sha1(bkey, key.length * 8);
|
||||
|
||||
var ipad = Array(16), opad = Array(16);
|
||||
for(var i = 0; i < 16; i++)
|
||||
{
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
var hash = binb_sha1(ipad.concat(rstr2binb(data)), 512 + data.length * 8);
|
||||
return binb2rstr(binb_sha1(opad.concat(hash), 512 + 160));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to a hex string
|
||||
*/
|
||||
function rstr2hex(input)
|
||||
{
|
||||
try { hexcase } catch(e) { hexcase=0; }
|
||||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
var output = "";
|
||||
var x;
|
||||
for(var i = 0; i < input.length; i++)
|
||||
{
|
||||
x = input.charCodeAt(i);
|
||||
output += hex_tab.charAt((x >>> 4) & 0x0F)
|
||||
+ hex_tab.charAt( x & 0x0F);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to a base-64 string
|
||||
*/
|
||||
function rstr2b64(input)
|
||||
{
|
||||
try { b64pad } catch(e) { b64pad=''; }
|
||||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var output = "";
|
||||
var len = input.length;
|
||||
for(var i = 0; i < len; i += 3)
|
||||
{
|
||||
var triplet = (input.charCodeAt(i) << 16)
|
||||
| (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0)
|
||||
| (i + 2 < len ? input.charCodeAt(i+2) : 0);
|
||||
for(var j = 0; j < 4; j++)
|
||||
{
|
||||
if(i * 8 + j * 6 > input.length * 8) output += b64pad;
|
||||
else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to an arbitrary string encoding
|
||||
*/
|
||||
function rstr2any(input, encoding)
|
||||
{
|
||||
var divisor = encoding.length;
|
||||
var remainders = Array();
|
||||
var i, q, x, quotient;
|
||||
|
||||
/* Convert to an array of 16-bit big-endian values, forming the dividend */
|
||||
var dividend = Array(Math.ceil(input.length / 2));
|
||||
for(i = 0; i < dividend.length; i++)
|
||||
{
|
||||
dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Repeatedly perform a long division. The binary array forms the dividend,
|
||||
* the length of the encoding is the divisor. Once computed, the quotient
|
||||
* forms the dividend for the next step. We stop when the dividend is zero.
|
||||
* All remainders are stored for later use.
|
||||
*/
|
||||
while(dividend.length > 0)
|
||||
{
|
||||
quotient = Array();
|
||||
x = 0;
|
||||
for(i = 0; i < dividend.length; i++)
|
||||
{
|
||||
x = (x << 16) + dividend[i];
|
||||
q = Math.floor(x / divisor);
|
||||
x -= q * divisor;
|
||||
if(quotient.length > 0 || q > 0)
|
||||
quotient[quotient.length] = q;
|
||||
}
|
||||
remainders[remainders.length] = x;
|
||||
dividend = quotient;
|
||||
}
|
||||
|
||||
/* Convert the remainders to the output string */
|
||||
var output = "";
|
||||
for(i = remainders.length - 1; i >= 0; i--)
|
||||
output += encoding.charAt(remainders[i]);
|
||||
|
||||
/* Append leading zero equivalents */
|
||||
var full_length = Math.ceil(input.length * 8 /
|
||||
(Math.log(encoding.length) / Math.log(2)))
|
||||
for(i = output.length; i < full_length; i++)
|
||||
output = encoding[0] + output;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a string as utf-8.
|
||||
* For efficiency, this assumes the input is valid utf-16.
|
||||
*/
|
||||
function str2rstr_utf8(input)
|
||||
{
|
||||
var output = "";
|
||||
var i = -1;
|
||||
var x, y;
|
||||
|
||||
while(++i < input.length)
|
||||
{
|
||||
/* Decode utf-16 surrogate pairs */
|
||||
x = input.charCodeAt(i);
|
||||
y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
|
||||
if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
|
||||
{
|
||||
x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Encode output as utf-8 */
|
||||
if(x <= 0x7F)
|
||||
output += String.fromCharCode(x);
|
||||
else if(x <= 0x7FF)
|
||||
output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
|
||||
0x80 | ( x & 0x3F));
|
||||
else if(x <= 0xFFFF)
|
||||
output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
|
||||
0x80 | ((x >>> 6 ) & 0x3F),
|
||||
0x80 | ( x & 0x3F));
|
||||
else if(x <= 0x1FFFFF)
|
||||
output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
|
||||
0x80 | ((x >>> 12) & 0x3F),
|
||||
0x80 | ((x >>> 6 ) & 0x3F),
|
||||
0x80 | ( x & 0x3F));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Encode a string as utf-16
|
||||
*/
|
||||
function str2rstr_utf16le(input)
|
||||
{
|
||||
var output = "";
|
||||
for(var i = 0; i < input.length; i++)
|
||||
output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
|
||||
(input.charCodeAt(i) >>> 8) & 0xFF);
|
||||
return output;
|
||||
}
|
||||
|
||||
function str2rstr_utf16be(input)
|
||||
{
|
||||
var output = "";
|
||||
for(var i = 0; i < input.length; i++)
|
||||
output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF,
|
||||
input.charCodeAt(i) & 0xFF);
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a raw string to an array of big-endian words
|
||||
* Characters >255 have their high-byte silently ignored.
|
||||
*/
|
||||
function rstr2binb(input)
|
||||
{
|
||||
var output = Array(input.length >> 2);
|
||||
for(var i = 0; i < output.length; i++)
|
||||
output[i] = 0;
|
||||
for(var i = 0; i < input.length * 8; i += 8)
|
||||
output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of big-endian words to a string
|
||||
*/
|
||||
function binb2rstr(input)
|
||||
{
|
||||
var output = "";
|
||||
for(var i = 0; i < input.length * 32; i += 8)
|
||||
output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the SHA-1 of an array of big-endian words, and a bit length
|
||||
*/
|
||||
function binb_sha1(x, len)
|
||||
{
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << (24 - len % 32);
|
||||
x[((len + 64 >> 9) << 4) + 15] = len;
|
||||
|
||||
var w = Array(80);
|
||||
var a = 1732584193;
|
||||
var b = -271733879;
|
||||
var c = -1732584194;
|
||||
var d = 271733878;
|
||||
var e = -1009589776;
|
||||
|
||||
for(var i = 0; i < x.length; i += 16)
|
||||
{
|
||||
var olda = a;
|
||||
var oldb = b;
|
||||
var oldc = c;
|
||||
var oldd = d;
|
||||
var olde = e;
|
||||
|
||||
for(var j = 0; j < 80; j++)
|
||||
{
|
||||
if(j < 16) w[j] = x[i + j];
|
||||
else w[j] = bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
|
||||
var t = safe_add(safe_add(bit_rol(a, 5), sha1_ft(j, b, c, d)),
|
||||
safe_add(safe_add(e, w[j]), sha1_kt(j)));
|
||||
e = d;
|
||||
d = c;
|
||||
c = bit_rol(b, 30);
|
||||
b = a;
|
||||
a = t;
|
||||
}
|
||||
|
||||
a = safe_add(a, olda);
|
||||
b = safe_add(b, oldb);
|
||||
c = safe_add(c, oldc);
|
||||
d = safe_add(d, oldd);
|
||||
e = safe_add(e, olde);
|
||||
}
|
||||
return Array(a, b, c, d, e);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Perform the appropriate triplet combination function for the current
|
||||
* iteration
|
||||
*/
|
||||
function sha1_ft(t, b, c, d)
|
||||
{
|
||||
if(t < 20) return (b & c) | ((~b) & d);
|
||||
if(t < 40) return b ^ c ^ d;
|
||||
if(t < 60) return (b & c) | (b & d) | (c & d);
|
||||
return b ^ c ^ d;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine the appropriate additive constant for the current iteration
|
||||
*/
|
||||
function sha1_kt(t)
|
||||
{
|
||||
return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
|
||||
(t < 60) ? -1894007588 : -899497514;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add(x, y)
|
||||
{
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function bit_rol(num, cnt)
|
||||
{
|
||||
return (num << cnt) | (num >>> (32 - cnt));
|
||||
}
|
||||
|
||||
exports.HMACSHA1= function(key, data) {
|
||||
return b64_hmac_sha1(key, data);
|
||||
}
|
37
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/package.json
generated
vendored
Normal file
37
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/package.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
792
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/tests/oauth.js
generated
vendored
Normal file
792
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/tests/oauth.js
generated
vendored
Normal file
@ -0,0 +1,792 @@
|
||||
var vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
events = require('events'),
|
||||
OAuth= require('../lib/oauth').OAuth,
|
||||
OAuthEcho= require('../lib/oauth').OAuthEcho;
|
||||
|
||||
var DummyResponse =function( statusCode ) {
|
||||
this.statusCode= statusCode;
|
||||
this.headers= {};
|
||||
}
|
||||
DummyResponse.prototype= events.EventEmitter.prototype;
|
||||
DummyResponse.prototype.setEncoding= function() {}
|
||||
|
||||
var DummyRequest =function( response ) {
|
||||
this.response= response;
|
||||
}
|
||||
DummyRequest.prototype= events.EventEmitter.prototype;
|
||||
DummyRequest.prototype.write= function(post_body){}
|
||||
DummyRequest.prototype.write= function(post_body){
|
||||
this.emit('response',this.response);
|
||||
}
|
||||
DummyRequest.prototype.end= function(){
|
||||
this.response.emit('end');
|
||||
}
|
||||
|
||||
vows.describe('OAuth').addBatch({
|
||||
'When generating the signature base string described in http://oauth.net/core/1.0/#sig_base_example': {
|
||||
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
'we get the expected result string': function (oa) {
|
||||
var result= oa._createSignatureBase("GET", "http://photos.example.net/photos",
|
||||
"file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original")
|
||||
assert.equal( result, "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal");
|
||||
}
|
||||
},
|
||||
'When generating the signature base string with PLAINTEXT': {
|
||||
topic: new OAuth(null, null, null, null, null, null, "PLAINTEXT"),
|
||||
'we get the expected result string': function (oa) {
|
||||
var result= oa._getSignature("GET", "http://photos.example.net/photos",
|
||||
"file=vacation.jpg&oauth_consumer_key=dpf43f3p2l4k3l03&oauth_nonce=kllo9940pd9333jh&oauth_signature_method=PLAINTEXT&oauth_timestamp=1191242096&oauth_token=nnch734d00sl2jdk&oauth_version=1.0&size=original",
|
||||
"test");
|
||||
assert.equal( result, "&test");
|
||||
}
|
||||
},
|
||||
'When normalising a url': {
|
||||
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
'default ports should be stripped': function(oa) {
|
||||
assert.equal( oa._normalizeUrl("https://somehost.com:443/foo/bar"), "https://somehost.com/foo/bar" );
|
||||
},
|
||||
'should leave in non-default ports from urls for use in signature generation': function(oa) {
|
||||
assert.equal( oa._normalizeUrl("https://somehost.com:446/foo/bar"), "https://somehost.com:446/foo/bar" );
|
||||
assert.equal( oa._normalizeUrl("http://somehost.com:81/foo/bar"), "http://somehost.com:81/foo/bar" );
|
||||
},
|
||||
'should add a trailing slash when no path at all is present': function(oa) {
|
||||
assert.equal( oa._normalizeUrl("http://somehost.com"), "http://somehost.com/")
|
||||
}
|
||||
},
|
||||
'When making an array out of the arguments hash' : {
|
||||
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
'flatten out arguments that are arrays' : function(oa) {
|
||||
var parameters= {"z": "a",
|
||||
"a": ["1", "2"],
|
||||
"1": "c" };
|
||||
var parameterResults= oa._makeArrayOfArgumentsHash(parameters);
|
||||
assert.equal(parameterResults.length, 4);
|
||||
assert.equal(parameterResults[0][0], "1");
|
||||
assert.equal(parameterResults[1][0], "z");
|
||||
assert.equal(parameterResults[2][0], "a");
|
||||
assert.equal(parameterResults[3][0], "a");
|
||||
}
|
||||
},
|
||||
'When ordering the request parameters' : {
|
||||
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
'Order them by name' : function(oa) {
|
||||
var parameters= {"z": "a",
|
||||
"a": "b",
|
||||
"1": "c" };
|
||||
var parameterResults= oa._sortRequestParams(oa._makeArrayOfArgumentsHash(parameters))
|
||||
assert.equal(parameterResults[0][0], "1");
|
||||
assert.equal(parameterResults[1][0], "a");
|
||||
assert.equal(parameterResults[2][0], "z");
|
||||
},
|
||||
'If two parameter names are the same then order by the value': function(oa) {
|
||||
var parameters= {"z": "a",
|
||||
"a": ["z", "b", "b", "a", "y"],
|
||||
"1": "c" };
|
||||
var parameterResults= oa._sortRequestParams(oa._makeArrayOfArgumentsHash(parameters))
|
||||
assert.equal(parameterResults[0][0], "1");
|
||||
assert.equal(parameterResults[1][0], "a");
|
||||
assert.equal(parameterResults[1][1], "a");
|
||||
assert.equal(parameterResults[2][0], "a");
|
||||
assert.equal(parameterResults[2][1], "b");
|
||||
assert.equal(parameterResults[3][0], "a");
|
||||
assert.equal(parameterResults[3][1], "b");
|
||||
assert.equal(parameterResults[4][0], "a");
|
||||
assert.equal(parameterResults[4][1], "y");
|
||||
assert.equal(parameterResults[5][0], "a");
|
||||
assert.equal(parameterResults[5][1], "z");
|
||||
assert.equal(parameterResults[6][0], "z");
|
||||
}
|
||||
},
|
||||
'When normalising the request parameters': {
|
||||
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
'the resulting parameters should be encoded and ordered as per http://tools.ietf.org/html/rfc5849#section-3.1 (3.4.1.3.2)' : function(oa) {
|
||||
var parameters= {"b5" : "=%3D",
|
||||
"a3": ["a", "2 q"],
|
||||
"c@": "",
|
||||
"a2": "r b",
|
||||
"oauth_consumer_key": "9djdj82h48djs9d2",
|
||||
"oauth_token":"kkk9d7dh3k39sjv7",
|
||||
"oauth_signature_method": "HMAC-SHA1",
|
||||
"oauth_timestamp": "137131201",
|
||||
"oauth_nonce": "7d8f3e4a",
|
||||
"c2" : ""};
|
||||
var normalisedParameterString= oa._normaliseRequestParams(parameters);
|
||||
assert.equal(normalisedParameterString, "a2=r%20b&a3=2%20q&a3=a&b5=%3D%253D&c%40=&c2=&oauth_consumer_key=9djdj82h48djs9d2&oauth_nonce=7d8f3e4a&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131201&oauth_token=kkk9d7dh3k39sjv7");
|
||||
}
|
||||
},
|
||||
'When preparing the parameters for use in signing': {
|
||||
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
'We need to be wary of node\'s auto object creation from foo[bar] style url parameters' : function(oa) {
|
||||
var result= oa._prepareParameters( "", "", "", "http://foo.com?foo[bar]=xxx&bar[foo]=yyy", {} );
|
||||
assert.equal( result[0][0], "bar[foo]")
|
||||
assert.equal( result[0][1], "yyy")
|
||||
assert.equal( result[1][0], "foo[bar]")
|
||||
assert.equal( result[1][1], "xxx")
|
||||
}
|
||||
},
|
||||
'When signing a url': {
|
||||
topic: function() {
|
||||
var oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");
|
||||
oa._getTimestamp= function(){ return "1272399856"; }
|
||||
oa._getNonce= function(){ return "ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp"; }
|
||||
return oa;
|
||||
},
|
||||
'Provide a valid signature when no token present': function(oa) {
|
||||
assert.equal( oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo"), "http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_version=1.0&oauth_signature=7ytO8vPSLut2GzHjU9pn1SV9xjc%3D");
|
||||
},
|
||||
'Provide a valid signature when a token is present': function(oa) {
|
||||
assert.equal( oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo", "token"), "http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_token=token&oauth_version=1.0&oauth_signature=9LwCuCWw5sURtpMroIolU3YwsdI%3D");
|
||||
},
|
||||
'Provide a valid signature when a token and a token secret is present': function(oa) {
|
||||
assert.equal( oa.signUrl("http://somehost.com:3323/foo/poop?bar=foo", "token", "tokensecret"), "http://somehost.com:3323/foo/poop?bar=foo&oauth_consumer_key=consumerkey&oauth_nonce=ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1272399856&oauth_token=token&oauth_version=1.0&oauth_signature=zeOR0Wsm6EG6XSg0Vw%2FsbpoSib8%3D");
|
||||
}
|
||||
},
|
||||
'When getting a request token': {
|
||||
topic: function() {
|
||||
var oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");
|
||||
oa._getTimestamp= function(){ return "1272399856"; }
|
||||
oa._getNonce= function(){ return "ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp"; }
|
||||
oa._performSecureRequest= function(){ return this.requestArguments = arguments; }
|
||||
return oa;
|
||||
},
|
||||
'Use the HTTP method in the client options': function(oa) {
|
||||
oa.setClientOptions({ requestTokenHttpMethod: "GET" });
|
||||
oa.getOAuthRequestToken(function() {});
|
||||
assert.equal(oa.requestArguments[2], "GET");
|
||||
},
|
||||
'Use a POST by default': function(oa) {
|
||||
oa.setClientOptions({});
|
||||
oa.getOAuthRequestToken(function() {});
|
||||
assert.equal(oa.requestArguments[2], "POST");
|
||||
}
|
||||
},
|
||||
'When getting an access token': {
|
||||
topic: function() {
|
||||
var oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");
|
||||
oa._getTimestamp= function(){ return "1272399856"; }
|
||||
oa._getNonce= function(){ return "ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp"; }
|
||||
oa._performSecureRequest= function(){ return this.requestArguments = arguments; }
|
||||
return oa;
|
||||
},
|
||||
'Use the HTTP method in the client options': function(oa) {
|
||||
oa.setClientOptions({ accessTokenHttpMethod: "GET" });
|
||||
oa.getOAuthAccessToken(function() {});
|
||||
assert.equal(oa.requestArguments[2], "GET");
|
||||
},
|
||||
'Use a POST by default': function(oa) {
|
||||
oa.setClientOptions({});
|
||||
oa.getOAuthAccessToken(function() {});
|
||||
assert.equal(oa.requestArguments[2], "POST");
|
||||
}
|
||||
},
|
||||
'When get authorization header' : {
|
||||
topic: function() {
|
||||
var oa= new OAuth(null, null, "consumerkey", "consumersecret", "1.0", null, "HMAC-SHA1");
|
||||
oa._getTimestamp= function(){ return "1272399856"; }
|
||||
oa._getNonce= function(){ return "ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp"; }
|
||||
return oa;
|
||||
},
|
||||
'Provide a valid signature when a token and a token secret is present': function(oa) {
|
||||
assert.equal( oa.authHeader("http://somehost.com:3323/foo/poop?bar=foo", "token", "tokensecret"), 'OAuth oauth_consumer_key="consumerkey",oauth_nonce="ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1272399856",oauth_token="token",oauth_version="1.0",oauth_signature="zeOR0Wsm6EG6XSg0Vw%2FsbpoSib8%3D"');
|
||||
},
|
||||
'Support variable whitespace separating the arguments': function(oa) {
|
||||
oa._oauthParameterSeperator= ", ";
|
||||
assert.equal( oa.authHeader("http://somehost.com:3323/foo/poop?bar=foo", "token", "tokensecret"), 'OAuth oauth_consumer_key="consumerkey", oauth_nonce="ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1272399856", oauth_token="token", oauth_version="1.0", oauth_signature="zeOR0Wsm6EG6XSg0Vw%2FsbpoSib8%3D"');
|
||||
}
|
||||
},
|
||||
'When get the OAuth Echo authorization header': {
|
||||
topic: function () {
|
||||
var realm = "http://foobar.com/";
|
||||
var verifyCredentials = "http://api.foobar.com/verify.json";
|
||||
var oa = new OAuthEcho(realm, verifyCredentials, "consumerkey", "consumersecret", "1.0A", "HMAC-SHA1");
|
||||
oa._getTimestamp= function(){ return "1272399856"; }
|
||||
oa._getNonce= function(){ return "ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp"; }
|
||||
return oa;
|
||||
},
|
||||
'Provide a valid signature when a token and token secret is present': function (oa) {
|
||||
assert.equal( oa.authHeader("http://somehost.com:3323/foo/poop?bar=foo", "token", "tokensecret"), 'OAuth realm="http://foobar.com/",oauth_consumer_key="consumerkey",oauth_nonce="ybHPeOEkAUJ3k2wJT9Xb43MjtSgTvKqp",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1272399856",oauth_token="token",oauth_version="1.0A",oauth_signature="0rr1LhSxACX2IEWRq3uCb4IwtOs%3D"');
|
||||
}
|
||||
},
|
||||
'When non standard ports are used': {
|
||||
topic: function() {
|
||||
var oa= new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
mockProvider= {};
|
||||
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers.Host, "somehost.com:8080");
|
||||
assert.equal(hostname, "somehost.com");
|
||||
assert.equal(port, "8080");
|
||||
return {
|
||||
on: function() {},
|
||||
end: function() {}
|
||||
};
|
||||
}
|
||||
return oa;
|
||||
},
|
||||
'getProtectedResource should correctly define the host headers': function(oa) {
|
||||
oa.getProtectedResource("http://somehost.com:8080", "GET", "oauth_token", null, function(){})
|
||||
}
|
||||
},
|
||||
'When building the OAuth Authorization header': {
|
||||
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1"),
|
||||
'All provided oauth arguments should be concatentated correctly' : function(oa) {
|
||||
var parameters= [
|
||||
["oauth_timestamp", "1234567"],
|
||||
["oauth_nonce", "ABCDEF"],
|
||||
["oauth_version", "1.0"],
|
||||
["oauth_signature_method", "HMAC-SHA1"],
|
||||
["oauth_consumer_key", "asdasdnm2321b3"]];
|
||||
assert.equal(oa._buildAuthorizationHeaders(parameters), 'OAuth oauth_timestamp="1234567",oauth_nonce="ABCDEF",oauth_version="1.0",oauth_signature_method="HMAC-SHA1",oauth_consumer_key="asdasdnm2321b3"');
|
||||
},
|
||||
'*Only* Oauth arguments should be concatentated, others should be disregarded' : function(oa) {
|
||||
var parameters= [
|
||||
["foo", "2343"],
|
||||
["oauth_timestamp", "1234567"],
|
||||
["oauth_nonce", "ABCDEF"],
|
||||
["bar", "dfsdfd"],
|
||||
["oauth_version", "1.0"],
|
||||
["oauth_signature_method", "HMAC-SHA1"],
|
||||
["oauth_consumer_key", "asdasdnm2321b3"],
|
||||
["foobar", "asdasdnm2321b3"]];
|
||||
assert.equal(oa._buildAuthorizationHeaders(parameters), 'OAuth oauth_timestamp="1234567",oauth_nonce="ABCDEF",oauth_version="1.0",oauth_signature_method="HMAC-SHA1",oauth_consumer_key="asdasdnm2321b3"');
|
||||
},
|
||||
'_buildAuthorizationHeaders should not depends on Array.prototype.toString' : function(oa) {
|
||||
var _toString = Array.prototype.toString;
|
||||
Array.prototype.toString = function(){ return '[Array] ' + this.length; }; // toString overwrite example used in jsdom.
|
||||
var parameters= [
|
||||
["foo", "2343"],
|
||||
["oauth_timestamp", "1234567"],
|
||||
["oauth_nonce", "ABCDEF"],
|
||||
["bar", "dfsdfd"],
|
||||
["oauth_version", "1.0"],
|
||||
["oauth_signature_method", "HMAC-SHA1"],
|
||||
["oauth_consumer_key", "asdasdnm2321b3"],
|
||||
["foobar", "asdasdnm2321b3"]];
|
||||
assert.equal(oa._buildAuthorizationHeaders(parameters), 'OAuth oauth_timestamp="1234567",oauth_nonce="ABCDEF",oauth_version="1.0",oauth_signature_method="HMAC-SHA1",oauth_consumer_key="asdasdnm2321b3"');
|
||||
Array.prototype.toString = _toString;
|
||||
}
|
||||
},
|
||||
'When performing the Secure Request' : {
|
||||
topic: new OAuth("http://foo.com/RequestToken",
|
||||
"http://foo.com/AccessToken",
|
||||
"anonymous", "anonymous",
|
||||
"1.0A", "http://foo.com/callback", "HMAC-SHA1"),
|
||||
'using the POST method' : {
|
||||
'Any passed extra_params should form part of the POST body': function(oa) {
|
||||
var post_body_written= false;
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return {
|
||||
write: function(post_body){
|
||||
post_body_written= true;
|
||||
assert.equal(post_body,"scope=foobar%2C1%2C2");
|
||||
}
|
||||
};
|
||||
}
|
||||
oa._performSecureRequest("token", "token_secret", 'POST', 'http://foo.com/protected_resource', {"scope": "foobar,1,2"});
|
||||
assert.equal(post_body_written, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'When performing a secure' : {
|
||||
topic: new OAuth("http://foo.com/RequestToken",
|
||||
"http://foo.com/AccessToken",
|
||||
"anonymous", "anonymous",
|
||||
"1.0A", "http://foo.com/callback", "HMAC-SHA1"),
|
||||
'POST' : {
|
||||
'if no callback is passed' : {
|
||||
'it should return a request object': function(oa) {
|
||||
var request= oa.post("http://foo.com/blah", "token", "token_secret", "BLAH", "text/plain")
|
||||
assert.isObject(request);
|
||||
assert.equal(request.method, "POST");
|
||||
request.end();
|
||||
}
|
||||
},
|
||||
'if a callback is passed' : {
|
||||
"it should call the internal request's end method and return nothing": function(oa) {
|
||||
var callbackCalled= false;
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return {
|
||||
write: function(){},
|
||||
on: function() {},
|
||||
end: function() {
|
||||
callbackCalled= true;
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.post("http://foo.com/blah", "token", "token_secret", "BLAH", "text/plain", function(e,d){})
|
||||
assert.equal(callbackCalled, true);
|
||||
assert.isUndefined(request);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
'if the post_body is not a string' : {
|
||||
"It should be url encoded and the content type set to be x-www-form-urlencoded" : function(oa) {
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
var callbackCalled= false;
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers["Content-Type"], "application/x-www-form-urlencoded")
|
||||
return {
|
||||
write: function(data){
|
||||
callbackCalled= true;
|
||||
assert.equal(data, "foo=1%2C2%2C3&bar=1%2B2");
|
||||
},
|
||||
on: function() {},
|
||||
end: function() {
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.post("http://foo.com/blah", "token", "token_secret", {"foo":"1,2,3", "bar":"1+2"})
|
||||
assert.equal(callbackCalled, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
'if the post_body is a string' : {
|
||||
"and it contains non ascii (7/8bit) characters" : {
|
||||
"the content length should be the byte count, and not the string length" : function(oa) {
|
||||
var testString= "Tôi yêu node";
|
||||
var testStringLength= testString.length;
|
||||
var testStringBytesLength= Buffer.byteLength(testString);
|
||||
assert.notEqual(testStringLength, testStringBytesLength); // Make sure we're testing a string that differs between byte-length and char-length!
|
||||
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
var callbackCalled= false;
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers["Content-length"], testStringBytesLength);
|
||||
return {
|
||||
write: function(data){
|
||||
callbackCalled= true;
|
||||
assert.equal(data, testString);
|
||||
},
|
||||
on: function() {},
|
||||
end: function() {
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.post("http://foo.com/blah", "token", "token_secret", "Tôi yêu node")
|
||||
assert.equal(callbackCalled, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
"and no post_content_type is specified" : {
|
||||
"It should be written as is, with a content length specified, and the encoding should be set to be x-www-form-urlencoded" : function(oa) {
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
var callbackCalled= false;
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers["Content-Type"], "application/x-www-form-urlencoded");
|
||||
assert.equal(headers["Content-length"], 23);
|
||||
return {
|
||||
write: function(data){
|
||||
callbackCalled= true;
|
||||
assert.equal(data, "foo=1%2C2%2C3&bar=1%2B2");
|
||||
},
|
||||
on: function() {},
|
||||
end: function() {
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.post("http://foo.com/blah", "token", "token_secret", "foo=1%2C2%2C3&bar=1%2B2")
|
||||
assert.equal(callbackCalled, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
"and a post_content_type is specified" : {
|
||||
"It should be written as is, with a content length specified, and the encoding should be set to be as specified" : function(oa) {
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
var callbackCalled= false;
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers["Content-Type"], "unicorn/encoded");
|
||||
assert.equal(headers["Content-length"], 23);
|
||||
return {
|
||||
write: function(data){
|
||||
callbackCalled= true;
|
||||
assert.equal(data, "foo=1%2C2%2C3&bar=1%2B2");
|
||||
},
|
||||
on: function() {},
|
||||
end: function() {
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.post("http://foo.com/blah", "token", "token_secret", "foo=1%2C2%2C3&bar=1%2B2", "unicorn/encoded")
|
||||
assert.equal(callbackCalled, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'GET' : {
|
||||
'if no callback is passed' : {
|
||||
'it should return a request object': function(oa) {
|
||||
var request= oa.get("http://foo.com/blah", "token", "token_secret")
|
||||
assert.isObject(request);
|
||||
assert.equal(request.method, "GET");
|
||||
request.end();
|
||||
}
|
||||
},
|
||||
'if a callback is passed' : {
|
||||
"it should call the internal request's end method and return nothing": function(oa) {
|
||||
var callbackCalled= false;
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return {
|
||||
on: function() {},
|
||||
end: function() {
|
||||
callbackCalled= true;
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.get("http://foo.com/blah", "token", "token_secret", function(e,d) {})
|
||||
assert.equal(callbackCalled, true);
|
||||
assert.isUndefined(request);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'PUT' : {
|
||||
'if no callback is passed' : {
|
||||
'it should return a request object': function(oa) {
|
||||
var request= oa.put("http://foo.com/blah", "token", "token_secret", "BLAH", "text/plain")
|
||||
assert.isObject(request);
|
||||
assert.equal(request.method, "PUT");
|
||||
request.end();
|
||||
}
|
||||
},
|
||||
'if a callback is passed' : {
|
||||
"it should call the internal request's end method and return nothing": function(oa) {
|
||||
var callbackCalled= 0;
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return {
|
||||
on: function() {},
|
||||
write: function(data) {
|
||||
callbackCalled++;
|
||||
},
|
||||
end: function() {
|
||||
callbackCalled++;
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.put("http://foo.com/blah", "token", "token_secret", "BLAH", "text/plain", function(e,d){})
|
||||
assert.equal(callbackCalled, 2);
|
||||
assert.isUndefined(request);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
'if the post_body is not a string' : {
|
||||
"It should be url encoded and the content type set to be x-www-form-urlencoded" : function(oa) {
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
var callbackCalled= false;
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers["Content-Type"], "application/x-www-form-urlencoded")
|
||||
return {
|
||||
write: function(data) {
|
||||
callbackCalled= true;
|
||||
assert.equal(data, "foo=1%2C2%2C3&bar=1%2B2");
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.put("http://foo.com/blah", "token", "token_secret", {"foo":"1,2,3", "bar":"1+2"})
|
||||
assert.equal(callbackCalled, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
'if the post_body is a string' : {
|
||||
"and no post_content_type is specified" : {
|
||||
"It should be written as is, with a content length specified, and the encoding should be set to be x-www-form-urlencoded" : function(oa) {
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
var callbackCalled= false;
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers["Content-Type"], "application/x-www-form-urlencoded");
|
||||
assert.equal(headers["Content-length"], 23);
|
||||
return {
|
||||
write: function(data) {
|
||||
callbackCalled= true;
|
||||
assert.equal(data, "foo=1%2C2%2C3&bar=1%2B2");
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.put("http://foo.com/blah", "token", "token_secret", "foo=1%2C2%2C3&bar=1%2B2")
|
||||
assert.equal(callbackCalled, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
"and a post_content_type is specified" : {
|
||||
"It should be written as is, with a content length specified, and the encoding should be set to be as specified" : function(oa) {
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
var callbackCalled= false;
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
assert.equal(headers["Content-Type"], "unicorn/encoded");
|
||||
assert.equal(headers["Content-length"], 23);
|
||||
return {
|
||||
write: function(data) {
|
||||
callbackCalled= true;
|
||||
assert.equal(data, "foo=1%2C2%2C3&bar=1%2B2");
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.put("http://foo.com/blah", "token", "token_secret", "foo=1%2C2%2C3&bar=1%2B2", "unicorn/encoded")
|
||||
assert.equal(callbackCalled, true);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'DELETE' : {
|
||||
'if no callback is passed' : {
|
||||
'it should return a request object': function(oa) {
|
||||
var request= oa.delete("http://foo.com/blah", "token", "token_secret")
|
||||
assert.isObject(request);
|
||||
assert.equal(request.method, "DELETE");
|
||||
request.end();
|
||||
}
|
||||
},
|
||||
'if a callback is passed' : {
|
||||
"it should call the internal request's end method and return nothing": function(oa) {
|
||||
var callbackCalled= false;
|
||||
var op= oa._createClient;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return {
|
||||
on: function() {},
|
||||
end: function() {
|
||||
callbackCalled= true;
|
||||
}
|
||||
};
|
||||
}
|
||||
var request= oa.delete("http://foo.com/blah", "token", "token_secret", function(e,d) {})
|
||||
assert.equal(callbackCalled, true);
|
||||
assert.isUndefined(request);
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'Request With a Callback' : {
|
||||
'and a 200 response code is received' : {
|
||||
'it should callback successfully' : function(oa) {
|
||||
var op= oa._createClient;
|
||||
var callbackCalled = false;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return new DummyRequest( new DummyResponse(200) );
|
||||
}
|
||||
oa._performSecureRequest("token", "token_secret", 'POST', 'http://originalurl.com', {"scope": "foobar,1,2"}, null, null, function(error) {
|
||||
// callback
|
||||
callbackCalled= true;
|
||||
assert.equal(error, undefined);
|
||||
});
|
||||
assert.equal(callbackCalled, true)
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
'and a 210 response code is received' : {
|
||||
'it should callback successfully' : function(oa) {
|
||||
var op= oa._createClient;
|
||||
var callbackCalled = false;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return new DummyRequest( new DummyResponse(210) );
|
||||
}
|
||||
oa._performSecureRequest("token", "token_secret", 'POST', 'http://originalurl.com', {"scope": "foobar,1,2"}, null, null, function(error) {
|
||||
// callback
|
||||
callbackCalled= true;
|
||||
assert.equal(error, undefined);
|
||||
});
|
||||
assert.equal(callbackCalled, true)
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
},
|
||||
'And A 301 redirect is received' : {
|
||||
'and there is a location header' : {
|
||||
'it should (re)perform the secure request but with the new location' : function(oa) {
|
||||
var op= oa._createClient;
|
||||
var psr= oa._performSecureRequest;
|
||||
var responseCounter = 1;
|
||||
var callbackCalled = false;
|
||||
var DummyResponse =function() {
|
||||
if( responseCounter == 1 ){
|
||||
this.statusCode= 301;
|
||||
this.headers= {location:"http://redirectto.com"};
|
||||
responseCounter++;
|
||||
}
|
||||
else {
|
||||
this.statusCode= 200;
|
||||
}
|
||||
}
|
||||
DummyResponse.prototype= events.EventEmitter.prototype;
|
||||
DummyResponse.prototype.setEncoding= function() {}
|
||||
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return new DummyRequest( new DummyResponse() );
|
||||
}
|
||||
oa._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback ) {
|
||||
if( responseCounter == 1 ) {
|
||||
assert.equal(url, "http://originalurl.com");
|
||||
}
|
||||
else {
|
||||
assert.equal(url, "http://redirectto.com");
|
||||
}
|
||||
return psr.call(oa, oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback )
|
||||
}
|
||||
|
||||
oa._performSecureRequest("token", "token_secret", 'POST', 'http://originalurl.com', {"scope": "foobar,1,2"}, null, null, function() {
|
||||
// callback
|
||||
assert.equal(responseCounter, 2);
|
||||
callbackCalled= true;
|
||||
});
|
||||
assert.equal(callbackCalled, true)
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
oa._performSecureRequest= psr;
|
||||
}
|
||||
}
|
||||
},
|
||||
'but there is no location header' : {
|
||||
'it should execute the callback, passing the HTTP Response code' : function(oa) {
|
||||
var op= oa._createClient;
|
||||
var callbackCalled = false;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return new DummyRequest( new DummyResponse(301) );
|
||||
}
|
||||
oa._performSecureRequest("token", "token_secret", 'POST', 'http://originalurl.com', {"scope": "foobar,1,2"}, null, null, function(error) {
|
||||
// callback
|
||||
assert.equal(error.statusCode, 301);
|
||||
callbackCalled= true;
|
||||
});
|
||||
assert.equal(callbackCalled, true)
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'And A 302 redirect is received' : {
|
||||
'and there is a location header' : {
|
||||
'it should (re)perform the secure request but with the new location' : function(oa) {
|
||||
var op= oa._createClient;
|
||||
var psr= oa._performSecureRequest;
|
||||
var responseCounter = 1;
|
||||
var callbackCalled = false;
|
||||
var DummyResponse =function() {
|
||||
if( responseCounter == 1 ){
|
||||
this.statusCode= 302;
|
||||
this.headers= {location:"http://redirectto.com"};
|
||||
responseCounter++;
|
||||
}
|
||||
else {
|
||||
this.statusCode= 200;
|
||||
}
|
||||
}
|
||||
DummyResponse.prototype= events.EventEmitter.prototype;
|
||||
DummyResponse.prototype.setEncoding= function() {}
|
||||
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return new DummyRequest( new DummyResponse() );
|
||||
}
|
||||
oa._performSecureRequest= function( oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback ) {
|
||||
if( responseCounter == 1 ) {
|
||||
assert.equal(url, "http://originalurl.com");
|
||||
}
|
||||
else {
|
||||
assert.equal(url, "http://redirectto.com");
|
||||
}
|
||||
return psr.call(oa, oauth_token, oauth_token_secret, method, url, extra_params, post_body, post_content_type, callback )
|
||||
}
|
||||
|
||||
oa._performSecureRequest("token", "token_secret", 'POST', 'http://originalurl.com', {"scope": "foobar,1,2"}, null, null, function() {
|
||||
// callback
|
||||
assert.equal(responseCounter, 2);
|
||||
callbackCalled= true;
|
||||
});
|
||||
assert.equal(callbackCalled, true)
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
oa._performSecureRequest= psr;
|
||||
}
|
||||
}
|
||||
},
|
||||
'but there is no location header' : {
|
||||
'it should execute the callback, passing the HTTP Response code' : function(oa) {
|
||||
var op= oa._createClient;
|
||||
var callbackCalled = false;
|
||||
try {
|
||||
oa._createClient= function( port, hostname, method, path, headers, sshEnabled ) {
|
||||
return new DummyRequest( new DummyResponse(302) );
|
||||
}
|
||||
oa._performSecureRequest("token", "token_secret", 'POST', 'http://originalurl.com', {"scope": "foobar,1,2"}, null, null, function(error) {
|
||||
// callback
|
||||
assert.equal(error.statusCode, 302);
|
||||
callbackCalled= true;
|
||||
});
|
||||
assert.equal(callbackCalled, true)
|
||||
}
|
||||
finally {
|
||||
oa._createClient= op;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
137
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/tests/oauth2.js
generated
vendored
Normal file
137
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/tests/oauth2.js
generated
vendored
Normal file
@ -0,0 +1,137 @@
|
||||
var vows = require('vows'),
|
||||
assert = require('assert'),
|
||||
https = require('https'),
|
||||
OAuth2= require('../lib/oauth2').OAuth2,
|
||||
url = require('url');
|
||||
|
||||
vows.describe('OAuth2').addBatch({
|
||||
'Given an OAuth2 instance with clientId and clientSecret, ': {
|
||||
topic: new OAuth2("clientId", "clientSecret"),
|
||||
'When handling the access token response': {
|
||||
'we should correctly extract the token if received as form-data': function (oa) {
|
||||
oa._request= function( method, url, fo, bar, bleh, callback) {
|
||||
callback(null, "access_token=access&refresh_token=refresh");
|
||||
};
|
||||
oa.getOAuthAccessToken("", {}, function(error, access_token, refresh_token) {
|
||||
assert.equal( access_token, "access");
|
||||
assert.equal( refresh_token, "refresh");
|
||||
});
|
||||
},
|
||||
'we should not include access token in both querystring and headers (favours headers if specified)': function (oa) {
|
||||
oa._request = new OAuth2("clientId", "clientSecret")._request.bind(oa);
|
||||
oa._executeRequest= function( http_library, options, post_body, callback) {
|
||||
callback(null, url.parse(options.path, true).query, options.headers);
|
||||
};
|
||||
|
||||
oa._request("GET", "http://foo/", {"Authorization":"Bearer BadNews"}, null, "accessx", function(error, query, headers) {
|
||||
assert.ok( !('access_token' in query), "access_token also in query");
|
||||
assert.ok( 'Authorization' in headers, "Authorization not in headers");
|
||||
});
|
||||
},
|
||||
'we should include access token in the querystring if no Authorization header present to override it': function (oa) {
|
||||
oa._request = new OAuth2("clientId", "clientSecret")._request.bind(oa);
|
||||
oa._executeRequest= function( http_library, options, post_body, callback) {
|
||||
callback(null, url.parse(options.path, true).query, options.headers);
|
||||
};
|
||||
oa._request("GET", "http://foo/", {}, null, "access", function(error, query, headers) {
|
||||
assert.ok( 'access_token' in query, "access_token not present in query");
|
||||
assert.ok( !('Authorization' in headers), "Authorization in headers");
|
||||
});
|
||||
},
|
||||
'we should correctly extract the token if received as a JSON literal': function (oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
callback(null, '{"access_token":"access","refresh_token":"refresh"}');
|
||||
};
|
||||
oa.getOAuthAccessToken("", {}, function(error, access_token, refresh_token) {
|
||||
assert.equal( access_token, "access");
|
||||
assert.equal( refresh_token, "refresh");
|
||||
});
|
||||
},
|
||||
'we should return the received data to the calling method': function (oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
callback(null, '{"access_token":"access","refresh_token":"refresh","extra_1":1, "extra_2":"foo"}');
|
||||
};
|
||||
oa.getOAuthAccessToken("", {}, function(error, access_token, refresh_token, results) {
|
||||
assert.equal( access_token, "access");
|
||||
assert.equal( refresh_token, "refresh");
|
||||
assert.isNotNull( results );
|
||||
assert.equal( results.extra_1, 1);
|
||||
assert.equal( results.extra_2, "foo");
|
||||
});
|
||||
}
|
||||
},
|
||||
'When no grant_type parameter is specified': {
|
||||
'we should pass the value of the code argument as the code parameter': function(oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
assert.isTrue( post_body.indexOf("code=xsds23") != -1 );
|
||||
};
|
||||
oa.getOAuthAccessToken("xsds23", {} );
|
||||
}
|
||||
},
|
||||
'When an invalid grant_type parameter is specified': {
|
||||
'we should pass the value of the code argument as the code parameter': function(oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
assert.isTrue( post_body.indexOf("code=xsds23") != -1 );
|
||||
};
|
||||
oa.getOAuthAccessToken("xsds23", {grant_type:"refresh_toucan"} );
|
||||
}
|
||||
},
|
||||
'When a grant_type parameter of value "refresh_token" is specified': {
|
||||
'we should pass the value of the code argument as the refresh_token parameter, should pass a grant_type parameter, but shouldn\'t pass a code parameter' : function(oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
assert.isTrue( post_body.indexOf("refresh_token=sdsds2") != -1 );
|
||||
assert.isTrue( post_body.indexOf("grant_type=refresh_token") != -1 );
|
||||
assert.isTrue( post_body.indexOf("code=") == -1 );
|
||||
};
|
||||
oa.getOAuthAccessToken("sdsds2", {grant_type:"refresh_token"} );
|
||||
}
|
||||
},
|
||||
'When we use the authorization header': {
|
||||
'and call get with the default authorization method': {
|
||||
'we should pass the authorization header with Bearer method and value of the access_token, _request should be passed a null access_token' : function(oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
assert.equal(headers["Authorization"], "Bearer abcd5");
|
||||
assert.isNull( access_token );
|
||||
};
|
||||
oa.useAuthorizationHeaderforGET(true);
|
||||
oa.get("", "abcd5");
|
||||
}
|
||||
},
|
||||
'and call get with the authorization method set to Basic': {
|
||||
'we should pass the authorization header with Basic method and value of the access_token, _request should be passed a null access_token' : function(oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
assert.equal(headers["Authorization"], "Basic cdg2");
|
||||
assert.isNull( access_token );
|
||||
};
|
||||
oa.useAuthorizationHeaderforGET(true);
|
||||
oa.setAuthMethod("Basic");
|
||||
oa.get("", "cdg2");
|
||||
}
|
||||
}
|
||||
},
|
||||
'When we do not use the authorization header': {
|
||||
'and call get': {
|
||||
'we should pass NOT provide an authorization header and the access_token should be being passed to _request' : function(oa) {
|
||||
oa._request= function(method, url, headers, post_body, access_token, callback) {
|
||||
assert.isUndefined(headers["Authorization"]);
|
||||
assert.equal( access_token, "abcd5" );
|
||||
};
|
||||
oa.useAuthorizationHeaderforGET(false);
|
||||
oa.get("", "abcd5");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
'Given an OAuth2 instance with clientId, clientSecret and customHeaders': {
|
||||
topic: new OAuth2("clientId", "clientSecret", undefined, undefined, undefined,
|
||||
{ 'SomeHeader': '123' }),
|
||||
'When calling get': {
|
||||
'we should see the custom headers mixed into headers property in options passed to http-library' : function(oa) {
|
||||
oa._executeRequest= function( http_library, options, callback ) {
|
||||
assert.equal(options.headers["SomeHeader"], "123");
|
||||
};
|
||||
oa.get("", {});
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
13
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/tests/sha1.js
generated
vendored
Normal file
13
node_modules/passport-google-oauth/node_modules/passport-oauth/node_modules/oauth/tests/sha1.js
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
var vows = require('vows'),
|
||||
assert = require('assert');
|
||||
|
||||
vows.describe('SHA1 Hashing').addBatch({
|
||||
'When using the SHA1 Hashing function': {
|
||||
topic: require('../lib/sha1'),
|
||||
'we get the specified digest as described in http://oauth.net/core/1.0/#sig_base_example (A.5.2)': function (sha1) {
|
||||
assert.equal (sha1.HMACSHA1( "kd94hf93k423kf44&pfkkdhi9sl3r4s00",
|
||||
"GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal"),
|
||||
"tR3+Ty81lMeYAr/Fid0kMTYa/WM=");
|
||||
}
|
||||
}
|
||||
}).export(module);
|
53
node_modules/passport-google-oauth/node_modules/passport-oauth/package.json
generated
vendored
Normal file
53
node_modules/passport-google-oauth/node_modules/passport-oauth/package.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2
node_modules/passport-google-oauth/node_modules/pkginfo/.npmignore
generated
vendored
Normal file
2
node_modules/passport-google-oauth/node_modules/pkginfo/.npmignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
npm-debug.log
|
85
node_modules/passport-google-oauth/node_modules/pkginfo/README.md
generated
vendored
Normal file
85
node_modules/passport-google-oauth/node_modules/pkginfo/README.md
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
# node-pkginfo
|
||||
|
||||
An easy way to expose properties on a module from a package.json
|
||||
|
||||
## Installation
|
||||
|
||||
### Installing npm (node package manager)
|
||||
```
|
||||
curl http://npmjs.org/install.sh | sh
|
||||
```
|
||||
|
||||
### Installing pkginfo
|
||||
```
|
||||
[sudo] npm install pkginfo
|
||||
```
|
||||
|
||||
## Motivation
|
||||
How often when writing node.js modules have you written the following line(s) of code?
|
||||
|
||||
* Hard code your version string into your code
|
||||
|
||||
``` js
|
||||
exports.version = '0.1.0';
|
||||
```
|
||||
|
||||
* Programmatically expose the version from the package.json
|
||||
|
||||
``` js
|
||||
exports.version = JSON.parse(fs.readFileSync('/path/to/package.json', 'utf8')).version;
|
||||
```
|
||||
|
||||
In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? **WELL NOW YOU CAN!**
|
||||
|
||||
## Usage
|
||||
|
||||
Using `pkginfo` is idiot-proof, just require and invoke it.
|
||||
|
||||
``` js
|
||||
var pkginfo = require('pkginfo')(module);
|
||||
|
||||
console.dir(module.exports);
|
||||
```
|
||||
|
||||
By invoking the `pkginfo` module all of the properties in your `package.json` file will be automatically exposed on the callee module (i.e. the parent module of `pkginfo`).
|
||||
|
||||
Here's a sample of the output:
|
||||
|
||||
```
|
||||
{ name: 'simple-app',
|
||||
description: 'A test fixture for pkginfo',
|
||||
version: '0.1.0',
|
||||
author: 'Charlie Robbins <charlie.robbins@gmail.com>',
|
||||
keywords: [ 'test', 'fixture' ],
|
||||
main: './index.js',
|
||||
scripts: { test: 'vows test/*-test.js --spec' },
|
||||
engines: { node: '>= 0.4.0' } }
|
||||
```
|
||||
|
||||
### Expose specific properties
|
||||
If you don't want to expose **all** properties on from your `package.json` on your module then simple pass those properties to the `pkginfo` function:
|
||||
|
||||
``` js
|
||||
var pkginfo = require('pkginfo')(module, 'version', 'author');
|
||||
|
||||
console.dir(module.exports);
|
||||
```
|
||||
|
||||
```
|
||||
{ version: '0.1.0',
|
||||
author: 'Charlie Robbins <charlie.robbins@gmail.com>' }
|
||||
```
|
||||
|
||||
If you're looking for further usage see the [examples][0] included in this repository.
|
||||
|
||||
## Run Tests
|
||||
Tests are written in [vows][1] and give complete coverage of all APIs.
|
||||
|
||||
```
|
||||
vows test/*-test.js --spec
|
||||
```
|
||||
|
||||
[0]: https://github.com/indexzero/node-pkginfo/tree/master/examples
|
||||
[1]: http://vowsjs.org
|
||||
|
||||
#### Author: [Charlie Robbins](http://nodejitsu.com)
|
194
node_modules/passport-google-oauth/node_modules/pkginfo/docs/docco.css
generated
vendored
Normal file
194
node_modules/passport-google-oauth/node_modules/pkginfo/docs/docco.css
generated
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
/*--------------------- Layout and Typography ----------------------------*/
|
||||
body {
|
||||
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
|
||||
font-size: 15px;
|
||||
line-height: 22px;
|
||||
color: #252519;
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
a {
|
||||
color: #261a3b;
|
||||
}
|
||||
a:visited {
|
||||
color: #261a3b;
|
||||
}
|
||||
p {
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
h4, h5, h6 {
|
||||
color: #333;
|
||||
margin: 6px 0 6px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
h2, h3 {
|
||||
margin-bottom: 0;
|
||||
color: #000;
|
||||
}
|
||||
h1 {
|
||||
margin-top: 40px;
|
||||
margin-bottom: 15px;
|
||||
color: #000;
|
||||
}
|
||||
#container {
|
||||
position: relative;
|
||||
}
|
||||
#background {
|
||||
position: fixed;
|
||||
top: 0; left: 525px; right: 0; bottom: 0;
|
||||
background: #f5f5ff;
|
||||
border-left: 1px solid #e5e5ee;
|
||||
z-index: -1;
|
||||
}
|
||||
#jump_to, #jump_page {
|
||||
background: white;
|
||||
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
|
||||
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
|
||||
font: 10px Arial;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
text-align: right;
|
||||
}
|
||||
#jump_to, #jump_wrapper {
|
||||
position: fixed;
|
||||
right: 0; top: 0;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
#jump_wrapper {
|
||||
padding: 0;
|
||||
display: none;
|
||||
}
|
||||
#jump_to:hover #jump_wrapper {
|
||||
display: block;
|
||||
}
|
||||
#jump_page {
|
||||
padding: 5px 0 3px;
|
||||
margin: 0 0 25px 25px;
|
||||
}
|
||||
#jump_page .source {
|
||||
display: block;
|
||||
padding: 5px 10px;
|
||||
text-decoration: none;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
#jump_page .source:hover {
|
||||
background: #f5f5ff;
|
||||
}
|
||||
#jump_page .source:first-child {
|
||||
}
|
||||
table td {
|
||||
border: 0;
|
||||
outline: 0;
|
||||
}
|
||||
td.docs, th.docs {
|
||||
max-width: 450px;
|
||||
min-width: 450px;
|
||||
min-height: 5px;
|
||||
padding: 10px 25px 1px 50px;
|
||||
overflow-x: hidden;
|
||||
vertical-align: top;
|
||||
text-align: left;
|
||||
}
|
||||
.docs pre {
|
||||
margin: 15px 0 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
.docs p tt, .docs p code {
|
||||
background: #f8f8ff;
|
||||
border: 1px solid #dedede;
|
||||
font-size: 12px;
|
||||
padding: 0 0.2em;
|
||||
}
|
||||
.pilwrap {
|
||||
position: relative;
|
||||
}
|
||||
.pilcrow {
|
||||
font: 12px Arial;
|
||||
text-decoration: none;
|
||||
color: #454545;
|
||||
position: absolute;
|
||||
top: 3px; left: -20px;
|
||||
padding: 1px 2px;
|
||||
opacity: 0;
|
||||
-webkit-transition: opacity 0.2s linear;
|
||||
}
|
||||
td.docs:hover .pilcrow {
|
||||
opacity: 1;
|
||||
}
|
||||
td.code, th.code {
|
||||
padding: 14px 15px 16px 25px;
|
||||
width: 100%;
|
||||
vertical-align: top;
|
||||
background: #f5f5ff;
|
||||
border-left: 1px solid #e5e5ee;
|
||||
}
|
||||
pre, tt, code {
|
||||
font-size: 12px; line-height: 18px;
|
||||
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
|
||||
margin: 0; padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------- Syntax Highlighting -----------------------------*/
|
||||
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
|
||||
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
|
||||
body .hll { background-color: #ffffcc }
|
||||
body .c { color: #408080; font-style: italic } /* Comment */
|
||||
body .err { border: 1px solid #FF0000 } /* Error */
|
||||
body .k { color: #954121 } /* Keyword */
|
||||
body .o { color: #666666 } /* Operator */
|
||||
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
|
||||
body .cp { color: #BC7A00 } /* Comment.Preproc */
|
||||
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
|
||||
body .cs { color: #408080; font-style: italic } /* Comment.Special */
|
||||
body .gd { color: #A00000 } /* Generic.Deleted */
|
||||
body .ge { font-style: italic } /* Generic.Emph */
|
||||
body .gr { color: #FF0000 } /* Generic.Error */
|
||||
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
|
||||
body .gi { color: #00A000 } /* Generic.Inserted */
|
||||
body .go { color: #808080 } /* Generic.Output */
|
||||
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
|
||||
body .gs { font-weight: bold } /* Generic.Strong */
|
||||
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
|
||||
body .gt { color: #0040D0 } /* Generic.Traceback */
|
||||
body .kc { color: #954121 } /* Keyword.Constant */
|
||||
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
|
||||
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
|
||||
body .kp { color: #954121 } /* Keyword.Pseudo */
|
||||
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
|
||||
body .kt { color: #B00040 } /* Keyword.Type */
|
||||
body .m { color: #666666 } /* Literal.Number */
|
||||
body .s { color: #219161 } /* Literal.String */
|
||||
body .na { color: #7D9029 } /* Name.Attribute */
|
||||
body .nb { color: #954121 } /* Name.Builtin */
|
||||
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
|
||||
body .no { color: #880000 } /* Name.Constant */
|
||||
body .nd { color: #AA22FF } /* Name.Decorator */
|
||||
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
|
||||
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
|
||||
body .nf { color: #0000FF } /* Name.Function */
|
||||
body .nl { color: #A0A000 } /* Name.Label */
|
||||
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
|
||||
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
|
||||
body .nv { color: #19469D } /* Name.Variable */
|
||||
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
|
||||
body .w { color: #bbbbbb } /* Text.Whitespace */
|
||||
body .mf { color: #666666 } /* Literal.Number.Float */
|
||||
body .mh { color: #666666 } /* Literal.Number.Hex */
|
||||
body .mi { color: #666666 } /* Literal.Number.Integer */
|
||||
body .mo { color: #666666 } /* Literal.Number.Oct */
|
||||
body .sb { color: #219161 } /* Literal.String.Backtick */
|
||||
body .sc { color: #219161 } /* Literal.String.Char */
|
||||
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
|
||||
body .s2 { color: #219161 } /* Literal.String.Double */
|
||||
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
|
||||
body .sh { color: #219161 } /* Literal.String.Heredoc */
|
||||
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
|
||||
body .sx { color: #954121 } /* Literal.String.Other */
|
||||
body .sr { color: #BB6688 } /* Literal.String.Regex */
|
||||
body .s1 { color: #219161 } /* Literal.String.Single */
|
||||
body .ss { color: #19469D } /* Literal.String.Symbol */
|
||||
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
|
||||
body .vc { color: #19469D } /* Name.Variable.Class */
|
||||
body .vg { color: #19469D } /* Name.Variable.Global */
|
||||
body .vi { color: #19469D } /* Name.Variable.Instance */
|
||||
body .il { color: #666666 } /* Literal.Number.Integer.Long */
|
101
node_modules/passport-google-oauth/node_modules/pkginfo/docs/pkginfo.html
generated
vendored
Normal file
101
node_modules/passport-google-oauth/node_modules/pkginfo/docs/pkginfo.html
generated
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
<!DOCTYPE html> <html> <head> <title>pkginfo.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> pkginfo.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">¶</a> </div> </td> <td class="code"> <div class="highlight"><pre><span class="cm">/*</span>
|
||||
<span class="cm"> * pkginfo.js: Top-level include for the pkginfo module</span>
|
||||
<span class="cm"> *</span>
|
||||
<span class="cm"> * (C) 2011, Charlie Robbins</span>
|
||||
<span class="cm"> *</span>
|
||||
<span class="cm"> */</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'fs'</span><span class="p">),</span>
|
||||
<span class="nx">path</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">'path'</span><span class="p">);</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">¶</a> </div> <h3>function pkginfo ([options, 'property', 'property' ..])</h3>
|
||||
|
||||
<h4>@pmodule {Module} Parent module to read from.</h4>
|
||||
|
||||
<h4>@options {Object|Array|string} <strong>Optional</strong> Options used when exposing properties.</h4>
|
||||
|
||||
<h4>@arguments {string...} <strong>Optional</strong> Specified properties to expose.</h4>
|
||||
|
||||
<p>Exposes properties from the package.json file for the parent module on
|
||||
it's exports. Valid usage:</p>
|
||||
|
||||
<p><code>require('pkginfo')()</code></p>
|
||||
|
||||
<p><code>require('pkginfo')('version', 'author');</code></p>
|
||||
|
||||
<p><code>require('pkginfo')(['version', 'author']);</code></p>
|
||||
|
||||
<p><code>require('pkginfo')({ include: ['version', 'author'] });</code></p> </td> <td class="code"> <div class="highlight"><pre><span class="kd">var</span> <span class="nx">pkginfo</span> <span class="o">=</span> <span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="kd">var</span> <span class="nx">args</span> <span class="o">=</span> <span class="p">[].</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="mi">2</span><span class="p">).</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="k">typeof</span> <span class="nx">arg</span> <span class="o">===</span> <span class="s1">'string'</span><span class="p">;</span>
|
||||
<span class="p">});</span>
|
||||
</pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">¶</a> </div> <p><strong>Parse variable arguments</strong></p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="nb">Array</span><span class="p">.</span><span class="nx">isArray</span><span class="p">(</span><span class="nx">options</span><span class="p">))</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">¶</a> </div> <p>If the options passed in is an Array assume that
|
||||
it is the Array of properties to expose from the
|
||||
on the package.json file on the parent module.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="p">{</span> <span class="nx">include</span><span class="o">:</span> <span class="nx">options</span> <span class="p">};</span>
|
||||
<span class="p">}</span>
|
||||
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">options</span> <span class="o">===</span> <span class="s1">'string'</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">¶</a> </div> <p>Otherwise if the first argument is a string, then
|
||||
assume that it is the first property to expose from
|
||||
the package.json file on the parent module.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="p">{</span> <span class="nx">include</span><span class="o">:</span> <span class="p">[</span><span class="nx">options</span><span class="p">]</span> <span class="p">};</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">¶</a> </div> <p><strong>Setup default options</strong></p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span> <span class="o">=</span> <span class="nx">options</span> <span class="o">||</span> <span class="p">{</span> <span class="nx">include</span><span class="o">:</span> <span class="p">[]</span> <span class="p">};</span>
|
||||
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">¶</a> </div> <p>If additional string arguments have been passed in
|
||||
then add them to the properties to expose on the
|
||||
parent module. </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">options</span><span class="p">.</span><span class="nx">include</span> <span class="o">=</span> <span class="nx">options</span><span class="p">.</span><span class="nx">include</span><span class="p">.</span><span class="nx">concat</span><span class="p">(</span><span class="nx">args</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">pkg</span> <span class="o">=</span> <span class="nx">pkginfo</span><span class="p">.</span><span class="nx">read</span><span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">options</span><span class="p">.</span><span class="nx">dir</span><span class="p">).</span><span class="kr">package</span><span class="p">;</span>
|
||||
<span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">pkg</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">key</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">include</span><span class="p">.</span><span class="nx">length</span> <span class="o">></span> <span class="mi">0</span> <span class="o">&&</span> <span class="o">!~</span><span class="nx">options</span><span class="p">.</span><span class="nx">include</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="k">return</span><span class="p">;</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">pmodule</span><span class="p">.</span><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">])</span> <span class="p">{</span>
|
||||
<span class="nx">pmodule</span><span class="p">.</span><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">pkg</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span>
|
||||
<span class="p">}</span>
|
||||
<span class="p">});</span>
|
||||
|
||||
<span class="k">return</span> <span class="nx">pkginfo</span><span class="p">;</span>
|
||||
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">¶</a> </div> <h3>function find (dir)</h3>
|
||||
|
||||
<h4>@pmodule {Module} Parent module to read from.</h4>
|
||||
|
||||
<h4>@dir {string} <strong>Optional</strong> Directory to start search from.</h4>
|
||||
|
||||
<p>Searches up the directory tree from <code>dir</code> until it finds a directory
|
||||
which contains a <code>package.json</code> file. </p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">pkginfo</span><span class="p">.</span><span class="nx">find</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">dir</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">dir</span> <span class="o">=</span> <span class="nx">dir</span> <span class="o">||</span> <span class="nx">pmodule</span><span class="p">.</span><span class="nx">filename</span><span class="p">;</span>
|
||||
<span class="nx">dir</span> <span class="o">=</span> <span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span><span class="p">(</span><span class="nx">dir</span><span class="p">);</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">files</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span><span class="p">(</span><span class="nx">dir</span><span class="p">);</span>
|
||||
|
||||
<span class="k">if</span> <span class="p">(</span><span class="o">~</span><span class="nx">files</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="s1">'package.json'</span><span class="p">))</span> <span class="p">{</span>
|
||||
<span class="k">return</span> <span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">dir</span><span class="p">,</span> <span class="s1">'package.json'</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="k">if</span> <span class="p">(</span><span class="nx">dir</span> <span class="o">===</span> <span class="s1">'/'</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="k">throw</span> <span class="k">new</span> <span class="nb">Error</span><span class="p">(</span><span class="s1">'Could not find package.json up from: '</span> <span class="o">+</span> <span class="nx">dir</span><span class="p">);</span>
|
||||
<span class="p">}</span>
|
||||
|
||||
<span class="k">return</span> <span class="nx">pkginfo</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">dir</span><span class="p">);</span>
|
||||
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">¶</a> </div> <h3>function read (pmodule, dir)</h3>
|
||||
|
||||
<h4>@pmodule {Module} Parent module to read from.</h4>
|
||||
|
||||
<h4>@dir {string} <strong>Optional</strong> Directory to start search from.</h4>
|
||||
|
||||
<p>Searches up the directory tree from <code>dir</code> until it finds a directory
|
||||
which contains a <code>package.json</code> file and returns the package information.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">pkginfo</span><span class="p">.</span><span class="nx">read</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">dir</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nx">dir</span> <span class="o">=</span> <span class="nx">pkginfo</span><span class="p">.</span><span class="nx">find</span><span class="p">(</span><span class="nx">pmodule</span><span class="p">,</span> <span class="nx">dir</span><span class="p">);</span>
|
||||
|
||||
<span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">dir</span><span class="p">).</span><span class="nx">toString</span><span class="p">();</span>
|
||||
|
||||
<span class="k">return</span> <span class="p">{</span>
|
||||
<span class="nx">dir</span><span class="o">:</span> <span class="nx">dir</span><span class="p">,</span>
|
||||
<span class="kr">package</span><span class="o">:</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span>
|
||||
<span class="p">};</span>
|
||||
<span class="p">};</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">¶</a> </div> <p>Call <code>pkginfo</code> on this module and expose version.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">pkginfo</span><span class="p">(</span><span class="nx">module</span><span class="p">,</span> <span class="p">{</span>
|
||||
<span class="nx">dir</span><span class="o">:</span> <span class="nx">__dirname</span><span class="p">,</span>
|
||||
<span class="nx">include</span><span class="o">:</span> <span class="p">[</span><span class="s1">'version'</span><span class="p">],</span>
|
||||
<span class="nx">target</span><span class="o">:</span> <span class="nx">pkginfo</span>
|
||||
<span class="p">});</span>
|
||||
|
||||
</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
|
19
node_modules/passport-google-oauth/node_modules/pkginfo/examples/all-properties.js
generated
vendored
Normal file
19
node_modules/passport-google-oauth/node_modules/pkginfo/examples/all-properties.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* all-properties.js: Sample of including all properties from a package.json file
|
||||
*
|
||||
* (C) 2011, Charlie Robbins
|
||||
*
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
pkginfo = require('../lib/pkginfo')(module);
|
||||
|
||||
exports.someFunction = function () {
|
||||
console.log('some of your custom logic here');
|
||||
};
|
||||
|
||||
console.log('Inspecting module:');
|
||||
console.dir(module.exports);
|
||||
|
||||
console.log('\nAll exports exposed:');
|
||||
console.error(Object.keys(module.exports));
|
20
node_modules/passport-google-oauth/node_modules/pkginfo/examples/array-argument.js
generated
vendored
Normal file
20
node_modules/passport-google-oauth/node_modules/pkginfo/examples/array-argument.js
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* array-argument.js: Sample of including specific properties from a package.json file
|
||||
* using Array argument syntax.
|
||||
*
|
||||
* (C) 2011, Charlie Robbins
|
||||
*
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
pkginfo = require('../lib/pkginfo')(module, ['version', 'author']);
|
||||
|
||||
exports.someFunction = function () {
|
||||
console.log('some of your custom logic here');
|
||||
};
|
||||
|
||||
console.log('Inspecting module:');
|
||||
console.dir(module.exports);
|
||||
|
||||
console.log('\nAll exports exposed:');
|
||||
console.error(Object.keys(module.exports));
|
19
node_modules/passport-google-oauth/node_modules/pkginfo/examples/multiple-properties.js
generated
vendored
Normal file
19
node_modules/passport-google-oauth/node_modules/pkginfo/examples/multiple-properties.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* multiple-properties.js: Sample of including multiple properties from a package.json file
|
||||
*
|
||||
* (C) 2011, Charlie Robbins
|
||||
*
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
pkginfo = require('../lib/pkginfo')(module, 'version', 'author');
|
||||
|
||||
exports.someFunction = function () {
|
||||
console.log('some of your custom logic here');
|
||||
};
|
||||
|
||||
console.log('Inspecting module:');
|
||||
console.dir(module.exports);
|
||||
|
||||
console.log('\nAll exports exposed:');
|
||||
console.error(Object.keys(module.exports));
|
22
node_modules/passport-google-oauth/node_modules/pkginfo/examples/object-argument.js
generated
vendored
Normal file
22
node_modules/passport-google-oauth/node_modules/pkginfo/examples/object-argument.js
generated
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* object-argument.js: Sample of including specific properties from a package.json file
|
||||
* using Object argument syntax.
|
||||
*
|
||||
* (C) 2011, Charlie Robbins
|
||||
*
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
pkginfo = require('../lib/pkginfo')(module, {
|
||||
include: ['version', 'author']
|
||||
});
|
||||
|
||||
exports.someFunction = function () {
|
||||
console.log('some of your custom logic here');
|
||||
};
|
||||
|
||||
console.log('Inspecting module:');
|
||||
console.dir(module.exports);
|
||||
|
||||
console.log('\nAll exports exposed:');
|
||||
console.error(Object.keys(module.exports));
|
10
node_modules/passport-google-oauth/node_modules/pkginfo/examples/package.json
generated
vendored
Normal file
10
node_modules/passport-google-oauth/node_modules/pkginfo/examples/package.json
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "simple-app",
|
||||
"description": "A test fixture for pkginfo",
|
||||
"version": "0.1.0",
|
||||
"author": "Charlie Robbins <charlie.robbins@gmail.com>",
|
||||
"keywords": ["test", "fixture"],
|
||||
"main": "./index.js",
|
||||
"scripts": { "test": "vows test/*-test.js --spec" },
|
||||
"engines": { "node": ">= 0.4.0" }
|
||||
}
|
19
node_modules/passport-google-oauth/node_modules/pkginfo/examples/single-property.js
generated
vendored
Normal file
19
node_modules/passport-google-oauth/node_modules/pkginfo/examples/single-property.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* single-property.js: Sample of including a single specific properties from a package.json file
|
||||
*
|
||||
* (C) 2011, Charlie Robbins
|
||||
*
|
||||
*/
|
||||
|
||||
var util = require('util'),
|
||||
pkginfo = require('../lib/pkginfo')(module, 'version');
|
||||
|
||||
exports.someFunction = function () {
|
||||
console.log('some of your custom logic here');
|
||||
};
|
||||
|
||||
console.log('Inspecting module:');
|
||||
console.dir(module.exports);
|
||||
|
||||
console.log('\nAll exports exposed:');
|
||||
console.error(Object.keys(module.exports));
|
132
node_modules/passport-google-oauth/node_modules/pkginfo/lib/pkginfo.js
generated
vendored
Normal file
132
node_modules/passport-google-oauth/node_modules/pkginfo/lib/pkginfo.js
generated
vendored
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* pkginfo.js: Top-level include for the pkginfo module
|
||||
*
|
||||
* (C) 2011, Charlie Robbins
|
||||
*
|
||||
*/
|
||||
|
||||
var fs = require('fs'),
|
||||
path = require('path');
|
||||
|
||||
//
|
||||
// ### function pkginfo ([options, 'property', 'property' ..])
|
||||
// #### @pmodule {Module} Parent module to read from.
|
||||
// #### @options {Object|Array|string} **Optional** Options used when exposing properties.
|
||||
// #### @arguments {string...} **Optional** Specified properties to expose.
|
||||
// Exposes properties from the package.json file for the parent module on
|
||||
// it's exports. Valid usage:
|
||||
//
|
||||
// `require('pkginfo')()`
|
||||
//
|
||||
// `require('pkginfo')('version', 'author');`
|
||||
//
|
||||
// `require('pkginfo')(['version', 'author']);`
|
||||
//
|
||||
// `require('pkginfo')({ include: ['version', 'author'] });`
|
||||
//
|
||||
var pkginfo = module.exports = function (pmodule, options) {
|
||||
var args = [].slice.call(arguments, 2).filter(function (arg) {
|
||||
return typeof arg === 'string';
|
||||
});
|
||||
|
||||
//
|
||||
// **Parse variable arguments**
|
||||
//
|
||||
if (Array.isArray(options)) {
|
||||
//
|
||||
// If the options passed in is an Array assume that
|
||||
// it is the Array of properties to expose from the
|
||||
// on the package.json file on the parent module.
|
||||
//
|
||||
options = { include: options };
|
||||
}
|
||||
else if (typeof options === 'string') {
|
||||
//
|
||||
// Otherwise if the first argument is a string, then
|
||||
// assume that it is the first property to expose from
|
||||
// the package.json file on the parent module.
|
||||
//
|
||||
options = { include: [options] };
|
||||
}
|
||||
|
||||
//
|
||||
// **Setup default options**
|
||||
//
|
||||
options = options || { include: [] };
|
||||
|
||||
if (args.length > 0) {
|
||||
//
|
||||
// If additional string arguments have been passed in
|
||||
// then add them to the properties to expose on the
|
||||
// parent module.
|
||||
//
|
||||
options.include = options.include.concat(args);
|
||||
}
|
||||
|
||||
var pkg = pkginfo.read(pmodule, options.dir).package;
|
||||
Object.keys(pkg).forEach(function (key) {
|
||||
if (options.include.length > 0 && !~options.include.indexOf(key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!pmodule.exports[key]) {
|
||||
pmodule.exports[key] = pkg[key];
|
||||
}
|
||||
});
|
||||
|
||||
return pkginfo;
|
||||
};
|
||||
|
||||
//
|
||||
// ### function find (dir)
|
||||
// #### @pmodule {Module} Parent module to read from.
|
||||
// #### @dir {string} **Optional** Directory to start search from.
|
||||
// Searches up the directory tree from `dir` until it finds a directory
|
||||
// which contains a `package.json` file.
|
||||
//
|
||||
pkginfo.find = function (pmodule, dir) {
|
||||
dir = dir || pmodule.filename;
|
||||
dir = path.dirname(dir);
|
||||
|
||||
var files = fs.readdirSync(dir);
|
||||
|
||||
if (~files.indexOf('package.json')) {
|
||||
return path.join(dir, 'package.json');
|
||||
}
|
||||
|
||||
if (dir === '/') {
|
||||
throw new Error('Could not find package.json up from: ' + dir);
|
||||
}
|
||||
else if (!dir || dir === '.') {
|
||||
throw new Error('Cannot find package.json from unspecified directory');
|
||||
}
|
||||
|
||||
return pkginfo.find(pmodule, dir);
|
||||
};
|
||||
|
||||
//
|
||||
// ### function read (pmodule, dir)
|
||||
// #### @pmodule {Module} Parent module to read from.
|
||||
// #### @dir {string} **Optional** Directory to start search from.
|
||||
// Searches up the directory tree from `dir` until it finds a directory
|
||||
// which contains a `package.json` file and returns the package information.
|
||||
//
|
||||
pkginfo.read = function (pmodule, dir) {
|
||||
dir = pkginfo.find(pmodule, dir);
|
||||
|
||||
var data = fs.readFileSync(dir).toString();
|
||||
|
||||
return {
|
||||
dir: dir,
|
||||
package: JSON.parse(data)
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// Call `pkginfo` on this module and expose version.
|
||||
//
|
||||
pkginfo(module, {
|
||||
dir: __dirname,
|
||||
include: ['version'],
|
||||
target: pkginfo
|
||||
});
|
36
node_modules/passport-google-oauth/node_modules/pkginfo/package.json
generated
vendored
Normal file
36
node_modules/passport-google-oauth/node_modules/pkginfo/package.json
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"name": "pkginfo",
|
||||
"version": "0.2.3",
|
||||
"description": "An easy way to expose properties on a module from a package.json",
|
||||
"author": {
|
||||
"name": "Charlie Robbins",
|
||||
"email": "charlie.robbins@gmail.com"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/indexzero/node-pkginfo.git"
|
||||
},
|
||||
"keywords": [
|
||||
"info",
|
||||
"tools",
|
||||
"package.json"
|
||||
],
|
||||
"devDependencies": {
|
||||
"vows": "0.6.x"
|
||||
},
|
||||
"main": "./lib/pkginfo",
|
||||
"scripts": {
|
||||
"test": "vows test/*-test.js --spec"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
},
|
||||
"readme": "# node-pkginfo\n\nAn easy way to expose properties on a module from a package.json\n\n## Installation\n\n### Installing npm (node package manager)\n```\n curl http://npmjs.org/install.sh | sh\n```\n\n### Installing pkginfo\n```\n [sudo] npm install pkginfo\n```\n\n## Motivation\nHow often when writing node.js modules have you written the following line(s) of code? \n\n* Hard code your version string into your code\n\n``` js\n exports.version = '0.1.0';\n```\n\n* Programmatically expose the version from the package.json\n\n``` js\n exports.version = JSON.parse(fs.readFileSync('/path/to/package.json', 'utf8')).version;\n```\n\nIn other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? **WELL NOW YOU CAN!**\n\n## Usage\n\nUsing `pkginfo` is idiot-proof, just require and invoke it. \n\n``` js\n var pkginfo = require('pkginfo')(module);\n \n console.dir(module.exports);\n```\n\nBy invoking the `pkginfo` module all of the properties in your `package.json` file will be automatically exposed on the callee module (i.e. the parent module of `pkginfo`). \n\nHere's a sample of the output:\n\n```\n { name: 'simple-app',\n description: 'A test fixture for pkginfo',\n version: '0.1.0',\n author: 'Charlie Robbins <charlie.robbins@gmail.com>',\n keywords: [ 'test', 'fixture' ],\n main: './index.js',\n scripts: { test: 'vows test/*-test.js --spec' },\n engines: { node: '>= 0.4.0' } }\n```\n\n### Expose specific properties\nIf you don't want to expose **all** properties on from your `package.json` on your module then simple pass those properties to the `pkginfo` function:\n\n``` js\n var pkginfo = require('pkginfo')(module, 'version', 'author');\n \n console.dir(module.exports);\n```\n\n```\n { version: '0.1.0',\n author: 'Charlie Robbins <charlie.robbins@gmail.com>' }\n```\n\nIf you're looking for further usage see the [examples][0] included in this repository. \n\n## Run Tests\nTests are written in [vows][1] and give complete coverage of all APIs.\n\n```\n vows test/*-test.js --spec\n```\n\n[0]: https://github.com/indexzero/node-pkginfo/tree/master/examples\n[1]: http://vowsjs.org\n\n#### Author: [Charlie Robbins](http://nodejitsu.com)",
|
||||
"readmeFilename": "README.md",
|
||||
"_id": "pkginfo@0.2.3",
|
||||
"dist": {
|
||||
"shasum": "0457c06646c236f7dab060461d31cb2121f040db"
|
||||
},
|
||||
"_from": "pkginfo@0.2.x",
|
||||
"_resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.2.3.tgz"
|
||||
}
|
69
node_modules/passport-google-oauth/node_modules/pkginfo/test/pkginfo-test.js
generated
vendored
Normal file
69
node_modules/passport-google-oauth/node_modules/pkginfo/test/pkginfo-test.js
generated
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* pkginfo-test.js: Tests for the pkginfo module.
|
||||
*
|
||||
* (C) 2011, Charlie Robbins
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
exec = require('child_process').exec,
|
||||
fs = require('fs'),
|
||||
path = require('path'),
|
||||
vows = require('vows'),
|
||||
pkginfo = require('../lib/pkginfo');
|
||||
|
||||
function assertProperties (source, target) {
|
||||
assert.lengthOf(source, target.length + 1);
|
||||
target.forEach(function (prop) {
|
||||
assert.isTrue(!!~source.indexOf(prop));
|
||||
});
|
||||
}
|
||||
|
||||
function testExposes (options) {
|
||||
return {
|
||||
topic: function () {
|
||||
exec('node ' + path.join(__dirname, '..', 'examples', options.script), this.callback);
|
||||
},
|
||||
"should expose that property correctly": function (err, stdout, stderr) {
|
||||
assert.isNull(err);
|
||||
|
||||
var exposed = stderr.match(/'(\w+)'/ig).map(function (p) {
|
||||
return p.substring(1, p.length - 1);
|
||||
});
|
||||
|
||||
return !options.assert
|
||||
? assertProperties(exposed, options.properties)
|
||||
: options.assert(exposed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vows.describe('pkginfo').addBatch({
|
||||
"When using the pkginfo module": {
|
||||
"and passed a single `string` argument": testExposes({
|
||||
script: 'single-property.js',
|
||||
properties: ['version']
|
||||
}),
|
||||
"and passed multiple `string` arguments": testExposes({
|
||||
script: 'multiple-properties.js',
|
||||
properties: ['version', 'author']
|
||||
}),
|
||||
"and passed an `object` argument": testExposes({
|
||||
script: 'object-argument.js',
|
||||
properties: ['version', 'author']
|
||||
}),
|
||||
"and passed an `array` argument": testExposes({
|
||||
script: 'array-argument.js',
|
||||
properties: ['version', 'author']
|
||||
}),
|
||||
"and passed no arguments": testExposes({
|
||||
script: 'all-properties.js',
|
||||
assert: function (exposed) {
|
||||
var pkg = fs.readFileSync(path.join(__dirname, '..', 'examples', 'package.json')).toString(),
|
||||
keys = Object.keys(JSON.parse(pkg));
|
||||
|
||||
assertProperties(exposed, keys);
|
||||
}
|
||||
})
|
||||
}
|
||||
}).export(module);
|
53
node_modules/passport-google-oauth/package.json
generated
vendored
Normal file
53
node_modules/passport-google-oauth/package.json
generated
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "passport-google-oauth",
|
||||
"version": "0.1.5",
|
||||
"description": "Google (OAuth) authentication strategies for Passport.",
|
||||
"keywords": [
|
||||
"passport",
|
||||
"google",
|
||||
"auth",
|
||||
"authn",
|
||||
"authentication",
|
||||
"identity"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jaredhanson/passport-google-oauth.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/jaredhanson/passport-google-oauth/issues"
|
||||
},
|
||||
"author": {
|
||||
"name": "Jared Hanson",
|
||||
"email": "jaredhanson@gmail.com",
|
||||
"url": "http://www.jaredhanson.net/"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/MIT"
|
||||
}
|
||||
],
|
||||
"main": "./lib/passport-google-oauth",
|
||||
"dependencies": {
|
||||
"pkginfo": "0.2.x",
|
||||
"passport-oauth": "~0.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vows": "0.6.x"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "NODE_PATH=lib node_modules/.bin/vows test/*-test.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4.0"
|
||||
},
|
||||
"readme": "# Passport-Google-OAuth\n\n[Passport](http://passportjs.org/) strategies for authenticating with [Google](http://www.google.com/)\nusing OAuth 1.0a and OAuth 2.0.\n\nThis module lets you authenticate using Google in your Node.js applications.\nBy plugging into Passport, Google authentication can be easily and\nunobtrusively integrated into any application or framework that supports\n[Connect](http://www.senchalabs.org/connect/)-style middleware, including\n[Express](http://expressjs.com/).\n\n## Install\n\n $ npm install passport-google-oauth\n\n## Usage of OAuth 1.0\n\n#### Configure Strategy\n\nThe Google OAuth 1.0 authentication strategy authenticates users using a Google\naccount and OAuth tokens. The strategy requires a `verify` callback, which\naccepts these credentials and calls `done` providing a user, as well as `options`\nspecifying a consumer key, consumer secret, and callback URL.\n\n passport.use(new GoogleStrategy({\n consumerKey: GOOGLE_CONSUMER_KEY,\n consumerSecret: GOOGLE_CONSUMER_SECRET,\n callbackURL: \"http://127.0.0.1:3000/auth/google/callback\"\n },\n function(token, tokenSecret, profile, done) {\n User.findOrCreate({ googleId: profile.id }, function (err, user) {\n return done(err, user);\n });\n }\n ));\n\n#### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'google'` strategy, to\nauthenticate requests.\n\nFor example, as route middleware in an [Express](http://expressjs.com/)\napplication:\n\n app.get('/auth/google',\n passport.authenticate('google', { scope: 'https://www.google.com/m8/feeds' }));\n\n app.get('/auth/google/callback', \n passport.authenticate('google', { failureRedirect: '/login' }),\n function(req, res) {\n // Successful authentication, redirect home.\n res.redirect('/');\n });\n\n## Usage of OAuth 2.0\n\n#### Configure Strategy\n\nThe Google OAuth 2.0 authentication strategy authenticates users using a Google\naccount and OAuth 2.0 tokens. The strategy requires a `verify` callback, which\naccepts these credentials and calls `done` providing a user, as well as\n`options` specifying a client ID, client secret, and callback URL.\n\n passport.use(new GoogleStrategy({\n clientID: GOOGLE_CLIENT_ID,\n clientSecret: GOOGLE_CLIENT_SECRET,\n callbackURL: \"http://127.0.0.1:3000/auth/google/callback\"\n },\n function(accessToken, refreshToken, profile, done) {\n User.findOrCreate({ googleId: profile.id }, function (err, user) {\n return done(err, user);\n });\n }\n ));\n\n#### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'google'` strategy, to\nauthenticate requests.\n\nFor example, as route middleware in an [Express](http://expressjs.com/)\napplication:\n\n app.get('/auth/google',\n passport.authenticate('google'));\n\n app.get('/auth/google/callback', \n passport.authenticate('google', { failureRedirect: '/login' }),\n function(req, res) {\n // Successful authentication, redirect home.\n res.redirect('/');\n });\n\n## Examples\n\nFor a complete, working example, refer to the [OAuth 1.0 example](https://github.com/jaredhanson/passport-google-oauth/tree/master/examples/oauth)\nand the [OAuth 2.0 example](https://github.com/jaredhanson/passport-google-oauth/tree/master/examples/oauth2).\n\n## Tests\n\n $ npm install --dev\n $ make test\n\n[](http://travis-ci.org/jaredhanson/passport-google-oauth)\n\n## Credits\n\n - [Jared Hanson](http://github.com/jaredhanson)\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n\nCopyright (c) 2012-2013 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>\n",
|
||||
"readmeFilename": "README.md",
|
||||
"_id": "passport-google-oauth@0.1.5",
|
||||
"dist": {
|
||||
"shasum": "dd4219fd0d8e52456275c0fd9dd5c7630c560fed"
|
||||
},
|
||||
"_from": "passport-google-oauth@",
|
||||
"_resolved": "https://registry.npmjs.org/passport-google-oauth/-/passport-google-oauth-0.1.5.tgz"
|
||||
}
|
Reference in New Issue
Block a user