mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 20:25:48 +00:00
[FEATURE] authinfo module
This commit is contained in:
32
src/js/ripple/authinfo.js
Normal file
32
src/js/ripple/authinfo.js
Normal 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;
|
||||||
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user