# passport-facebook-extension

> [![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

Latest version **0.0.7** (published 2015-05-10) · 0 weekly downloads

## Install

```sh
npm install passport-facebook-extension
pnpm add passport-facebook-extension
yarn add passport-facebook-extension
bun add passport-facebook-extension
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.7 |
| Published | 2015-05-10 |
| First published | 2015-05-08 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Erick Arroyo |
| Maintainers | coerick |

## Links

- npm: https://www.npmjs.com/package/passport-facebook-extension
- Repository: https://github.com/CoericK/passport-facebook-extension
- Issues: https://github.com/CoericK/passport-facebook-extension/issues
- npm.io page: https://npm.io/package/passport-facebook-extension

## Dependencies (4)

- [q](https://npm.io/package/q.md) ^1.4.0
- [async](https://npm.io/package/async.md) ^0.9.0
- [request](https://npm.io/package/request.md) ^2.55.0
- [json-bignum](https://npm.io/package/json-bignum.md) 0.0.3

## Recent versions

- 0.0.7 (latest) — 2015-05-10
- 0.0.6 — 2015-05-10
- 0.0.5 — 2015-05-10
- 0.0.4 — 2015-05-10
- 0.0.3 — 2015-05-10
- 0.0.1 — 2015-05-08

## README

# passport-facebook-extension

[![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://david-dm.org/coerick/passport-facebook-extension)


I created this module, because after setting up [Passport](http://passportjs.org/) strategy for authenticating with [Facebook](http://www.facebook.com/) and their
recent v2.3 API ([Passport-facebook](https://github.com/jaredhanson/passport-facebook)) i couldnt know what permissions was given by the user and if the user accepted
 the [user-friends permission](https://developers.facebook.com/docs/graph-api/reference/v2.3/user/friends), 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

  - [See the demo](https://github.com/CoericK/FBExtensionDemo)

## 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](https://github.com/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

  - [Erick Arroyo](http://github.com/coerick)

## License

[The MIT License](http://opensource.org/licenses/MIT)

Copyright (c) 2015 Erick Arroyo <[http://erickarroyo.com/](http://erickarroyo.com/)>

---
_Source: https://npm.io/package/passport-facebook-extension · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
