Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ install:
- npm install
env:
global:
secure: pL9O2VFziHNToD2FW+eZJcZNCEl2ltL7WuTa2aZro4XFjiU30JfY/nTD1hLcPDd+ZgS8gg/+OREHs2GCxsmzOpyLZNj4mR9/jNdfCwwGZrf/oJzjZjBWNzEqgTTrZTGKji4/XonVfVg0wU7sqv+SNpWOhdsfr9NZBnOYSs7vMcmqdhCiILGJIGMqBj37ux5tgtGJJkxR+IHwJKQe634S+HzNuCXaTJ2U1a6pCz9tb25Y8vFQ9rOPd2iZVd7GoNccDAzHGWNBuiRxxETE4Mn6VmHiaAccJ181kcKJ01S0bjoALbX9L5ySKqDLPfs2dKOJdrvGwWfMhZYkXWJGelIzOHUtSBcxYQ4ZfXWpLKbd169EeEwEC9tC6E4h3SaKddUiP+aVzC2zsh+WNag/xIDT+a3uXdDRSieNAL3cCh/45bFyo5BXRxSJamVRVBTuhaAvVGxRjuIc1qBiLKnNXTnkVFmEtnmoPmeaNWvBaGvqvhKOERJXGRCnB3mXaTTgdDEAXfHHdHgLQc0NfS/VgW9qGFJQklCHV15/MJ06+f8od/FeE+/s3FsrFxSD3qxuLvvOUYzYCQUeXI8Q6WfX6vwU9UYsSpDhkmV1k5Eg/1oZeYo+pVI94L3LhtwGw/ZCWeTR9IEFOmZQX66i/4BAfU2xyKkXMLaBOeWd8v9/QCbLacQ=
secure: ATb4QFGG6sPkfquAoye6BeN7u4uQ4abP8qatVK8XG3Qof+pECZwRkFPVoopO1Gb/4bQSPfapc1aGPzGuKi409v633vpDnpcgM7cHX9CPT+YQYcTePMFtq/m+5YY3WIYWM1zCFmJ+bBwQO/MtsubfGfA9EmSAAxtnJV+1JDD3Y6+NQRkQN7K+gxQozec0u1W0Oe1sJXLSKlW3JPL8iRtKcLvmIDysKtBK6X/Wg1qP2Me4reb449a0yGej3QvZDbDYJbdlh7vuFLjXJAz3yExfED8QAm8wf0p9F8emILHnkLxjumTTnGUUqDJLLu8WgkahFiyFo4jMtryhNQ0+p6WhXmEbpNIO+yMGSZPsCGbnpkhWJ1aMAT6ZhgpHf4jDZQd4ZJi02+n9tOpe+Lm2Jk2LXY8SwMk3xGtqm5sk03weTc019TUGj/NLoHNjO/vfNz3xOImD5Gck3bXWNxdrX3bjiyVsr/u77enoWu9drPCEl3JOTIwVP3mTF8R3axSFOQ8M4SI1orCMChkGMB5qExl+Gfx+MHa/jL7QKO1SFRgl1O3DbhsyFE6xiabYzwLcdbI50ypy6VJjmDd5RxK7BkDa8RumlHT1uY1FK9yRXu4XFrrw9FjF2s+xjWbliRZqXRReXk0W1Hz4zj5au3Y9YH5a/UPtB72TY+AUUWHTUPQl3SU=
deploy:
provider: npm
skip_cleanup: true
Expand Down
128 changes: 124 additions & 4 deletions src/Kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,7 @@ Kuzzle.prototype.getJwtToken = function() {
Kuzzle.prototype.login = function (strategy) {
var
self = this,
request = {
strategy: strategy
},
request = {},
credentials,
cb = null;

Expand Down Expand Up @@ -505,7 +503,7 @@ Kuzzle.prototype.login = function (strategy) {
});
}

