Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,56 @@ | |
[Passport](https://github.com/jaredhanson/passport) strategy for authenticating | ||
with [Google](http://www.google.com/) using OpenID 2.0. | ||
|
||
## Installation | ||
|
||
$ npm install passport-google | ||
|
||
## Usage | ||
|
||
#### Configure Strategy | ||
|
||
The Google authentication strategy authenticates users using a Google account, | ||
which is also an OpenID 2.0 identifier. The strategy requires a `validate` | ||
callback, which accepts this identifier and calls `done` providing a user. | ||
Additionally, options can be supplied to specify a return URL and realm. | ||
|
||
passport.use(new GoogleStrategy({ | ||
returnURL: 'http://localhost:3000/auth/google/return', | ||
realm: 'http://localhost:3000/' | ||
}, | ||
function(identifier, done) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jaredhanson
Author
Owner
|
||
User.findByOpenID({ openId: identifier }, 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'), | ||
function(req, res){ | ||
// The request will be redirected to Google for authentication, so | ||
// this function will not be called. | ||
}); | ||
|
||
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 [signon example](https://github.com/jaredhanson/passport-google/tree/master/examples/signon). | ||
|
||
## Credits | ||
|
||
- [Jared Hanson](http://github.com/jaredhanson) | ||
|
seems like a bug. Maybe it's
userInfo, identifier, done
?