Socket
Socket
Sign inDemoInstall

diet-auth

Package Overview
Dependencies
86
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

diet-auth

Dead-simple authentication for diet.js


Version published
Maintainers
1
Weekly downloads
2
increased by100%

Weekly downloads

Readme

Source

diet-auth

Dead-simple authentication for diet.js.

Install

npm install diet-auth

Supported Services

ServiceProtocolScope List
facebookOAuth 2.0https://developers.facebook.com/docs/facebook-login/permissions/v2.1
googleOAuth 2.0https://developers.google.com/+/api/oauth
More services are coming soon.

Example Facebook Authentication

// index.js
var server = require('diet')
var app = server()
app.listen('http://localhost:8000/')
var auth  = require('diet-auth')(app)

// Setup Auth Service
var facebook = auth('facebook', {
	id		: 'yourId',             // facebook app id
	secret	: 'yourSecret',         // facebook app secret
	scope	: 'email'               // specify facebook scopes
})

// Listen on GET /auth/facebook/redirect
app.get(facebook.redirect, function($){
    $($.passed){
        $.end('Hello' + $.data.user.first_name + '!')
    } else {
        $.end('Something went wrong: ' + $.error)
    }
})
  • Visiting http://localhost:8000/auth/facebook will bring up the facebook login page.
  • After the user agreed or declined access to the application it will be redirected to your Redirect URL that is held in facebook.redirect
  • if $.passed is true then you'll have access to the $.data.user object that contains every profile information that you requested with the scope.
  • If $.passed is false then you can see what's wrong in the $.error method.

API

diet-auth has a generalised api for all services. The only differences between services is the scope names and the $.data.user object.

// Setup Auth Service 
var yourService = auth.use('yourService', {
	id		: 'yourServiceId',             // service app id
	secret	: 'yourServiceSecret',         // service app secret
	scope	: 'email'                      // specify facebook scopes
})

// Listen on GET /auth/yourService/redirect
app.get(yourService.redirect, function($){
    $($.passed){
        $.end('Hello' + $.data.user.first_name + '!')
    } else {
        $.end('Something went wrong: ' + $.error)
    }
})

Upcoming Features:

  • Better API documentation

  • Twitter authorization

  • Linkedin authorization

  • Github authorization

  • Windows Live authorization

  • Yahoo authorization

  • Trello authorization

Keywords

FAQs

Last updated on 20 Jan 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc