Skip to content

Commit 5b553b2

Browse files
author
Kristina Matuleviciute
committedFeb 4, 2016
dependencies updated, linting done
1 parent 251fc76 commit 5b553b2

File tree

6 files changed

+86
-76
lines changed

6 files changed

+86
-76
lines changed
 

‎.eslintrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["seneca"]
3+
}

‎example/config.template.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
2-
"github-auth": {
3-
"clientID": "",
4-
"clientSecret": "",
5-
"urlhost": "http://local.host:3000"
2+
'github-auth': {
3+
'clientID': '',
4+
'clientSecret': '',
5+
'urlhost': 'http://local.host:3000'
66
}
77
}

‎example/github-auth-example.js

+32-33
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
/* Copyright (c) 2012-2013 Richard Rodger, MIT License */
2-
"use strict";
2+
'use strict'
33

44

5-
var http = require('http')
5+
var Http = require('http')
66

7-
var express = require('express')
8-
var argv = require('optimist').argv
7+
var Express = require('express')
8+
var argv = require('optimist').argv
99

1010

1111
// create a seneca instance
12-
var seneca = require('seneca')()
12+
var seneca = require('seneca')()
1313

1414
// use the user and auth plugins
1515
// the user plugin gives you user account business logic
1616
seneca.use('user')
1717

