diff --git a/user-accounts/app.js b/user-accounts/app.js index aba0097..92ed5a7 100644 --- a/user-accounts/app.js +++ b/user-accounts/app.js @@ -28,19 +28,12 @@ seneca.use('user') // the auth plugin handles HTTP authentication -seneca.use('auth',{ - // redirects after login are needed for traditional multi-page web apps - redirect:{ - login: { - win: '/account', - fail: '/login#failed' - }, - register: { - 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 || {}) +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..8d7beb5 100644 --- a/user-accounts/config.template.js +++ b/user-accounts/config.template.js @@ -2,18 +2,40 @@ module.exports = { main: { port: 3000 }, - - auth: { - service: { - twitter: { - key: "TWITTER_KEY", - secret: "TWITTER_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" + }, + "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: '/' }, - facebook: { - key: "FACEBOOK_ID", - secret: "FACEBOOK_SECRET", - urlhost: "http://localhost:3000" + register: { + always: true, + win: '/account', + fail: '/#failed' } } } 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()