Skip to content

Commit

Permalink
Support federation names
Browse files Browse the repository at this point in the history
The blobvault has all of the data it needs to support federation names
on a given domain, so we should support that as well as the blobvault
protocol.
  • Loading branch information
singpolyma committed May 31, 2014
1 parent cb95c0f commit 54970c0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
38 changes: 38 additions & 0 deletions api/federation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var config = require('../config');
var response = require('response');
var libutils = require('../lib/utils');

exports.store;
var federation = function (req, res) {
if (!req.query.domain || req.query.domain !== config.federation.domain) {
response.json({"error":"invalidParams","result":"error","error_message":"Invalid domain"}).status(400).pipe(res);
return;
}

if (!req.query.destination) {
if (req.query.user) { // Compatability
req.query.destination = req.query.user;
} else {
response.json({"error":"invalidParams","result":"error","error_message":"No destination provided"}).status(400).pipe(res);
return;
}
}

var normalized_username = libutils.normalizeUsername(req.query.destination);

exports.store.read({username:normalized_username,res:res},function(resp) {
if (resp.exists) {
// this is a 200
response.json({ federation_json: {
type: "federation_record",
destination: req.query.destination,
domain: config.federation.domain,
destination_address: resp.address
}}).pipe(res);
} else {
response.json({"error":"noSuchUser","result":"error","error_message":"No such alias on that domain"}).status(404).pipe(res);
}
});
};

exports.federation = federation;
2 changes: 2 additions & 0 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
exports.user = require('./user');
exports.federation = require('./federation');
exports.blob = require('./blob');
exports.meta = require('./meta');
exports.setStore = function(store) {
exports.user.store = store;
exports.federation.store = store;
exports.blob.setStore(store);
};
var error = require('../error');
Expand Down
5 changes: 5 additions & 0 deletions config-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ exports.port = 8080;
// Public URL for this blobvault (required for authinfo)
exports.url = "https://blobvault.example.com";

// Federation names provider settings
exports.federation = {
domain: "example.com"
};

// SSL settings
exports.ssl = false;

Expand Down
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ app.post('/v1/user/:username', guard.locked, ecdsa.middleware, api.user.rename);
app.delete('/v1/user', guard.locked, hmac.middleware, api.blob.delete);
app.get('/v1/user/:username', api.user.get);
app.get('/v1/user/:username/verify/:token', api.user.verify);
app.get('/v1/federation', api.federation.federation);

// JSON handlers
app.get('/v1/blob/:blob_id', api.blob.get);
Expand Down

0 comments on commit 54970c0

Please sign in to comment.