diet-auth
Dead-simple authentication for diet.js.
Install
npm install diet-auth
Supported Services
Example Facebook Authentication
var server = require('diet')
var app = server()
app.listen('http://localhost:8000/')
var auth = require('diet-auth')(app)
var facebook = auth('facebook', {
id : 'yourId',
secret : 'yourSecret',
scope : 'email'
})
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.
var yourService = auth.use('yourService', {
id : 'yourServiceId',
secret : 'yourServiceSecret',
scope : 'email'
})
app.get(yourService.redirect, function($){
$($.passed){
$.end('Hello' + $.data.user.first_name + '!')
} else {
$.end('Something went wrong: ' + $.error)
}
})
Upcoming Features: