Skip to content
Merged
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
122 changes: 122 additions & 0 deletions src/Kuzzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if !strategy?

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if !strategy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to all the following methods that accept strategy as the first argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then kuzzle wil answer an error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok then we assume that we leave the responsibility to Kuzzle. Approving.

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;
Loading