UNPKG

@sync-in/server

Version:

The secure, open-source platform for file storage, sharing, collaboration, and sync

54 lines (53 loc) 2.4 kB
/* * Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com> * This file is part of Sync-in | The open source file sync and share solution * See the LICENSE file for licensing details */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "AuthBasicGuard", { enumerable: true, get: function() { return AuthBasicGuard; } }); const _common = require("@nestjs/common"); const _passport = require("@nestjs/passport"); const _applicationsconstants = require("../../applications/applications.constants"); const _routes = require("../../applications/webdav/constants/routes"); function _ts_decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } let AuthBasicGuard = class AuthBasicGuard extends (0, _passport.AuthGuard)('basic') { canActivate(ctx) { // allow options method on server (webdav) const req = this.getRequest(ctx); if (req.method === _applicationsconstants.HTTP_METHOD.OPTIONS) { // only allow options method to skip auth check on the server and webdav paths (including child uris) const segments = req.originalUrl.split('/').filter(Boolean); if (!segments.length || segments[0] === _routes.WEBDAV_BASE_PATH) { return true; } } return super.canActivate(ctx); } handleRequest(err, user, info, ctx, status) { const req = this.getRequest(ctx); req.raw.user = user?.login || 'unauthorized'; if (info) { this.logger.warn(`<${req.raw.user}> <${req.ip}> ${info}`); } return super.handleRequest(err, user, info, ctx, status); } constructor(...args){ super(...args), this.logger = new _common.Logger(AuthBasicGuard.name); } }; AuthBasicGuard = _ts_decorate([ (0, _common.Injectable)() ], AuthBasicGuard); //# sourceMappingURL=auth-basic.guard.js.map