Add endpoint to retrieve info using HTTP Basic auth
This commit is contained in:
parent
f02e3ebe75
commit
23a8ab8cdf
@ -34,6 +34,17 @@ module.exports = function(app, historicSync, peerSync) {
|
|||||||
app.use(express.methodOverride());
|
app.use(express.methodOverride());
|
||||||
app.use(express.compress());
|
app.use(express.compress());
|
||||||
|
|
||||||
|
if (config.enableEmailstore) {
|
||||||
|
var allowCopayCrossDomain = function(req, res, next) {
|
||||||
|
res.header('Access-Control-Allow-Origin', '*');
|
||||||
|
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
||||||
|
res.header('Access-Control-Allow-Headers', 'Content-Type,Authorization');
|
||||||
|
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
app.use(allowCopayCrossDomain);
|
||||||
|
}
|
||||||
|
|
||||||
if (config.publicPath) {
|
if (config.publicPath) {
|
||||||
var staticPath = path.normalize(config.rootPath + '/../' + config.publicPath);
|
var staticPath = path.normalize(config.rootPath + '/../' + config.publicPath);
|
||||||
//IMPORTANT: for html5mode, this line must to be before app.router
|
//IMPORTANT: for html5mode, this line must to be before app.router
|
||||||
|
|||||||
@ -57,6 +57,7 @@ module.exports = function(app) {
|
|||||||
app.post(apiPrefix + '/email/register', emailPlugin.post);
|
app.post(apiPrefix + '/email/register', emailPlugin.post);
|
||||||
app.post(apiPrefix + '/email/validate', emailPlugin.validate);
|
app.post(apiPrefix + '/email/validate', emailPlugin.validate);
|
||||||
app.get(apiPrefix + '/email/retrieve/:email', emailPlugin.get);
|
app.get(apiPrefix + '/email/retrieve/:email', emailPlugin.get);
|
||||||
|
app.get(apiPrefix + '/email/retrieve', emailPlugin.retrieve);
|
||||||
app.get(apiPrefix + '/email/validate', emailPlugin.validate);
|
app.get(apiPrefix + '/email/validate', emailPlugin.validate);
|
||||||
app.post(apiPrefix + '/email/change_passphrase', emailPlugin.changePassphrase);
|
app.post(apiPrefix + '/email/change_passphrase', emailPlugin.changePassphrase);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -422,11 +422,14 @@ emailPlugin.retrieveDataByEmailAndPassphrase = function(email, key, passphrase,
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a record from the database.
|
* Retrieve a record from the database (deprecated)
|
||||||
*
|
*
|
||||||
* The request is expected to contain the parameters:
|
* The request is expected to contain the parameters:
|
||||||
|
* * email
|
||||||
* * secret
|
* * secret
|
||||||
|
* * key
|
||||||
*
|
*
|
||||||
|
* @deprecated
|
||||||
* @param {Express.Request} request
|
* @param {Express.Request} request
|
||||||
* @param {Express.Response} response
|
* @param {Express.Response} response
|
||||||
*/
|
*/
|
||||||
@ -446,6 +449,34 @@ emailPlugin.get = function (request, response) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a record from the database
|
||||||
|
*/
|
||||||
|
emailPlugin.retrieve = function (request, response) {
|
||||||
|
if (!request.header('authorization')) {
|
||||||
|
return emailPlugin.returnError(emailPlugin.errors.INVALID_REQUEST, response);
|
||||||
|
}
|
||||||
|
var authHeader = new Buffer(request.header('authorization'), 'base64').toString('utf8');
|
||||||
|
var splitIndex = authHeader.indexOf(':');
|
||||||
|
if (splitIndex === -1) {
|
||||||
|
return emailPlugin.returnError(emailPlugin.errors.INVALID_REQUEST, response);
|
||||||
|
}
|
||||||
|
var email = authHeader.substr(0, splitIndex);
|
||||||
|
var secret = authHeader.substr(splitIndex + 1);
|
||||||
|
|
||||||
|
var key = request.param('key');
|
||||||
|
if (!secret || !email || !key) {
|
||||||
|
return emailPlugin.returnError(emailPlugin.errors.MISSING_PARAMETER, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
emailPlugin.retrieveDataByEmailAndPassphrase(email, key, secret, function (err, value) {
|
||||||
|
if (err) {
|
||||||
|
return emailPlugin.returnError(err, response);
|
||||||
|
}
|
||||||
|
response.send(value).end();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Marks an email as validated
|
* Marks an email as validated
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user