Created
October 23, 2013 15:26
-
-
Save zaach/7120829 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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/. */ | |
var Client = require('./gherkin'); | |
var crypto = require('crypto'); | |
var email = crypto.randomBytes(4).toString('hex') + '@example.com'; | |
var password = 'verySecurePassword'; | |
var publicKey = { | |
"algorithm":"RS", | |
"n":"4759385967235610503571494339196749614544606692567785790953934768202714280652973091341316862993582789079872007974809511698859885077002492642203267408776123", | |
"e":"65537" | |
}; | |
var duration = 1000 * 60 * 60 * 24; | |
var client = new Client('http://127.0.0.1:9000') | |
client.accountExists(email) | |
.then( | |
function (exists) { | |
console.log('exists?', exists); | |
client.password = password | |
if (exists) { | |
return client.rawPasswordLogin() | |
} else { | |
return client.rawPasswordCreate() | |
} | |
} | |
) | |
.then( | |
function () { | |
return client.sign(publicKey, duration) | |
} | |
) | |
.then( | |
function (cert) { | |
console.log('my cert:', cert) | |
return 'done' | |
} | |
) | |
.done(console.log, console.error) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment