From 93f7d18d7a425a2701f924ee4c8fb2fddc17d9f9 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 15 May 2013 13:42:25 -0700 Subject: [PATCH] stubbed /create route --- packages/fxa-auth-server/routes/idp.js | 77 ++++++++++++++++++++++--- packages/fxa-auth-server/routes/sign.js | 4 ++ 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/packages/fxa-auth-server/routes/idp.js b/packages/fxa-auth-server/routes/idp.js index d9a412a4a2..9759929021 100644 --- a/packages/fxa-auth-server/routes/idp.js +++ b/packages/fxa-auth-server/routes/idp.js @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + const Hapi = require('hapi'); const CC = require('compute-cluster') const config = require('../lib/config') @@ -5,7 +9,7 @@ const config = require('../lib/config') const hour = 1000 * 60 * 60 var cc = new CC({ module: __dirname + '/sign.js' }) -var db = {} // TODO +var kv = require('../lib/kvstore').connect() var routes = [ { @@ -33,6 +37,21 @@ var routes = [ } } }, + { + method: 'POST', + path: '/create', + config: { + handler: create, + validate: { + payload: { + email: Hapi.types.String().email().required(), + verifier: Hapi.types.String().required(), + params: Hapi.types.String(), + kB: Hapi.types.String() + } + } + } + }, { method: 'POST', path: '/sign', @@ -50,13 +69,25 @@ var routes = [ }, { method: 'POST', - path: '/login', + path: '/beginLogin', config: { - handler: login, + handler: beginLogin, validate: { payload: { - email: Hapi.types.String().email().required(), - password: Hapi.types.String().required() // for testing only + email: Hapi.types.String().email().required() + } + } + } + }, + { + method: 'POST', + path: '/finishLogin', + config: { + handler: finishLogin, + validate: { + payload: { + sessionId: Hapi.types.String().required(), + password: Hapi.types.String().required() } } } @@ -71,6 +102,24 @@ function wellKnown(request) { }) } +function create(request) { + kv.get( + request.payload.email, + function (err, record) { + if (err) { + request.reply(Hapi.error.internal('Database errror', err)) + } + else if (record) { + request.reply('ok') + } + else { + //TODO do stuff + request.reply('ok') + } + } + ) +} + function sign(request) { // TODO validate token, get email from token cc.enqueue( @@ -86,8 +135,8 @@ function sign(request) { ) } -function login(request) { - db.get( +function beginLogin(request) { + kv.get( request.payload.email, function (err, record) { if (err) { @@ -98,12 +147,24 @@ function login(request) { } else { var token = 'TODO' - request.reply({ token: token }) + request.reply({ sessionId: token }) } } ) } +function finishLogin(request) { + // TODO lookup sessionId, verify email/password + var accountToken = 'TODO' + var kA = 'TODO' + var kB = 'TODO' + request.reply({ + accountToken: accountToken, + kA: kA, + kB: kB + }) +} + module.exports = { routes: routes } diff --git a/packages/fxa-auth-server/routes/sign.js b/packages/fxa-auth-server/routes/sign.js index 7e002d70ec..e526e34cb3 100644 --- a/packages/fxa-auth-server/routes/sign.js +++ b/packages/fxa-auth-server/routes/sign.js @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + const jwcrypto = require('jwcrypto'); const config = require('../lib/config')