[FEATURE] authinfo module

This commit is contained in:
Matthew Fettig
2014-05-19 16:38:51 -07:00
parent 7fe530e82c
commit 7ea1ba168d
2 changed files with 46 additions and 0 deletions

32
src/js/ripple/authinfo.js Normal file
View File

@@ -0,0 +1,32 @@
var RippleTxt = require('./rippletxt');
var request = require('superagent');
function AuthInfo () {
this.rippleTxt = new RippleTxt;
}
//Can I cache the auth info for later use?
AuthInfo.prototype.get = function (domain, username, fn) {
var self = this;
self.rippleTxt.get(domain, function(err, txt){
if (err) return fn(err);
processTxt(txt)
});
function processTxt(txt) {
if (!txt.authinfo_url) return fn(new Error("Authentication is not supported on "+domain));
var url = Array.isArray(txt.authinfo_url) ? txt.authinfo_url[0] : txt.authinfo_url;
url += "?domain="+domain+"&username="+username;
request.get(url, function(err, resp){
if (err) return fn(new Error("Authentication info server unreachable"));
fn(null, resp.body);
});
}
}
module.exports = AuthInfo;

View File

@@ -1,6 +1,8 @@
var assert = require('assert'); var assert = require('assert');
var RippleTxt = require('../src/js/ripple/rippletxt'); var RippleTxt = require('../src/js/ripple/rippletxt');
var AuthInfo = require('../src/js/ripple/authinfo');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; //must be set for self signed certs
describe('Vault Client', function() { describe('Vault Client', function() {
@@ -15,4 +17,16 @@ describe('Vault Client', function() {
}); });
}); });
}); });
describe('AuthInfo', function() {
var auth = new AuthInfo();
it ('should', function(done){
auth.get("staging.ripple.com", "testUser", function(err, resp){
assert.ifError(err);
assert.equal(typeof resp, 'object');
done();
});
});
});
}); });