@matthewglover/hapi-oauth
Oauth login plugin for Hapi.js
Last updated 4 years ago by matthewglover .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @matthewglover/hapi-oauth 
SYNC missed versions from official npm registry.

Build Status Coverage Status

hapi-oauth

What

A Hapi.js plugin providing Oauth login. Currently just for Facebook.

Why

To implement a simple minimal oauth setup, and to learn more about oauth and plugins.

How

To install, run npm install --save @matthewglover/hapi-oauth.

A simple implementation:

const { createServer, setConnection, registerPlugins, addRoutes, startServer } =
  require('@matthewglover/hapi-wrapper');
const hapiOauth = require('@matthewglover/hapi-oauth');

const options = {
  configs: [
    {
      provider: 'facebook',                       // name of provider (currently only facebook)
      loginPath: '/fb-login',                     // path to start login process
      authPath: '/fb-auth',                       // path to complete login process
      redirectPath: '/process-login',             // path to handle any post-login
      baseUrl: 'your.domain.com',                 // base path of your domain (without)
      clientId: 'your-facebook-client-id',        // facebook client id
      clientSecret: 'your-facebook-client-secret',// facebook client secret
      options: {                                  // any additional params to be sent to provider
        scope: 'user_likes',
      },
    },
  ],
};


// Create plugin with options
const plugin = { register: hapiOauth, options };

// Example route to process data from login
// This is where you may wan to create a web token or cookie
const processLoginRoute = {
  method: 'GET',
  path: '/process-login',
  handler: (req, reply) => reply(req.query),
};


// Create a server, register plugin and add process-login route
const server =
  createServer()
  .then(setConnection({ port: 3000 }))
  .then(registerPlugins([plugin]))
  .then(addRoutes([processLoginRoute]))
  .then(startServer)
  .then(s => console.log(`Server running at: ${s.info.uri}`))
  .catch(err => console.error(err));

module.exports = server;

Current Tags

  • 0.1.1                                ...           latest (4 years ago)

2 Versions

  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (15)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |