GoogleOauth2.0 First implementation
First try for GoogleOauth2.0
This commit is contained in:
8
express-server/node_modules/passport-google-oauth1/.npmignore
generated
vendored
Normal file
8
express-server/node_modules/passport-google-oauth1/.npmignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
Makefile
|
||||
docs/
|
||||
examples/
|
||||
reports/
|
||||
test/
|
||||
|
||||
.jshintrc
|
||||
.travis.yml
|
20
express-server/node_modules/passport-google-oauth1/LICENSE
generated
vendored
Normal file
20
express-server/node_modules/passport-google-oauth1/LICENSE
generated
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2012-2016 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.
|
126
express-server/node_modules/passport-google-oauth1/README.md
generated
vendored
Normal file
126
express-server/node_modules/passport-google-oauth1/README.md
generated
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
**DEPRECATED:** On April 20, 2015, Google's support for OAuth 1.0 was officially
|
||||
deprecated and is no longer supported. You are encouraged to migrate to OAuth
|
||||
2.0 and [passport-google-oauth20](https://github.com/jaredhanson/passport-google-oauth2)
|
||||
as soon as possible.
|
||||
|
||||
|
||||
# passport-google-oauth1
|
||||
|
||||
[](https://travis-ci.org/jaredhanson/passport-google-oauth1)
|
||||
[](https://coveralls.io/r/jaredhanson/passport-google-oauth1)
|
||||
[](https://codeclimate.com/github/jaredhanson/passport-google-oauth1)
|
||||
[](https://david-dm.org/jaredhanson/passport-google-oauth1)
|
||||
|
||||
|
||||
[Passport](http://passportjs.org/) strategy for authenticating with [Google](http://www.google.com/)
|
||||
using the OAuth 1.0a API.
|
||||
|
||||
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-oauth1
|
||||
|
||||
## Usage
|
||||
|
||||
#### Create an Application
|
||||
|
||||
Before using `passport-google-oauth1`, you must register your domain with Google.
|
||||
If you have not already done so, a new domain can be added at [Google Accounts](https://accounts.google.com/ManageDomains).
|
||||
Your domain will be issued an OAuth Consumer Key and OAuth Consumer Secret,
|
||||
which need to be provided to the strategy.
|
||||
|
||||
#### Configure Strategy
|
||||
|
||||
The Google authentication strategy authenticates users using a Google account
|
||||
and OAuth tokens. The consumer key and consumer secret obtained when
|
||||
registering a domain are supplied as options when creating the strategy. The
|
||||
strategy also requires a `verify` callback, which receives the access token and
|
||||
corresponding secret as arguments, as well as `profile` which contains the
|
||||
authenticated user's Google profile. The `verify` callback must call `cb`
|
||||
providing a user to complete authentication.
|
||||
|
||||
passport.use(new GoogleStrategy({
|
||||
consumerKey: 'www.example.com',
|
||||
consumerSecret: GOOGLE_CONSUMER_SECRET,
|
||||
callbackURL: "http://127.0.0.1:3000/auth/google/callback"
|
||||
},
|
||||
function(token, tokenSecret, profile, cb) {
|
||||
User.findOrCreate({ googleId: profile.id }, function (err, user) {
|
||||
return cb(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('/');
|
||||
});
|
||||
|
||||
## Examples
|
||||
|
||||
Developers using the popular [Express](http://expressjs.com/) web framework can
|
||||
refer to an [example](https://github.com/passport/express-4.x-twitter-example)
|
||||
as a starting point for their own web applications. The example shows how to
|
||||
authenticate users using Twitter. However, because both Twitter and Google
|
||||
use OAuth 1.0, the code is similar. Simply replace references to Twitter with
|
||||
corresponding references to Google.
|
||||
|
||||
## Contributing
|
||||
|
||||
#### Tests
|
||||
|
||||
The test suite is located in the `test/` directory. All new features are
|
||||
expected to have corresponding test cases. Ensure that the complete test suite
|
||||
passes by executing:
|
||||
|
||||
```bash
|
||||
$ make test
|
||||
```
|
||||
|
||||
#### Coverage
|
||||
|
||||
All new feature development is expected to have test coverage. Patches that
|
||||
increse test coverage are happily accepted. Coverage reports can be viewed by
|
||||
executing:
|
||||
|
||||
```bash
|
||||
$ make test-cov
|
||||
$ make view-cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
#### Funding
|
||||
|
||||
This software is provided to you as open source, free of charge. The time and
|
||||
effort to develop and maintain this project is dedicated by [@jaredhanson](https://github.com/jaredhanson).
|
||||
If you (or your employer) benefit from this project, please consider a financial
|
||||
contribution. Your contribution helps continue the efforts that produce this
|
||||
and other open source software.
|
||||
|
||||
Funds are accepted via [PayPal](https://paypal.me/jaredhanson), [Venmo](https://venmo.com/jaredhanson),
|
||||
and [other](http://jaredhanson.net/pay) methods. Any amount is appreciated.
|
||||
|
||||
## License
|
||||
|
||||
[The MIT License](http://opensource.org/licenses/MIT)
|
||||
|
||||
Copyright (c) 2012-2016 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>
|
9
express-server/node_modules/passport-google-oauth1/lib/index.js
generated
vendored
Normal file
9
express-server/node_modules/passport-google-oauth1/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// Load modules.
|
||||
var Strategy = require('./strategy');
|
||||
|
||||
|
||||
// Expose Strategy.
|
||||
exports = module.exports = Strategy;
|
||||
|
||||
// Exports.
|
||||
exports.Strategy = Strategy;
|
28
express-server/node_modules/passport-google-oauth1/lib/profile.js
generated
vendored
Normal file
28
express-server/node_modules/passport-google-oauth1/lib/profile.js
generated
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Parse profile.
|
||||
*
|
||||
* Parses user profile as fetched from Google Contacts API.
|
||||
*
|
||||
* Note that the following scope must have been requested and granted in order
|
||||
* to access the Google Contacts API:
|
||||
* { scope: 'https://www.google.com/m8/feeds' }
|
||||
*
|
||||
* References:
|
||||
* - https://developers.google.com/google-apps/contacts/v3/
|
||||
*
|
||||
* @param {object|string} json
|
||||
* @return {object}
|
||||
* @access public
|
||||
*/
|
||||
exports.parse = function(json) {
|
||||
if ('string' == typeof json) {
|
||||
json = JSON.parse(json);
|
||||
}
|
||||
|
||||
var profile = {};
|
||||
profile.id = json.feed.id['$t']
|
||||
profile.displayName = json.feed.author[0].name['$t'];
|
||||
profile.emails = [{ value: json.feed.author[0].email['$t'] }];
|
||||
|
||||
return profile;
|
||||
};
|
112
express-server/node_modules/passport-google-oauth1/lib/strategy.js
generated
vendored
Normal file
112
express-server/node_modules/passport-google-oauth1/lib/strategy.js
generated
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
// Load modules.
|
||||
var OAuthStrategy = require('passport-oauth1')
|
||||
, util = require('util')
|
||||
, Profile = require('./profile')
|
||||
, InternalOAuthError = require('passport-oauth1').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 `cb`
|
||||
* 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, cb) {
|
||||
* User.findOrCreate(..., function (err, user) {
|
||||
* cb(err, user);
|
||||
* });
|
||||
* }
|
||||
* ));
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} options
|
||||
* @param {Function} verify
|
||||
* @access 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
|
||||
* @access 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)); }
|
||||
|
||||
var json;
|
||||
try {
|
||||
json = JSON.parse(body);
|
||||
} catch (ex) {
|
||||
return done(new Error('Failed to parse user profile'));
|
||||
}
|
||||
|
||||
var profile = Profile.parse(json);
|
||||
profile.provider = 'google';
|
||||
profile._raw = body;
|
||||
profile._json = json;
|
||||
|
||||
done(null, profile);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extra Google-specific parameters to be included in the request token
|
||||
* request.
|
||||
*
|
||||
* @param {Object} options
|
||||
* @return {Object}
|
||||
* @access 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 constructor.
|
||||
module.exports = Strategy;
|
71
express-server/node_modules/passport-google-oauth1/package.json
generated
vendored
Normal file
71
express-server/node_modules/passport-google-oauth1/package.json
generated
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
{
|
||||
"_from": "passport-google-oauth1@1.x.x",
|
||||
"_id": "passport-google-oauth1@1.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-r3SoA99R7GRvZqRNgigr5vEI4Mw=",
|
||||
"_location": "/passport-google-oauth1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "passport-google-oauth1@1.x.x",
|
||||
"name": "passport-google-oauth1",
|
||||
"escapedName": "passport-google-oauth1",
|
||||
"rawSpec": "1.x.x",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.x.x"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/passport-google-oauth"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/passport-google-oauth1/-/passport-google-oauth1-1.0.0.tgz",
|
||||
"_shasum": "af74a803df51ec646f66a44d82282be6f108e0cc",
|
||||
"_spec": "passport-google-oauth1@1.x.x",
|
||||
"_where": "C:\\Users\\Georg\\GitHub\\SmartShopper\\express-server\\node_modules\\passport-google-oauth",
|
||||
"author": {
|
||||
"name": "Jared Hanson",
|
||||
"email": "jaredhanson@gmail.com",
|
||||
"url": "http://www.jaredhanson.net/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/jaredhanson/passport-google-oauth1/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"passport-oauth1": "1.x.x"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Google (OAuth 1.0) authentication strategy for Passport.",
|
||||
"devDependencies": {
|
||||
"chai": "2.x.x",
|
||||
"chai-passport-strategy": "1.x.x",
|
||||
"make-node": "0.3.x",
|
||||
"mocha": "1.x.x"
|
||||
},
|
||||
"homepage": "https://github.com/jaredhanson/passport-google-oauth1#readme",
|
||||
"keywords": [
|
||||
"passport",
|
||||
"google",
|
||||
"auth",
|
||||
"authn",
|
||||
"authentication",
|
||||
"identity"
|
||||
],
|
||||
"license": "MIT",
|
||||
"licenses": [
|
||||
{
|
||||
"type": "MIT",
|
||||
"url": "http://opensource.org/licenses/MIT"
|
||||
}
|
||||
],
|
||||
"main": "./lib",
|
||||
"name": "passport-google-oauth1",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jaredhanson/passport-google-oauth1.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --require test/bootstrap/node test/*.test.js"
|
||||
},
|
||||
"version": "1.0.0"
|
||||
}
|
Reference in New Issue
Block a user