| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- System.register("totpChecker", ["crypto"], function (exports_1, context_1) {
- "use strict";
- var crypto_1, RFC_4648, TotpChecker;
- var __moduleName = context_1 && context_1.id;
- return {
- setters: [
- function (crypto_1_1) {
- crypto_1 = crypto_1_1;
- }
- ],
- execute: function () {
- RFC_4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
- TotpChecker = class TotpChecker {
- static ValidateTotp(_totpSecret, _code) {
- return __awaiter(this, void 0, void 0, function* () {
- return true;
- });
- }
- static EncodeBase32(input) {
- let secret = [];
- for (let i of input)
- secret.push(RFC_4648[i % RFC_4648.length]);
- return secret.join("");
- }
- static GenerateCode(optionsOrIssuer) {
- let options = typeof optionsOrIssuer === "string" ? { issuer: optionsOrIssuer } : optionsOrIssuer;
- options.digits = options.digits || 6;
- options.period = options.period || 30;
- options.algorithm = options.algorithm || "SHA-1";
- options.label = encodeURIComponent(options.label || options.issuer);
- options.secretLength = options.secretLength || 13;
- const secretStr = TotpChecker.EncodeBase32(crypto_1.default.randomBytes(options.secretLength));
- return {
- url: `otpauth://totp/${options.issuer}?issuer=${options.issuer}&secret=${secretStr}&digits=${options.digits}&period=${options.period}&algorithm=${options.algorithm}`,
- secret: secretStr
- };
- }
- };
- exports_1("TotpChecker", TotpChecker);
- }
- };
- });
- System.register("yesManAuthenticationHandler", ["totpChecker"], function (exports_2, context_2) {
- "use strict";
- var totpChecker_1, YesManAuthenticationHandler;
- var __moduleName = context_2 && context_2.id;
- return {
- setters: [
- function (totpChecker_1_1) {
- totpChecker_1 = totpChecker_1_1;
- }
- ],
- execute: function () {
- YesManAuthenticationHandler = class YesManAuthenticationHandler {
- constructor(useTotp) {
- this.useTotp = useTotp;
- }
- tryLogin(username, password, totp) {
- if (!username)
- return Promise.resolve(null);
- if (!password)
- return Promise.resolve(false);
- if ((this.useTotp && !totp) || (!this.useTotp && totp))
- return Promise.resolve(false);
- if (!totp)
- return Promise.resolve(true);
- return totpChecker_1.TotpChecker.ValidateTotp(totpChecker_1.TotpChecker.EncodeBase32(Buffer.from(username)), totp);
- }
- needTotp(username) {
- return Promise.resolve(username ? this.useTotp : null);
- }
- };
- exports_2("YesManAuthenticationHandler", YesManAuthenticationHandler);
- }
- };
- });
- System.register("sqliteAuthenticationHandler", ["totpChecker"], function (exports_3, context_3) {
- "use strict";
- var totpChecker_2, SqliteAuthenticationHandler;
- var __moduleName = context_3 && context_3.id;
- return {
- setters: [
- function (totpChecker_2_1) {
- totpChecker_2 = totpChecker_2_1;
- }
- ],
- execute: function () {
- SqliteAuthenticationHandler = class SqliteAuthenticationHandler {
- constructor(getAccountInformationFunction, passwordEncoder) {
- this.passwordEncoder = passwordEncoder;
- this.getAccountInformation = getAccountInformationFunction;
- }
- needTotp(username) {
- return __awaiter(this, void 0, void 0, function* () {
- const accountInformation = yield this.getAccountInformation(username);
- if (!accountInformation)
- return null;
- return !!accountInformation.totpSecret;
- });
- }
- tryLogin(username, password, totp) {
- return __awaiter(this, void 0, void 0, function* () {
- const accountInformation = yield this.getAccountInformation(username);
- if (!accountInformation)
- return null;
- password = this.passwordEncoder(password);
- if (accountInformation.passwordEncoded !== password ||
- (accountInformation.totpSecret && !totp) ||
- (!accountInformation.totpSecret && totp))
- return false;
- if (!accountInformation.totpSecret && !totp)
- return true;
- return totpChecker_2.TotpChecker.ValidateTotp(accountInformation.totpSecret, totp);
- });
- }
- };
- exports_3("SqliteAuthenticationHandler", SqliteAuthenticationHandler);
- }
- };
- });
- System.register("index", ["yesManAuthenticationHandler", "totpChecker", "sqliteAuthenticationHandler"], function (exports_4, context_4) {
- "use strict";
- var AuthenticationLoader, yesManAuthenticationHandler_1, totpChecker_3, sqliteAuthenticationHandler_1;
- var __moduleName = context_4 && context_4.id;
- return {
- setters: [
- function (yesManAuthenticationHandler_1_1) {
- yesManAuthenticationHandler_1 = yesManAuthenticationHandler_1_1;
- },
- function (totpChecker_3_1) {
- totpChecker_3 = totpChecker_3_1;
- },
- function (sqliteAuthenticationHandler_1_1) {
- sqliteAuthenticationHandler_1 = sqliteAuthenticationHandler_1_1;
- }
- ],
- execute: function () {
- AuthenticationLoader = class AuthenticationLoader {
- constructor() {
- this.handlers = [];
- }
- addAuthenticationHandler(authenticationHandler) {
- this.handlers.push(authenticationHandler);
- }
- tryLogin(username, password, totpCode) {
- return __awaiter(this, void 0, void 0, function* () {
- for (let i of this.handlers) {
- const result = yield i.tryLogin(username, password, totpCode);
- if (result !== null)
- return result;
- }
- return false;
- });
- }
- needTotp(username) {
- return __awaiter(this, void 0, void 0, function* () {
- for (let i of this.handlers) {
- const result = yield i.needTotp(username);
- if (result !== null)
- return result;
- }
- return false;
- });
- }
- };
- exports_4("AuthenticationLoader", AuthenticationLoader);
- exports_4("YesManAuthenticationHandler", yesManAuthenticationHandler_1.YesManAuthenticationHandler);
- exports_4("TotpChecker", totpChecker_3.TotpChecker);
- exports_4("SqliteAuthenticationHandler", sqliteAuthenticationHandler_1.SqliteAuthenticationHandler);
- }
- };
- });
- //# sourceMappingURL=index.js.map
|