From 836a7c81de921ebf6f845bd24f53ae84ca761b61 Mon Sep 17 00:00:00 2001 From: mirceaalexandru Date: Wed, 5 Aug 2015 10:45:36 +0300 Subject: [PATCH 1/4] changes to support new seneca-auth implementation --- user-accounts/app.js | 10 ++++++++++ user-accounts/package.json | 18 ++++++++++-------- user-accounts/public/index.html | 6 ++++-- user-accounts/public/js/user-accounts.js | 14 +++++++------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/user-accounts/app.js b/user-accounts/app.js index aba0097..bd42323 100644 --- a/user-accounts/app.js +++ b/user-accounts/app.js @@ -31,16 +31,26 @@ seneca.use('user') seneca.use('auth',{ // redirects after login are needed for traditional multi-page web apps redirect:{ + always: false, + restrict: '/', login: { win: '/account', fail: '/login#failed' }, + logout: { + win: '/', + fail: '/' + }, register: { + always: true, win: '/account', fail: '/#failed' } } }) +// the local-auth handles local auth strategy +seneca.use('local-auth') +seneca.use('facebook-auth', options.facebook || {}) // use the express module in the normal way diff --git a/user-accounts/package.json b/user-accounts/package.json index a333084..48206e0 100644 --- a/user-accounts/package.json +++ b/user-accounts/package.json @@ -11,21 +11,23 @@ "author": "Richard Rodger", "license": "MIT", "dependencies": { - "express": "~4.9.5", "body-parser": "~1.9.0", "cookie-parser": "~1.3.2", - "method-override": "~2.2.0", - "express-session": "~1.8.2", - "serve-static": "~1.6.3", - "optimist": "~0.6.1", "ejs": "~1.0.0", "ejs-locals": "~1.0.2", + "express": "~4.9.5", + "express-session": "~1.8.2", + "method-override": "~2.2.0", + "optimist": "~0.6.1", "seneca": "plugin", - "seneca-user": "~0.2.10", - "seneca-auth": "~0.4.0", "seneca-admin": "~0.2.0", + "seneca-auth": "~0.4.0", + "seneca-data-editor": "~0.2.0", + "seneca-facebook-auth": "^0.1.0", "seneca-jsonrest-api": "~0.3.1", + "seneca-local-auth": "~0.0.3", "seneca-perm": "~0.4.0", - "seneca-data-editor": "~0.2.0" + "seneca-user": "~0.2.10", + "serve-static": "~1.6.3" } } diff --git a/user-accounts/public/index.html b/user-accounts/public/index.html index e88de89..5d267bd 100644 --- a/user-accounts/public/index.html +++ b/user-accounts/public/index.html @@ -4,8 +4,10 @@ -Multi-page App Login
-Single-page App Login
+Multi-page App Login (make sure that redirect.always is true - to automatically redirect to desired page) +
+Single-page App Login (make sure that redirect.always is false - no redirect is required) +

Twitter Login
diff --git a/user-accounts/public/js/user-accounts.js b/user-accounts/public/js/user-accounts.js index 8e143c0..3497ce4 100644 --- a/user-accounts/public/js/user-accounts.js +++ b/user-accounts/public/js/user-accounts.js @@ -5,21 +5,21 @@ $(function(){ username: $('#username').val(), password: $('#password').val() } - http.post('/auth/login',data,showAccount) + $.post('/auth/login',data,showAccount) return false }) $('#logout').click(function(){ - http.post('/auth/logout',{},showLogin) + $.post('/auth/logout',{},showLogin) }) - http.get('/auth/instance',showAccount) + $.get('/auth/user',showAccount) }) -function showAccount(err,instance) { - if( err ) return console.log(err); +function showAccount(instance) { + if( !instance.ok ) return console.log(instance.why); if( instance.user ) { $('#user_name').text(instance.user.name) @@ -30,8 +30,8 @@ function showAccount(err,instance) { } } -function showLogin(err) { - if( err ) return console.log(err); +function showLogin(data) { + if( !data.ok ) return console.log(data.why); $('#content_login').slideDown() $('#content_account').slideUp() From 86e80fe5509fe0c5f32fa0a3b383fc009bad06d4 Mon Sep 17 00:00:00 2001 From: mirceaalexandru Date: Wed, 5 Aug 2015 11:25:39 +0300 Subject: [PATCH 2/4] removed twitter login --- user-accounts/public/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user-accounts/public/index.html b/user-accounts/public/index.html index 5d267bd..9bd2f91 100644 --- a/user-accounts/public/index.html +++ b/user-accounts/public/index.html @@ -10,7 +10,7 @@

-Twitter Login
+ Facebook Login

From 2ba3124d345458abf1cc4736756cc051e1e11ed2 Mon Sep 17 00:00:00 2001 From: mirceaalexandru Date: Wed, 5 Aug 2015 12:40:26 +0300 Subject: [PATCH 3/4] use twitter login --- user-accounts/app.js | 1 + user-accounts/config.template.js | 27 ++++++++++++++------------- user-accounts/public/index.html | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/user-accounts/app.js b/user-accounts/app.js index bd42323..bab408a 100644 --- a/user-accounts/app.js +++ b/user-accounts/app.js @@ -51,6 +51,7 @@ seneca.use('auth',{ // the local-auth handles local auth strategy seneca.use('local-auth') seneca.use('facebook-auth', options.facebook || {}) +seneca.use('twitter-auth', options.twitter || {}) // use the express module in the normal way diff --git a/user-accounts/config.template.js b/user-accounts/config.template.js index a998610..6b8cd25 100644 --- a/user-accounts/config.template.js +++ b/user-accounts/config.template.js @@ -2,19 +2,20 @@ module.exports = { main: { port: 3000 }, - - auth: { - service: { - twitter: { - key: "TWITTER_KEY", - secret: "TWITTER_SECRET", - urlhost: "http://localhost:3000" - }, - facebook: { - key: "FACEBOOK_ID", - secret: "FACEBOOK_SECRET", - urlhost: "http://localhost:3000" - } + "facebook" : { + "appId" : "FB_ID", + "appSecret" : "FB_SECRET", + "urlhost" : "http://localhost:3000", + "serviceParams": { + "scope" : [ + "email" + ] } + }, + "twitter" : { + "apiKey" : "TWITTER_KEY", + "apiSecret" : "TWITTER_SECRET", + "urlhost" : "http://localhost:3000" } + } diff --git a/user-accounts/public/index.html b/user-accounts/public/index.html index 9bd2f91..5d267bd 100644 --- a/user-accounts/public/index.html +++ b/user-accounts/public/index.html @@ -10,7 +10,7 @@

- +Twitter Login
Facebook Login

From 9045d0c70155ad37e920e402104bebc8201c6a85 Mon Sep 17 00:00:00 2001 From: mirceaalexandru Date: Mon, 10 Aug 2015 12:16:14 +0300 Subject: [PATCH 4/4] move auth options to external options file --- user-accounts/app.js | 22 ++-------------------- user-accounts/config.template.js | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/user-accounts/app.js b/user-accounts/app.js index bab408a..92ed5a7 100644 --- a/user-accounts/app.js +++ b/user-accounts/app.js @@ -28,26 +28,8 @@ seneca.use('user') // the auth plugin handles HTTP authentication -seneca.use('auth',{ - // redirects after login are needed for traditional multi-page web apps - redirect:{ - always: false, - restrict: '/', - login: { - win: '/account', - fail: '/login#failed' - }, - logout: { - win: '/', - fail: '/' - }, - register: { - always: true, - win: '/account', - fail: '/#failed' - } - } -}) +seneca.use('auth', options.auth) + // the local-auth handles local auth strategy seneca.use('local-auth') seneca.use('facebook-auth', options.facebook || {}) diff --git a/user-accounts/config.template.js b/user-accounts/config.template.js index 6b8cd25..8d7beb5 100644 --- a/user-accounts/config.template.js +++ b/user-accounts/config.template.js @@ -16,6 +16,27 @@ module.exports = { "apiKey" : "TWITTER_KEY", "apiSecret" : "TWITTER_SECRET", "urlhost" : "http://localhost:3000" + }, + "auth": { + // redirects after login are needed for traditional multi-page web apps + redirect:{ + // * when using multi-page web apps always should be true to allow redirects + // * when using single-page web apps always should be false to disable redirects + // except for register - when callback is called from external auth sources - facebook/twitter/others + always: true, + login: { + win: '/account', + fail: '/login#failed' + }, + logout: { + win: '/', + fail: '/' + }, + register: { + always: true, + win: '/account', + fail: '/#failed' + } + } } - }