From 297f1ababb16fec440963da5a385be9ab7b33b7f Mon Sep 17 00:00:00 2001 From: Eugene Obrezkov Date: Thu, 1 Oct 2015 19:15:56 +0300 Subject: [PATCH] Update documentation --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9a886a8..38b323f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ unobtrusively integrated into any application or framework that supports ## Usage -#### Configure Strategy +### Configure Strategy The Facebook authentication strategy authenticates users using a Facebook account and OAuth 2.0 tokens. The strategy requires a `verify` callback, which @@ -35,16 +35,15 @@ accepts these credentials and calls `done` providing a user, as well as passport.use(new FacebookTokenStrategy({ clientID: FACEBOOK_APP_ID, clientSecret: FACEBOOK_APP_SECRET - }, - function(accessToken, refreshToken, profile, done) { - User.findOrCreate({ facebookId: profile.id }, function (err, user) { - return done(err, user); + }, function(accessToken, refreshToken, profile, done) { + User.findOrCreate({facebookId: profile.id}, function (error, user) { + return done(error, user); }); } )); ``` -#### Authenticate Requests +### Authenticate Requests Use `passport.authenticate()`, specifying the `'facebook-token'` strategy, to authenticate requests. @@ -58,6 +57,20 @@ app.post('/auth/facebook/token', ); ``` +Or using Sails framework: + +```javascript +// api/controllers/AuthController.js +module.exports = { + facebook: function(req, res) { + passport.authenticate('facebook-token', function(error, user, info) { + // do stuff with user + res.ok(); + })(req, res); + } +}; +``` + The post request to this route should include POST or GET data with the keys `access_token` and optionally, `refresh_token` set to the credentials you receive from facebook. ```