Skip to content

Loading…

Add option to pass req to callback #1

Merged
merged 2 commits into from

2 participants

@rodrigok

Please accept my PR.
This functionality is very important to me, to can get some informations from the request.

@drudge
Owner

Hey @rodrigok,

Can you give me an example of how you're using this?

@rodrigok

Of course @drudge.

I'm using req to get some data from request like device id to generate internal tokens that I use to authenticate requests later using a X-Auth-Token by device.

var facebookConfig = {
    clientID    : "...",
    clientSecret: "...",
    callbackURL : "...",
    passReqToCallback: true
}

var facebookTokenStrategy = new FacebookTokenStrategy(facebookConfig, function(req, accessToken, refreshToken, profile, done) {
    // Find or add user
    ...

    // Returns user id and device
    return done null, {
        id: user.id,
        device: req.body.device || 'no-device',
    }
});

passport.use(facebookTokenStrategy);
@rodrigok

Is there a problem with my PR?

@drudge drudge merged commit 85ae671 into drudge:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 18, 2013
  1. @rodrigok

    Removes callback with param 'params' and adds option 'passReqToCallba…

    rodrigok committed
    …ck' to pass req into callback function.
  2. @rodrigok

    Bump version to 0.1.3

    rodrigok committed
Showing with 6 additions and 5 deletions.
  1. +5 −4 lib/passport-facebook-token/strategy.js
  2. +1 −1 package.json
View
9 lib/passport-facebook-token/strategy.js
@@ -43,6 +43,8 @@ function FacebookTokenStrategy(options, verify) {
options.authorizationURL = options.authorizationURL || 'https://www.facebook.com/dialog/oauth';
options.tokenURL = options.tokenURL || 'https://graph.facebook.com/oauth/access_token';
options.scopeSeparator = options.scopeSeparator || ',';
+
+ this._passReqToCallback = options.passReqToCallback;
OAuth2Strategy.call(this, options, verify);
this.name = 'facebook-token';
@@ -86,10 +88,9 @@ FacebookTokenStrategy.prototype.authenticate = function(req, options) {
self.success(user, info);
}
- var arity = self._verify.length;
- if (arity == 5) {
- self._verify(accessToken, refreshToken, params, profile, verified);
- } else { // arity == 4
+ if (self._passReqToCallback) {
+ self._verify(req, accessToken, refreshToken, profile, verified);
+ } else {
self._verify(accessToken, refreshToken, profile, verified);
}
});
View
2 package.json
@@ -1,6 +1,6 @@
{
"name": "passport-facebook-token",
- "version": "0.1.2",
+ "version": "0.1.3",
"description": "Facebook token authentication strategy for Passport.",
"author": { "name": "Nicholas Penree", "email": "nick@penree.com", "url": "http://www.penree.com/" },
"repository": {
Something went wrong with that request. Please try again.