66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
(function(root, factory) {
|
|
if (typeof exports === 'object') {
|
|
// CommonJS
|
|
factory(exports, module);
|
|
} else if (typeof define === 'function' && define.amd) {
|
|
// AMD
|
|
define(['exports', 'module'], factory);
|
|
}
|
|
}(this, function(exports, module) {
|
|
|
|
/**
|
|
* PLAIN `Mechanism` constructor.
|
|
*
|
|
* This class implements the PLAIN SASL mechanism.
|
|
*
|
|
* The PLAIN SASL mechanism provides support for exchanging a clear-text
|
|
* username and password. This mechanism should not be used without adequate
|
|
* security provided by an underlying transport layer.
|
|
*
|
|
* References:
|
|
* - [RFC 4616](http://tools.ietf.org/html/rfc4616)
|
|
*
|
|
* @api public
|
|
*/
|
|
function Mechanism() {
|
|
}
|
|
|
|
Mechanism.prototype.name = 'PLAIN';
|
|
Mechanism.prototype.clientFirst = true;
|
|
|
|
/**
|
|
* Encode a response using given credential.
|
|
*
|
|
* Options:
|
|
* - `username`
|
|
* - `password`
|
|
* - `authzid` authorization identity (optional)
|
|
*
|
|
* @param {Object} cred
|
|
* @api public
|
|
*/
|
|
Mechanism.prototype.response = function(cred) {
|
|
var str = '';
|
|
str += cred.authzid || '';
|
|
str += '\0';
|
|
str += cred.username;
|
|
str += '\0';
|
|
str += cred.password;
|
|
return str;
|
|
};
|
|
|
|
/**
|
|
* Decode a challenge issued by the server.
|
|
*
|
|
* @param {String} chal
|
|
* @return {Mechanism} for chaining
|
|
* @api public
|
|
*/
|
|
Mechanism.prototype.challenge = function(chal) {
|
|
return this;
|
|
};
|
|
|
|
exports = module.exports = Mechanism;
|
|
|
|
}));
|