Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/microauth/microauth-facebook
Facebook oauth for micro
https://github.com/microauth/microauth-facebook
auth authentication facebook javascript js micro microauth microservice nodejs
Last synced: 3 months ago
JSON representation
Facebook oauth for micro
- Host: GitHub
- URL: https://github.com/microauth/microauth-facebook
- Owner: microauth
- License: mit
- Created: 2017-04-14T12:02:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-05-22T23:37:25.000Z (6 months ago)
- Last Synced: 2024-08-02T01:59:05.222Z (3 months ago)
- Topics: auth, authentication, facebook, javascript, js, micro, microauth, microservice, nodejs
- Language: JavaScript
- Size: 540 KB
- Stars: 15
- Watchers: 2
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-micro - microauth-facebook
README
# microauth-facebook
> Facebook oauth for [micro](https://github.com/zeit/micro/)
[![Build Status](https://travis-ci.org/microauth/microauth-facebook.svg?branch=master)](https://travis-ci.org/microauth/microauth-facebook)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![Greenkeeper badge](https://badges.greenkeeper.io/microauth/microauth-facebook.svg)](https://greenkeeper.io/)Add [Facebook](https://facebook.com) authentication to your [micro](https://github.com/zeit/micro/) service as easy as a flick of your fingers.
This module is a part of [microauth](https://github.com/microauth/microauth) collection.## Installation
```sh
npm install --save microauth-facebook
# or
yarn add microauth-facebook
```## Usage
app.js
```js
const { send } = require('micro');
const microAuthFacebook = require('microauth-facebook');const options = {
appId: 'APP_ID',
appSecret: 'APP_SECRET',
callbackUrl: 'http://localhost:3000/auth/facebook/callback',
path: '/auth/facebook',
fields: 'name,email,cover,first_name', // Check fields list here: https://developers.facebook.com/docs/graph-api/reference/v2.11/user
scope: 'public_profile,email' // Check permissions list here: https://developers.facebook.com/docs/facebook-login/permissions
};const facebookAuth = microAuthFacebook(options);
// third `auth` argument will provide error or result of authentication
// so it will { err: errorObject} or { result: {
// provider: 'facebook',
// accessToken: 'blahblah',
// info: userInfo
// }}
module.exports = facebookAuth(async (req, res, auth) => {
if (!auth) {
return send(res, 404, 'Not Found');
}if (auth.err) {
// Error handler
console.error(auth.err);
return send(res, 403, 'Forbidden');
}return `Hello ${auth.result.info.first_name}`;
});
```Run:
```sh
micro app.js
```Now visit `http://localhost:3000/auth/facebook`
## Author
[Dmitry Pavlovsky](http://palosk.in)