botpress
Version:
The world's first CMS for bots. Easily create, manage and extend chatbots.
93 lines (81 loc) • 2.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* Security Provider
* @private
* @module security
*/
class AbstractAuthenticationProvider {
constructor(options) {
Object.assign(this, options);
}
/**
* @abstract
* @description Login a user to the configured provider
* @return {object} An authenticated User object or false if invalid login
*/
login() {
throw new Error('Abstract Class: Needs to be implemented');
}
/**
* @abstract
* @description Returns a fresh token from an old (but still active) token
* @return {{ success: bool, token: string, reason: string }} A token object
*/
refreshToken() {
throw new Error('Abstract Class: Needs to be implemented');
}
/**
* Authenticates a user from an authentication header
* @description Example of header is: "bearer your_token_here"
* @return {object} An authenticated User object or false if invalid login
*/
authenticate(authHeader) {
var _this = this;
return _asyncToGenerator(function* () {
try {
return yield _this.authenticateWithError(authHeader);
} catch (err) {
_this.logger.debug('[Login]', err.message);
return false;
}
})();
}
/**
* @abstract
*/
authenticateWithError() {
return _asyncToGenerator(function* () {
throw new Error('Abstract Class: Needs to be implemented');
})();
}
/**
* @abstract
* @description Retrieve the user's identity from an authentication token
* @return {object} An authenticated User object or false if invalid token
*/
getUserIdentity() {
throw new Error('Abstract Class: Needs to be implemented');
}
/**
* @abstract
* @description Returns information about the authentication provider and authentication status
* @return {Object} Varies from provider to the other
*/
getAuthenticationInfo() {
throw new Error('Abstract Class: Needs to be implemented');
}
/**
* @abstract
* @description Returns a public JWT certificate or a private JWT key used to sign tokens and validate its origin
* @return {String} The public certificate or private secret
*/
getJWTSecretOrCertificate() {
throw new Error('Abstract Class: Needs to be implemented');
}
}
exports.default = AbstractAuthenticationProvider;
//# sourceMappingURL=provider.js.map