npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

passport-facebook-extension

v0.0.7

Published

[![Coverage](https://coveralls.io/repos/coerick/passport-facebook-extension/badge.svg?branch=master)](https://coveralls.io/r/coerick/passport-facebook-extension) [![Dependencies](https://david-dm.org/coerick/passport-facebook-extension.svg)](https://davi

Downloads

47

Readme

passport-facebook-extension

Coverage Dependencies

I created this module, because after setting up Passport strategy for authenticating with Facebook and their recent v2.3 API (Passport-facebook) i couldnt know what permissions was given by the user and if the user accepted the user-friends permission, i decided to make this module and share it for whoever needs it.

Install

$ npm install passport-facebook-extension

Usage

Require the module

var PassportFacebookExtension = require('passport-facebook-extension');

Initialize and use the FBExtension module

To use these module we asume that you integrated Passport and Passport-Facebook with Expresss, so this code should look familiar to you.

passport.use(new FacebookStrategy({
    clientID: FACEBOOK_APP_ID,
    clientSecret: FACEBOOK_APP_SECRET,
    callbackURL: "/auth/facebook/callback"
  },
  function(accessToken, refreshToken, profile, done) {
    var FBExtension = new PassportFacebookExtension(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET);
    // After initialize the module you can check the given permission by:
    FBExtension.permissionsGiven(profile.id, accessToken)
        .then(function (permissions) {
            profile.permissions = permissions;
            done(null, profile);
        }).fail(function (e) {
            console.log(e);
        });
  }
));

Methods

permissionsGiven (facebookid, accessToken)

  • facebookid - Facebook id from the user that just logged.
  • accessToken - Access Token generated by Facebook and ported to you by Passport-Facebook after accepted the app.
    FBExtension.permissionsGiven(profile.id, accessToken)
        .then(function (permissions) {
            profile.permissions = permissions;
            done(null, profile);
        }).fail(function (e) {
            console.log(e);
        });

If no error was triggered then will be executed with a callback and an array (permissions) passed as parameter:

    [
        {
        "permission":"user_friends",
        "status":"granted"},
        {"permission":"read_stream","status":"granted"},
        {"permission":"public_profile","status":"granted"}
    ]

friendsUsingApp (facebookid, accessToken)

  • facebookid - Facebook id from the user that just logged.
  • accessToken - Access Token generated by Facebook and ported to you by Passport-Facebook after accepted the app.
    FBExtension.friendsUsingApp(profile.id, accessToken)
        .then(function (friends) {
            profile.friends = friends;
            done(null, profile);
        }).fail(function (e) {
            console.log(e);
        });

If no error was triggered then will be executed with a callback and an array (friends) passed as parameter:

   [{"name":"Erick Arroyo","id":"87854546852123"}]

extendShortToken (accessToken)

  • accessToken - Access Token generated by Facebook and ported to you by Passport-Facebook after accepted the app.
    FBExtension.extendShortToken(accessToken)
        .then(function(response){
            console.log('Long-lived Token: ',response.access_token); // CAAWhckuwzlUBAIIZAZACh2uVpaRXv4NTgdZdRNiM2enIZBhRe5ur.....
            console.log('Expires in : ',response.expires+' secs.');  // 60 days in seconds
        })
        .fail(function(error){
            console.log(error)
        });

If no error was triggered then will be executed with a callback and an array (friends) passed as parameter:

   {
    "access_token": "CAAWhckuwzlUBAIIZAZACh2uVpaRXv4NTgdZdRNiM2enIZBhRe5ur....",
    "expires": "5184000"
   }
  • access_token - Long-lived token generated.
  • expires - Live in seconds of the long-lived token generated, ussually 60 days.

Demo

Issues

Facebook's OAuth 2.0 implementation has a [bug][1] in which the fragment #_=_ is appended to the callback URL. This appears to affect Firefox and Chrome, but not Safari. This fragment can be removed via client-side JavaScript, and @niftylettuce provides a suggested [workaround][2]. Developers are encouraged to direct their complaints to Facebook in an effort to get them to implement a proper fix for this issue. [1]: https://developers.facebook.com/bugs/196125357123225 [2]: https://github.com/jaredhanson/passport-facebook/issues/12#issuecomment-5913711

Credits

License

The MIT License

Copyright (c) 2015 Erick Arroyo <http://erickarroyo.com/>