1818
// the auth plugin handles HTTP authentication
19-
seneca.use('auth',{
19+
seneca.use('auth', {
2020
// redirects after login are needed for traditional multi-page web apps
21-
redirect:{
22-
login:{win:'/account',fail:'/login#failed'},
23-
register:{win:'/account',fail:'/#failed'},
21+
redirect: {
22+
login: {win: '/account', fail: '/login#failed'},
23+
register: {win: '/account', fail: '/#failed'}
2424
}
2525
})
2626

2727
// load configuration for plugins
2828
// top level properties match plugin names
2929
// copy template config.template.js to config.mine.js and customize
30-
seneca.use('options','config.mine.js')
30+
seneca.use('options', 'config.mine.js')
3131

32-
//seneca.use('../google-auth.js')
32+
// seneca.use('../google-auth.js')
3333

3434
var conf = {
3535
port: argv.p || 3000
@@ -39,57 +39,56 @@ seneca.use('github-auth')
3939

4040

4141
// use the express module in the normal way
42-
var app = express()
42+
var app = Express()
4343
app.enable('trust proxy')
4444

45-
app.use(express.cookieParser())
46-
app.use(express.query())
47-
app.use(express.bodyParser())
48-
app.use(express.methodOverride())
49-
app.use(express.json())
45+
app.use(Express.cookieParser())
46+
app.use(Express.query())
47+
app.use(Express.bodyParser())
48+
app.use(Express.methodOverride())
49+
app.use(Express.json())
5050

51-
app.use(express.session({secret:'seneca'}))
51+
app.use(Express.session({secret: 'seneca'}))
5252

53-
app.use(express.static(__dirname + '/public'))
53+
app.use(Express.static(__dirname + '/public'))
5454

5555

5656
// add any middleware provided by seneca plugins
5757

5858

59-
app.use( seneca.export('web') )
59+
app.use(seneca.export('web'))
6060

6161

6262
// some express views
63-
app.engine('ejs',require('ejs-locals'))
63+
app.engine('ejs', require('ejs-locals'))
6464
app.set('views', __dirname + '/views')
65-
app.set('view engine','ejs')
65+
app.set('view engine', 'ejs')
6666

67-
app.get('/login', function(req, res){
68-
res.render('login.ejs',{})
67+
app.get('/login', function (req, res) {
68+
res.render('login.ejs', {})
6969
})
7070

7171

7272
// when rendering the account page, use the req.seneca.user object
7373
// to get user details. This is automatically set up by the auth plugin
74-
app.get('/account', function(req, res){
75-
res.render('account.ejs',{locals:{user:req.seneca.user}})
74+
app.get('/account', function (req, res) {
75+
res.render('account.ejs', {locals: {user: req.seneca.user}})
7676
})
7777

7878
// create some test accounts
7979
// the "pin" creates a more convenient api, avoiding the need for
8080
// a full action specification: seneca.act( {role:'user', cmd:'register', ... } )
81-
var u = seneca.pin({role:'user',cmd:'*'})
82-
u.register({nick:'u1',name:'nu1',email:'u1@example.com',password:'u1',active:true})
83-
u.register({nick:'u2',name:'nu2',email:'u2@example.com',password:'u2',active:true})
84-
u.register({nick:'a1',name:'na1',email:'a1@example.com',password:'a1',active:true,admin:true})
81+
var u = seneca.pin({role: 'user', cmd: '*'})
82+
u.register({nick: 'u1', name: 'nu1', email: 'u1@example.com', password: 'u1', active: true})
83+
u.register({nick: 'u2', name: 'nu2', email: 'u2@example.com', password: 'u2', active: true})
84+
u.register({nick: 'a1', name: 'na1', email: 'a1@example.com', password: 'a1', active: true, admin: true})
8585

8686

8787
// create a HTTP server using the core Node API
8888
// this lets the admin plugin use web sockets
89-
var server = http.createServer(app)
89+
var server = Http.createServer(app)
9090
server.listen(conf.port)
9191

9292
// visit http://localhost[:port]/admin to see the admin page
9393
// you'll need to logged in as an admin - user 'a1' above
94-
seneca.use('admin',{server:server})
95-
94+
seneca.use('admin', {server: server})

‎example/public/js/user-accounts.js

+30-29
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
1-
$(function(){
1+
/* global $ */
2+
var Http = require('http')
3+
$(function () {
4+
$('#login').submit(function () {
5+
var data = {
6+
username: $('#username').val(),
7+
password: $('#password').val()
8+
}
9+
Http.post('/auth/login', data, showAccount)
10+
return false
11+
})
212

3-
$('#login').submit(function(){
4-
var data = {
5-
username: $('#username').val(),
6-
password: $('#password').val()
7-
}
8-
http.post('/auth/login',data,showAccount)
9-
return false
10-
})
13+
$('#logout').click(function () {
14+
Http.post('/auth/logout', {}, showLogin)
15+
})
1116

12-
$('#logout').click(function(){
13-
http.post('/auth/logout',{},showLogin)
14-
})
1517

18+
Http.get('/auth/instance', showAccount)
19+
})
1620

17-
http.get('/auth/instance',showAccount)
18-
})
1921

22+
function showAccount (err, instance) {
23+
if (err) return console.log(err)
2024

21-
function showAccount(err,instance) {
22-
if( err ) return console.log(err);
25+
if (instance.user) {
26+
$('#user_name').text(instance.user.name)
27+
$('#user_email').text(instance.user.email)
2328

24-
if( instance.user ) {
25-
$('#user_name').text(instance.user.name)
26-
$('#user_email').text(instance.user.email)
29+
$('#content_login').slideUp()
30+
$('#content_account').slideDown()
31+
}
32+
}
2733

28-
$('#content_login').slideUp()
29-
$('#content_account').slideDown()
30-
}
31-
}
34+
function showLogin (err) {
35+
if (err) return console.log(err)
3236

33-
function showLogin(err) {
34-
if( err ) return console.log(err);
35-
36-
$('#content_login').slideDown()
37-
$('#content_account').slideUp()
38-
}
37+
$('#content_login').slideDown()
38+
$('#content_account').slideUp()
39+
}

‎github-auth.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ var GitHubStrategy = require('passport-github').Strategy
33
var _ = require('lodash')
44

55
module.exports = function (options) {
6-
76
var seneca = this
87
var service = 'github'
98

109
var params = {
11-
clientID: options.clientID,
12-
clientSecret: options.clientSecret,
13-
callbackURL: options.urlhost + (options.callbackUrl || '/auth/github/callback')
10+
clientID: options.clientID,
11+
clientSecret: options.clientSecret,
12+
callbackURL: options.urlhost + (options.callbackUrl || '/auth/github/callback')
1413
}
1514
params = _.extend(params, options.serviceParams || {})
1615

@@ -27,7 +26,7 @@ module.exports = function (options) {
2726
}
2827
)
2928

30-
var prepareLoginData = function(args, cb){
29+
var prepareLoginData = function (args, cb) {
3130
var accessToken = args.accessToken
3231
var refreshToken = args.refreshToken
3332
var profile = args.profile
@@ -42,14 +41,14 @@ module.exports = function (options) {
4241
},
4342
userdata: profile,
4443
when: new Date().toISOString()
45-
};
44+
}
4645

4746
data = _.extend({}, data, profile)
48-
if (data.emails && data.emails.length > 0 && data.emails[0].value){
47+
if (data.emails && data.emails.length > 0 && data.emails[0].value) {
4948
data.email = data.emails[0].value
5049
data.nick = data.email
5150
}
52-
if (data.name && _.isObject(data.name)){
51+
if (data.name && _.isObject(data.name)) {
5352
data.firstName = data.name.givenName
5453
data.lastName = data.name.familyName
5554
data.name = data.name || (data.firstName + ' ' + data.lastName)

‎package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@
2929
"bugs": {
3030
"url": "https://github.com/nherment/seneca-github-auth/issues"
3131
},
32+
"scripts": {
33+
"lint": "lab test -dL"
34+
},
3235
"homepage": "https://github.com/nherment/seneca-github-auth",
3336
"dependencies": {
34-
"passport-github": "0.1.5",
35-
"lodash": "~3.10.0"
37+
"passport-github": "1.1.0",
38+
"lodash": "~4.2.1",
39+
"eslint-config-seneca": "1.x.x",
40+
"eslint-plugin-standard": "1.x.x",
41+
"eslint-plugin-hapi": "4.x.x",
42+
"lab": "8.0.1",
43+
"seneca": "plugin"
3644
},
3745
"peerDependencies": {
3846
"seneca-auth": "*",

0 commit comments

Comments
 (0)