jingo
jingo copied to clipboard
Sample of integration of other user databases
Just an idea to easily integrate other user databases (not authorization), i did it with my own OSMBC database.
I just have extended lib/tools.js
var pg = require('pg');
var tools = {
isValidUser: function (user,connectStr,callback) {
pg.connect(connectStr, function(err, client, pgdone) {
if (err) return callback(err);
client.query("select data->>'email' as email,data->>'OSMUser' as osmuser from usert where data->>'OSMUser' = $1 and data->>'access' = 'full' ",[user.displayName],function(err,result){
if (err) return callback(err);
if (result.rows.length!= 1) return callback(null,false);
user.email = result.rows[0].email;
return callback(null,true);
});
});
},
Form principle the query & the database can be done more configurable and be placed in config.yaml. Of course "isAuthorised" has to be exchanged by this asynchronous function. (This version enriches the OSM Authorization data with an email address, which is not given by OpenStreetMap itself. OSMBC user data contains an address, so i add that to the user object, to use the gravatar feature.
As I said on your authentication PR, I don't think Jingo is ready – as it is – to support this kind of "extension". The problem is that adding more auth systems (especially those requiring custom logic and not only the passport support) will make testing quite a nightmare. If I have 5 auth supports in the core (not "pluggable") I must check all the possible combination of those to be sure that there are no problems.
Unfortunately I don't have time for that.
Hi claudio, thankx for information,. For a more flexible auth system it make a lot of sense switching from a cofigurable to a more plugabble system..
Christoph