this.query({controller: 'auth', action: 'login'}, {body: request}, {queuable: false}, function(error, response) {
this.query({controller: 'auth', action: 'login'}, {strategy: strategy, body: request}, {queuable: false}, function(error, response) {
if (!error) {
if (response.result.jwt) {
self.setJwtToken(response.result.jwt);
Expand All @@ -520,6 +518,128 @@ Kuzzle.prototype.login = function (strategy) {
});
};

/**
* Create credentials of the specified <strategy> for the current user.
*
* @param credentials
* @param strategy
* @param options
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.createMyCredentials = function (strategy, credentials, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.query({controller: 'auth', action: 'createMyCredentials'}, {strategy: strategy, body: credentials}, options, function(err, res) {
if (!err) {
cb && cb(null, res.result._source);
} else {
cb && cb(err);
}
});

return this;
};

/**
* Delete credentials of the specified <strategy> for the current user.
*
* @param strategy
* @param options
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.deleteMyCredentials = function (strategy, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.query({controller: 'auth', action: 'deleteMyCredentials'}, {strategy: strategy}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});

return this;
};

/**
* Get credential information of the specified <strategy> for the current user.
*
* @param strategy
* @param options
* @param cb
*/
Kuzzle.prototype.getMyCredentials = function (strategy, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.query({controller: 'auth', action: 'getMyCredentials'}, {strategy: strategy}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});
};

/**
* Update credentials of the specified <strategy> for the current user.
*
* @param strategy
* @param credentals
* @param options
* @param cb
* @returns {Kuzzle}
*/
Kuzzle.prototype.updateMyCredentials = function (strategy, credentials, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.query({controller: 'auth', action: 'updateMyCredentials'}, {strategy: strategy, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});

return this;
};

/**
* Validate credentials of the specified <strategy> for the current user.
*
* @param strategy
* @param credentials
* @param options
* @param cb
*/
Kuzzle.prototype.validateMyCredentials = function (strategy, credentials, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.query({controller: 'auth', action: 'validateMyCredentials'}, {strategy: strategy, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});
};

/**
* Create a kuzzle index
*
Expand Down
193 changes: 193 additions & 0 deletions src/security/Security.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,197 @@ Security.prototype.getUserRights = function (userId, options, cb) {
});
};

/**
* Create credentials of the specified <strategy> for the user <kuid>.
*
* @param strategy
* @param kuid
* @param credentials
* @param options
* @param cb
* @returns {Security}
*/
Security.prototype.createCredentials = function (strategy, kuid, credentials, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'createCredentials'}, {_id: kuid, strategy: strategy, body: credentials}, options, function(err, res) {
if (!err) {
cb && cb(null, res.result._source);
} else {
cb && cb(err);
}
});

return this;
};

/**
* Delete credentials of the specified <strategy> for the user <kuid> .
*
* @param strategy
* @param kuid
* @param options
* @param cb
* @returns {Security}
*/
Security.prototype.deleteCredentials = function (strategy, kuid, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'deleteCredentials'}, {strategy: strategy, _id: kuid}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});

return this;
};

/**
* Retrieve a list of accepted fields per authentication strategy.
*
* @param options
* @param cb
*/
Security.prototype.getAllCredentialFields = function (options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'getAllCredentialFields'}, {}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});
};

/**
* Retrieve the list of accepted field names by the specified <strategy>.
*
* @param strategy
* @param options
* @param cb
*/
Security.prototype.getCredentialFields = function (strategy, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'getCredentialFields'}, {strategy: strategy}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});
};

/**
* Get credential information of the specified <strategy> for the user <kuid>.
*
* @param strategy
* @param kuid
* @param options
* @param cb
*/
Security.prototype.getCredentials = function (strategy, kuid, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'getCredentials'}, {strategy: strategy, _id: kuid}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});
};

/**
* Check the existence of the specified <strategy>’s credentials for the user <kuid>.
*
* @param strategy
* @param kuid
* @param options
* @param cb
*/
Security.prototype.hasCredentials = function (strategy, kuid, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'hasCredentials'}, {strategy: strategy, _id: kuid}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});
};

/**
* Updates credentials of the specified <strategy> for the user <kuid>.
*
* @param strategy
* @param kuid
* @param credentials
* @param options
* @param cb
* @returns {Security}
*/
Security.prototype.updateCredentials = function (strategy, kuid, credentials, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'updateCredentials'}, {strategy: strategy, _id: kuid, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});

return this;
};

/**
* Validate credentials of the specified <strategy> for the user <kuid>.
*
* @param strategy
* @param kuid
* @param credentials
* @param options
* @param cb
*/
Security.prototype.validateCredentials = function (strategy, kuid, credentials, options, cb) {
if (!cb && typeof options === 'function') {
cb = options;
options = null;
}

this.kuzzle.query({controller: 'security', action: 'validateCredentials'}, {strategy: strategy, _id: kuid, body: credentials}, options, typeof cb !== 'function' ? null : function(err, res) {
if (!err) {
cb && cb(null, res.result);
} else {
cb && cb(err);
}
});
};

module.exports = Security;
1 change: 1 addition & 0 deletions test/kuzzle/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ describe('Kuzzle constructor', function () {
});

kuzzle.query = function(queryArgs, query, options, cb) {
should(query.strategy).be.eql('local');
cb(null, {result: {jwt: 'test-toto'}});
};

Expand Down
Loading