@passport-next/passport-google-oauth2
Advanced tools
Comparing version 0.3.0 to 1.0.0-beta.0
@@ -0,1 +1,7 @@ | ||
# 1.0.0 | ||
* Switched to google openid login as default for profile information @rwky @MarshallOfSound @gtebbutt | ||
* Removed google plus support since it's being shutdown @rwky | ||
# 0.3.0 (2018-11-03) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "@passport-next/passport-google-oauth2", | ||
"version": "0.3.0", | ||
"description": "Passport strategy for Google OAuth 2.0", | ||
"main": "./lib/oauth2.js", | ||
"directories": { | ||
"example": "examples", | ||
"test": "test" | ||
}, | ||
"dependencies": { | ||
"@passport-next/passport-oauth2": "1.7.x" | ||
}, | ||
"devDependencies": { | ||
"vows": "^0.8.0" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/passport-next/passport-google-oauth2.git" | ||
}, | ||
"version": "1.0.0-beta.0", | ||
"description": "Google (OAuth 2.0) authentication strategy for Passport.", | ||
"keywords": [ | ||
"passport", | ||
"google", | ||
"auth", | ||
"google", | ||
"google+", | ||
"passportjs", | ||
"oauth2" | ||
"authn", | ||
"authentication", | ||
"identity" | ||
], | ||
@@ -34,2 +17,6 @@ "author": { | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/passport-next/passport-google-oauth2.git" | ||
}, | ||
"bugs": { | ||
@@ -44,3 +31,19 @@ "url": "http://github.com/passport-next/passport-google-oauth2/issues" | ||
} | ||
] | ||
], | ||
"main": "./lib", | ||
"dependencies": { | ||
"@passport-next/passport-oauth2": "1.7.x" | ||
}, | ||
"devDependencies": { | ||
"make-node": "0.3.x", | ||
"mocha": "5.x.x", | ||
"chai": "4.x.x", | ||
"@passport-next/chai-passport-strategy": "1.1.x" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha --require test/bootstrap/node test/*.test.js test/**/*.test.js" | ||
} | ||
} |
103
README.md
@@ -10,37 +10,40 @@ # Passport strategy for Google OAuth 2.0 | ||
## Install | ||
[Passport](http://passportjs.org/) strategies for authenticating with [Google](http://www.google.com/) | ||
using ONLY OAuth 2.0. | ||
```bash | ||
$ npm install @passport-next/passport-google-oauth2 | ||
``` | ||
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/). | ||
## Usage | ||
## Install | ||
#### Create an Application | ||
$ npm install @passport-next/passport-google-oauth2 | ||
Before using `@passport-next/passport-google-oauth2`, you must register an application with | ||
Google. If you have not already done so, a new project can be created in the | ||
[Google Developers Console](https://console.developers.google.com/). | ||
Your application will be issued a client ID and client secret, which need to be | ||
provided to the strategy. You will also need to configure a redirect URI which | ||
matches the route in your application. | ||
## 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. | ||
The Google authentication strategy authenticates users using a Google account | ||
and OAuth 2.0 tokens. The client ID and secret obtained when creating an | ||
application are supplied as options when creating the strategy. The strategy | ||
also requires a `verify` callback, which receives the access token and optional | ||
refresh token, as well as `profile` which contains the authenticated user's | ||
Google profile. The `verify` callback must call `cb` providing a user to | ||
complete authentication. | ||
```Javascript | ||
var GoogleStrategy = require( 'passport-google-oauth2' ).Strategy; | ||
```javascript | ||
var GoogleStrategy = require('@passport-next/passport-google-oauth2').Strategy; | ||
passport.use(new GoogleStrategy({ | ||
clientID: GOOGLE_CLIENT_ID, | ||
clientID: GOOGLE_CLIENT_ID, | ||
clientSecret: GOOGLE_CLIENT_SECRET, | ||
callbackURL: "http://yourdomain:3000/auth/google/callback", | ||
passReqToCallback : true | ||
callbackURL: "http://www.example.com/auth/google/callback" | ||
}, | ||
function(request, accessToken, refreshToken, profile, done) { | ||
function(accessToken, refreshToken, profile, cb) { | ||
User.findOrCreate({ googleId: profile.id }, function (err, user) { | ||
return done(err, user); | ||
return cb(err, user); | ||
}); | ||
@@ -51,11 +54,2 @@ } | ||
#### Note about Local environment | ||
Avoid usage of Private IP, otherwise you will get the device_id device_name issue for Private IP during authentication. | ||
A workaround consist to set up thru the google cloud console a fully qualified domain name such as http://mydomain:3000/ for the callback | ||
then edit your /etc/hosts on your computer and/or vm to point on your private IP. | ||
Also both sign-in button + callbackURL has to be share the same url, otherwise two cookies will be created and it will lead to lost your session | ||
#### Authenticate Requests | ||
@@ -69,37 +63,20 @@ | ||
```Javascript | ||
```javascript | ||
app.get('/auth/google', | ||
passport.authenticate('google', { scope: | ||
[ 'https://www.googleapis.com/auth/plus.login', | ||
'https://www.googleapis.com/auth/plus.profile.emails.read' ] } | ||
)); | ||
passport.authenticate('google', { scope: ['profile'] })); | ||
app.get( '/auth/google/callback', | ||
passport.authenticate( 'google', { | ||
successRedirect: '/auth/google/success', | ||
failureRedirect: '/auth/google/failure' | ||
})); | ||
``` | ||
#### What you will get in profile response ? | ||
``` | ||
provider always set to `google` | ||
id | ||
name | ||
displayName | ||
birthday | ||
relationship | ||
isPerson | ||
isPlusUser | ||
placesLived | ||
language | ||
emails | ||
gender | ||
picture | ||
coverPhoto | ||
``` | ||
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 2.0 example](example). | ||
Developers using the popular [Express](http://expressjs.com/) web framework can | ||
refer to an [example](https://github.com/passport/express-4.x-facebook-example) | ||
as a starting point for their own web applications. The example shows how to | ||
authenticate users using Facebook. However, because both Facebook and Google | ||
use OAuth 2.0, the code is similar. Simply replace references to Facebook with | ||
corresponding references to Google. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
17733
4
11
224
80