add high-level login call to client
This commit is contained in:
Родитель
3de3ebb4fb
Коммит
d01cca7594
|
@ -67,8 +67,7 @@ function verifier(salt, email, password, algorithm) {
|
|||
).toString('hex')
|
||||
}
|
||||
|
||||
Client.create = function (origin, email, password, callback) {
|
||||
var c = new Client(origin)
|
||||
function setupCredentials (c, email, password) {
|
||||
// TODO: password stretching
|
||||
c.email = Buffer(email).toString('hex')
|
||||
c.password = password
|
||||
|
@ -78,6 +77,13 @@ Client.create = function (origin, email, password, callback) {
|
|||
c.srp.algorithm = 'sha256'
|
||||
c.srp.verifier = verifier(c.srp.salt, c.email, c.password, c.srp.algorithm)
|
||||
c.passwordSalt = crypto.randomBytes(32).toString('hex')
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
Client.create = function (origin, email, password, callback) {
|
||||
var c = new Client(origin)
|
||||
setupCredentials(c, email, password)
|
||||
var p = c.create()
|
||||
if (callback) {
|
||||
p.done(callback.bind(null, null), callback)
|
||||
|
@ -87,6 +93,23 @@ Client.create = function (origin, email, password, callback) {
|
|||
}
|
||||
}
|
||||
|
||||
Client.login = function (origin, email, password, callback) {
|
||||
var c = new Client(origin)
|
||||
setupCredentials(c, email, password)
|
||||
var p = c.login()
|
||||
.then(
|
||||
function () {
|
||||
return c
|
||||
}
|
||||
)
|
||||
if (callback) {
|
||||
p.done(callback.bind(null, null), callback)
|
||||
}
|
||||
else {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
Client.parse = function (string) {
|
||||
var object = JSON.parse(string)
|
||||
var client = new Client(object.api.origin)
|
||||
|
|
|
@ -103,6 +103,54 @@ function main() {
|
|||
}
|
||||
)
|
||||
|
||||
test(
|
||||
'Login flow',
|
||||
function (t) {
|
||||
var email = 'test2@example.com'
|
||||
var password = 'foobar'
|
||||
var wrapKb = null
|
||||
var client = null
|
||||
var publicKey = {
|
||||
"algorithm":"RS",
|
||||
"n":"4759385967235610503571494339196749614544606692567785790953934768202714280652973091341316862993582789079872007974809511698859885077002492642203267408776123",
|
||||
"e":"65537"
|
||||
};
|
||||
var duration = 1000 * 60 * 60 * 24
|
||||
Client.login(config.public_url, email, password)
|
||||
.then(
|
||||
function (x) {
|
||||
client = x
|
||||
return client.keys()
|
||||
}
|
||||
)
|
||||
.then(
|
||||
function (keys) {
|
||||
t.equal(typeof(keys.kA), 'string', 'kA exists')
|
||||
t.equal(typeof(keys.wrapKb), 'string', 'wrapKb exists')
|
||||
}
|
||||
)
|
||||
.then(
|
||||
function () {
|
||||
return client.sign(publicKey, duration)
|
||||
}
|
||||
)
|
||||
.then(
|
||||
function (cert) {
|
||||
t.equal(typeof(cert), 'string', 'cert exists')
|
||||
}
|
||||
)
|
||||
.done(
|
||||
function () {
|
||||
t.end()
|
||||
},
|
||||
function (err) {
|
||||
t.fail(err.message || err.error)
|
||||
t.end()
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
'account destroy',
|
||||
function (t) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче