UNPKG

verdaccio-passport-google-oauth-ui

Version:

<h1 align="center"> 📦🔐 Verdaccio Google OAuth </h1>

647 lines (574 loc) 28 kB
var $jyUGL$dotenv = require("dotenv"); var $jyUGL$verdacciocore = require("@verdaccio/core"); var $jyUGL$express = require("express"); var $jyUGL$picocolors = require("picocolors"); var $jyUGL$passportgoogleoauth = require("passport-google-oauth"); var $jyUGL$passport = require("passport"); var $jyUGL$verdacciourl = require("@verdaccio/url"); var $jyUGL$lodashget = require("lodash/get"); var $jyUGL$ow = require("ow"); var $jyUGL$process = require("process"); var $jyUGL$verdacciopackagejson = require("verdaccio/package.json"); var $jyUGL$globalagent = require("global-agent"); var $jyUGL$lodashmerge = require("lodash/merge"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } function $parcel$interopDefault(a) { return a && a.__esModule ? a.default : a; } function $parcel$defineInteropFlag(a) { Object.defineProperty(a, '__esModule', {value: true, configurable: true}); } var $parcel$global = globalThis; var $parcel$modules = {}; var $parcel$inits = {}; var parcelRequire = $parcel$global["parcelRequiree687"]; if (parcelRequire == null) { parcelRequire = function(id) { if (id in $parcel$modules) { return $parcel$modules[id].exports; } if (id in $parcel$inits) { var init = $parcel$inits[id]; delete $parcel$inits[id]; var module = {id: id, exports: {}}; $parcel$modules[id] = module; init.call(module.exports, module, module.exports); return module.exports; } var err = new Error("Cannot find module '" + id + "'"); err.code = 'MODULE_NOT_FOUND'; throw err; }; parcelRequire.register = function register(id, init) { $parcel$inits[id] = init; }; $parcel$global["parcelRequiree687"] = parcelRequire; } var parcelRegister = parcelRequire.register; parcelRegister("c0egw", function(module, exports) { $parcel$export(module.exports, "publicRoot", () => publicRoot); $parcel$export(module.exports, "staticPath", () => staticPath); var $27UeD = parcelRequire("27UeD"); // Parcel will replace `__dirname` with the directory of the source file during // the build. Using `eval` prevents this static analysis and substitution, // allowing us to access the `__dirname` of the compiled output file at runtime // to locate the adjacent client assets. const fileDirectory = eval("__dirname"); const publicRoot = fileDirectory + "/../client"; const staticPath = "/-/static/" + (0, $27UeD.pluginKey); }); parcelRegister("27UeD", function(module, exports) { $parcel$export(module.exports, "pluginKey", () => $18c7db52fd1235ab$export$18d4026d1ea86bb1); $parcel$export(module.exports, "authorizePath", () => $18c7db52fd1235ab$export$42fcb85fa5803dac); $parcel$export(module.exports, "callbackPath", () => $18c7db52fd1235ab$export$9e960429933a7149); $parcel$export(module.exports, "authenticatedUserGroups", () => $18c7db52fd1235ab$export$827c2d0b213c39b9); $parcel$export(module.exports, "plugin", () => (/*@__PURE__*/$parcel$interopDefault((parcelRequire("crzrf"))))); var $crzrf = parcelRequire("crzrf"); const $18c7db52fd1235ab$export$3a689f099db7e338 = (0, (/*@__PURE__*/$parcel$interopDefault($crzrf))).name; const $18c7db52fd1235ab$export$18d4026d1ea86bb1 = (0, (/*@__PURE__*/$parcel$interopDefault($crzrf))).name.replace("verdaccio-", ""); const $18c7db52fd1235ab$export$42fcb85fa5803dac = "/-/oauth/authorize"; const $18c7db52fd1235ab$export$9e960429933a7149 = "/-/oauth/callback"; const $18c7db52fd1235ab$export$cf98473208e53590 = $18c7db52fd1235ab$export$42fcb85fa5803dac; const $18c7db52fd1235ab$export$bd46c9d2d39fc9 = "/"; const $18c7db52fd1235ab$export$3c6c1020e175037c = 8239; const $18c7db52fd1235ab$export$32fbdff0ec95e1c6 = "cli"; const $18c7db52fd1235ab$export$b3d17af05dbcae2f = "/oauth/authorize"; const $18c7db52fd1235ab$export$827c2d0b213c39b9 = [ "$all", "@all", "$authenticated", "@authenticated" ]; }); parcelRegister("crzrf", function(module, exports) { module.exports = JSON.parse("{\"$schema\":\"http://json.schemastore.org/package\",\"name\":\"verdaccio-passport-google-oauth-ui\",\"version\":\"0.1.10\",\"keywords\":[\"authentication\",\"google\",\"login\",\"npm\",\"oauth\",\"package\",\"passport\",\"private\",\"registry\",\"verdaccio\",\"verdaccio-auth\",\"verdaccio-auth-plugin\",\"verdaccio-plugin\"],\"bugs\":\"https://github.com/okayasu/verdaccio-passport-google-oauth-ui/issues\",\"repository\":{\"url\":\"git+https://github.com/okayasu/verdaccio-passport-google-oauth-ui.git\"},\"license\":\"MIT\",\"author\":\"Masanori Okayasu\",\"main\":\"dist/server/index.js\",\"bin\":{\"verdaccio-passport-google-oauth-ui\":\"dist/cli/index.js\"},\"files\":[\"dist\",\"verdaccio.yaml\"],\"scripts\":{\"build\":\"bash run build\",\"clean\":\"bash run clean\",\"cli\":\"bash run cli\",\"cli:login\":\"bash run cli-login\",\"cli:publish\":\"bash run cli-publish\",\"cli:whoami\":\"bash run cli-whoami\",\"copy\":\"bash run copy\",\"coverage\":\"vitest --coverage\",\"dev\":\"run-s update start\",\"docker\":\"bash run docker_\",\"fix\":\"run-s format typecheck\",\"format\":\"prettier --write \\\"**/*.{ts,js,css,scss,html,json}\\\"\",\"format:check\":\"prettier --check \\\"**/*.{ts,js,css,scss,html,json}\\\"\",\"prepack\":\"bash run clean && bash run build\",\"start\":\"verdaccio -c verdaccio.yaml\",\"test\":\"vitest\",\"typecheck\":\"bash run typecheck\",\"update\":\"run-s prepack copy\",\"watch\":\"nodemon --watch src --watch verdaccio.yaml --ext ts,css,yaml --exec \\\"bun dev\\\"\"},\"dependencies\":{\"@verdaccio/core\":\"^8.0.0-next-8.31\",\"@verdaccio/url\":\"^13.0.0-next-8.31\",\"copy-to-clipboard\":\"^3.3.3\",\"dotenv\":\"^17.3.1\",\"express\":\"^5.1.0\",\"global-agent\":\"^3.0.0\",\"lodash\":\"^4.17.23\",\"minimist\":\"^1.2.8\",\"open\":\"^11.0.0\",\"ow\":\"^3.1.1\",\"passport\":\"^0.7.0\",\"passport-google-oauth\":\"^2.0.0\",\"picocolors\":\"^1.1.1\"},\"devDependencies\":{\"@parcel/config-default\":\"^2.16.4\",\"@parcel/transformer-typescript-tsc\":\"^2.16.4\",\"@types/express\":\"^5.0.3\",\"@types/global-agent\":\"^3.0.0\",\"@types/lodash\":\"^4.17.24\",\"@types/minimist\":\"^1.2.5\",\"@types/node\":\"^24.12.0\",\"@types/passport\":\"^1.0.17\",\"@types/passport-google-oauth\":\"^1.0.45\",\"@verdaccio/types\":\"^13.0.0-next-8.11\",\"@vitest/coverage-v8\":\"^4.0.18\",\"browserslist\":\"^4.28.1\",\"core-js\":\"^3.48.0\",\"nodemon\":\"^3.1.14\",\"npm-run-all2\":\"^8.0.4\",\"parcel\":\"^2.16.4\",\"prettier\":\"^3.8.1\",\"process\":\"^0.11.10\",\"timekeeper\":\"^2.3.1\",\"type-fest\":\"^5.4.4\",\"typescript\":\"^5.9.3\",\"verdaccio\":\"^6.3.1\",\"verdaccio-htpasswd\":\"^13.0.0-next-8.31\",\"vite-tsconfig-paths\":\"^6.1.1\",\"vitest\":\"^4.0.18\"},\"peerDependencies\":{\"verdaccio\":\">=6\"},\"engines\":{\"node\":\">=20\"},\"publishConfig\":{\"registry\":\"https://registry.npmjs.org/\"},\"targets\":{\"client\":{\"source\":\"src/client/verdaccio-6.ts\",\"distDir\":\"dist/client\",\"context\":\"browser\",\"includeNodeModules\":true},\"server\":{\"source\":\"src/server/index.ts\",\"distDir\":\"dist/server\",\"context\":\"node\",\"outputFormat\":\"commonjs\",\"optimize\":false,\"isLibrary\":true},\"cli\":{\"source\":\"src/cli/index.ts\",\"distDir\":\"dist/cli\",\"context\":\"node\",\"outputFormat\":\"commonjs\",\"optimize\":false}}}"); }); $parcel$defineInteropFlag(module.exports); $parcel$export(module.exports, "default", () => $81a2a9ce08a8660a$export$2e2bcd8739ae039); parcelRequire("27UeD"); var $crzrf = parcelRequire("crzrf"); var $27UeD = parcelRequire("27UeD"); const $2e3858452e5e4e6f$var$prefix = (0, ($parcel$interopDefault($jyUGL$picocolors))).blue(`[${(0, $27UeD.pluginKey)}]`); function $2e3858452e5e4e6f$var$toString(arg) { if (typeof arg === "string") return arg; if (typeof arg === "object") try { return JSON.stringify(arg); } catch { // ignore } return String(arg); } const $2e3858452e5e4e6f$export$af88d00dbe7f521 = { log: (...args)=>{ console.log($2e3858452e5e4e6f$var$prefix, args.map($2e3858452e5e4e6f$var$toString).join(" ")); }, debug: (...args)=>{ console.debug($2e3858452e5e4e6f$var$prefix, (0, ($parcel$interopDefault($jyUGL$picocolors))).gray(args.map($2e3858452e5e4e6f$var$toString).join(" "))); }, error: (...args)=>{ console.error($2e3858452e5e4e6f$var$prefix, (0, ($parcel$interopDefault($jyUGL$picocolors))).red(args.map($2e3858452e5e4e6f$var$toString).join(" "))); } }; $2e3858452e5e4e6f$export$af88d00dbe7f521.log(`Version: ${(0, (/*@__PURE__*/$parcel$interopDefault($crzrf))).name}@${(0, (/*@__PURE__*/$parcel$interopDefault($crzrf))).version}`); var $27UeD = parcelRequire("27UeD"); function $f18b3a3015da1bdb$export$3d55ba16968d5eca(id) { return (0, $27UeD.authorizePath) + "/" + (id || ":id?"); } function $f18b3a3015da1bdb$export$d63ade3310945c4c(id) { return (0, $27UeD.callbackPath) + (id ? "/" + id : ""); } var $27UeD = parcelRequire("27UeD"); const $e52e85e2e0f47504$var$styles = ` html, body { padding: 0; margin: 0; height: 100%; background-color: #e0e0e0; color: #24292F; font-family: Helvetica, sans-serif; position: relative; text-align: center; } .wrap { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } a { color: #3f51b5; } .img { filter: drop-shadow(0 0.5rem 0.5rem #24292F80); width: 100px; } `.trim().replace(/\s+/g, " "); const $e52e85e2e0f47504$var$logo = `<svg class="img" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100"><defs/><defs><filter id="a" width="139.6%" height="140.4%" x="-20%" y="-12%" filterUnits="objectBoundingBox"><feOffset dy="4" in="SourceAlpha" result="shadowOffsetOuter1"/><feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="2.5"/><feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"/><feColorMatrix in="shadowBlurOuter1" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0906646286 0"/></filter><filter id="c" width="167.9%" height="272.7%" x="-34%" y="-50%" filterUnits="objectBoundingBox"><feOffset dy="4" in="SourceAlpha" result="shadowOffsetOuter1"/><feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="2.5"/><feColorMatrix in="shadowBlurOuter1" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0906646286 0"/></filter><path id="b" d="M48 17L33 47h-9L0 0h15l13 25 5-8h15z"/><path id="d" d="M35 11h-7V9h8l2-3h-6V4h7l1-2h-4V0h20l-6 11H35z"/></defs><g fill="none" fill-rule="evenodd"><rect width="100" height="100" fill="#000" rx="37"/><g transform="translate(22 30)"><use fill="#000" filter="url(#a)" xlink:href="#b"/><use fill="#FFF" fill-opacity=".6" xlink:href="#b"/></g><g transform="translate(22 30)"><use fill="#000" filter="url(#c)" xlink:href="#d"/><use fill="#FFF" xlink:href="#d"/></g><path fill="#FFF" d="M55 77h-9L22 30h15l21 41z"/></g></svg>`; function $e52e85e2e0f47504$export$54abf82a1c28d398(body, withBackLink) { const backButton = withBackLink ? `<p><a href="/">Go back</a></p>` : ""; return `<!DOCTYPE html> <html lang="en"> <head> <title>${0, $27UeD.pluginKey}</title> <style>${$e52e85e2e0f47504$var$styles}</style> </head> <body> <div class="wrap"> ${$e52e85e2e0f47504$var$logo} ${body} ${backButton} </div> </body> </html>`; } function $e52e85e2e0f47504$export$1c5ed2c43abe9c5(error, withBackLink) { return $e52e85e2e0f47504$export$54abf82a1c28d398(`<h1>Sorry :(</h1> <p>${error?.message || error}</p>`, withBackLink); } var $27UeD = parcelRequire("27UeD"); function $52aa339448c7ba66$export$f654b28f82155665(config, req) { const urlPrefix = config.url_prefix; const baseUrl = (0, $jyUGL$verdacciourl.getPublicUrl)(urlPrefix, req); const baseUrlWithoutTrailingSlash = baseUrl.replace(/\/$/, ""); return baseUrlWithoutTrailingSlash; } function $52aa339448c7ba66$export$6efe61794e587b4b(userName) { const user = { name: userName, groups: [ ...(0, $27UeD.authenticatedUserGroups) ], // groups returned by GH are not used here and not saved in the JWT token // to avoid Verdaccio granting access based on the outdated groups real_groups: [] }; (0, $2e3858452e5e4e6f$export$af88d00dbe7f521).log("User successfully authenticated:", user); return user; } const $eae2119d3de2a465$var$COOKIE_OPTIONS = { sameSite: true, httpOnly: false, maxAge: 10000 }; class $eae2119d3de2a465$export$dcc64a48664bd665 { verdaccio; config; constructor(verdaccio, config){ this.verdaccio = verdaccio; this.config = config; } initialize(app) { //app.use(passport.initialize()); const conf = { clientID: this.config.clientId, clientSecret: this.config.clientSecret, callbackURL: this.config.redirectUri, passReqToCallback: true }; (0, ($parcel$interopDefault($jyUGL$passport))).use(new (0, $jyUGL$passportgoogleoauth.OAuth2Strategy)(conf, (req, accessToken, refreshToken, profile, done)=>{ //console.log(accessToken); //console.log(profile); // GCP側で権限処理は済んでいるので、ここでは全て許可 return done(null, profile._json); })); } /** * IPluginMiddleware */ register_middlewares(app) { this.initialize(app); app.get((0, $f18b3a3015da1bdb$export$3d55ba16968d5eca)(), this.authorize); app.get((0, $f18b3a3015da1bdb$export$d63ade3310945c4c)(), this.callback); } /** * Initiates the auth flow by redirecting to the provider's login URL. */ authorize = async (req, res, next)=>{ try { (0, ($parcel$interopDefault($jyUGL$passport))).authenticate("google", { session: false, scope: [ "email" ] })(req, res, next); } catch (error) { (0, $2e3858452e5e4e6f$export$af88d00dbe7f521).error(error); next(error); } }; /** * After successful authentication, the auth provider redirects back to us. * We use the code in the query params to get an access token and the username * associated with the account. * * We issue a JWT using these values and pass them back to the frontend as * cookies accessible to JS so they can be stored in the browser. * * The username and token are encrypted and base64 encoded to form a token for * the npm CLI. * * There is no need to later decode and decrypt the token. This process is * automatically reversed by verdaccio before passing it to the plugin. */ callback = async (req, res, next)=>{ const withBackLink = true; try { await (0, ($parcel$interopDefault($jyUGL$passport))).authenticate("google", { session: false, failureRedirect: "/error", failWithError: true }, async (err, user, info)=>{ if (err) // res.status(401).send(buildAccessDeniedPage(withBackLink)): return next(err); if (!user) res.redirect("/"); const userObj = (0, $52aa339448c7ba66$export$6efe61794e587b4b)(user.email); const uiToken = await this.verdaccio.issueUiToken(userObj); const npmToken = await this.verdaccio.issueNpmToken(userObj, info); res.cookie("username", userObj.name, $eae2119d3de2a465$var$COOKIE_OPTIONS); res.cookie("uiToken", uiToken, $eae2119d3de2a465$var$COOKIE_OPTIONS); res.cookie("npmToken", npmToken, $eae2119d3de2a465$var$COOKIE_OPTIONS); return res.redirect("/"); })(req, res, next); } catch (error) { (0, $2e3858452e5e4e6f$export$af88d00dbe7f521).error(error); res.status(500).send((0, $e52e85e2e0f47504$export$1c5ed2c43abe9c5)(error, withBackLink)); } }; } var $27UeD = parcelRequire("27UeD"); function $e1317433b085d6c5$export$c506eb22e615ba4a() { return $jyUGL$verdacciopackagejson.version; } // // Validation // function $e1317433b085d6c5$var$validateVersion() { const version = $e1317433b085d6c5$export$c506eb22e615ba4a(); if (version < "5") throw new Error("This plugin requires verdaccio 5 or above"); } function $e1317433b085d6c5$var$validateNodeExists(config, node) { const path = `[${node}][${(0, $27UeD.pluginKey)}]`; const obj = (0, ($parcel$interopDefault($jyUGL$lodashget)))(config, path, {}); if (!Object.keys(obj).length) throw new Error(`"${node}.${(0, $27UeD.pluginKey)}" must be enabled`); } function $e1317433b085d6c5$var$getConfigValue(config, key, predicate) { let valueOrEnvName = (0, ($parcel$interopDefault($jyUGL$lodashget)))(config, [ "auth", (0, $27UeD.pluginKey), key ]); const value = (0, ($parcel$interopDefault($jyUGL$process))).env[String(valueOrEnvName)] ?? valueOrEnvName; try { (0, ($parcel$interopDefault($jyUGL$ow)))(value, predicate); } catch (error) { (0, $2e3858452e5e4e6f$export$af88d00dbe7f521).error(`Invalid configuration at "auth.${(0, $27UeD.pluginKey)}.${key}": ${error.message} \u{2014} Please check your verdaccio config.`); (0, ($parcel$interopDefault($jyUGL$process))).exit(1); } return value; } class $e1317433b085d6c5$export$9ec2d706c52a0d56 { config; url_prefix; clientId; clientSecret; redirectUri; enterpriseOrigin; cacheTTLms; constructor(config){ this.config = config; $e1317433b085d6c5$var$validateVersion(); $e1317433b085d6c5$var$validateNodeExists(config, "middlewares"); $e1317433b085d6c5$var$validateNodeExists(config, "auth"); this.url_prefix = this.config.url_prefix ?? ""; this.clientId = $e1317433b085d6c5$var$getConfigValue(this.config, "client-id", (0, ($parcel$interopDefault($jyUGL$ow))).string.nonEmpty); this.clientSecret = $e1317433b085d6c5$var$getConfigValue(this.config, "client-secret", (0, ($parcel$interopDefault($jyUGL$ow))).string.nonEmpty); this.redirectUri = $e1317433b085d6c5$var$getConfigValue(this.config, "redirect-uri", (0, ($parcel$interopDefault($jyUGL$ow))).string.nonEmpty); this.parseConfiguredPackageGroups(); } configuredGroupsMap = {}; parsedUsers = []; parsedOrgs = []; parsedTeams = []; parsedRepos = []; isGroupConfigured(group) { return !!this.configuredGroupsMap[group]; } /** * Returns all permission groups used in the Verdacio config. */ parseConfiguredPackageGroups() { const configuredGroups = Object.values(this.config.packages || {}).flatMap((packageConfig)=>{ return [ "access", "publish", "unpublish" ].flatMap((action)=>{ const allowedGroups = packageConfig[action]; if (typeof allowedGroups === "string") return allowedGroups; if (Array.isArray(allowedGroups) && allowedGroups.every((group)=>typeof group === "string")) return allowedGroups; return []; }); }); const configuredGroupsDeduped = [ ...new Set(configuredGroups) ]; configuredGroupsDeduped.forEach((group)=>{ const [providerId, key1, value1, key2, value2, key3] = group.split("/"); if (providerId !== "github") return null; if (key1 === "user" && !key2) { const parsedUser = { group: group, user: value1 }; this.parsedUsers.push(parsedUser); this.configuredGroupsMap[group] = true; } if (key1 === "org" && key2 === "team" && !key3) { const parsedTeam = { group: group, org: value1, team: value2 }; this.parsedTeams.push(parsedTeam); this.configuredGroupsMap[group] = true; } if ((key1 === "org" || key1 === "user") && key2 === "repo" && !key3) { const parsedRepo = { group: group, owner: value1, repo: value2 }; this.parsedRepos.push(parsedRepo); this.configuredGroupsMap[group] = true; } if (key1 === "org" && !key2) { const parsedOrg = { group: group, org: value1 }; this.parsedOrgs.push(parsedOrg); this.configuredGroupsMap[group] = true; } }); } } var $c0egw = parcelRequire("c0egw"); class $db16e73291b78442$export$a0f791cb3d82d3ef { config; constructor(config){ this.config = config; } /** * IPluginMiddleware */ register_middlewares(app) { app.use(this.patchResponse); } /** * Patches `res.send` in order to inject style and script tags. */ patchResponse = (req, res, next)=>{ const send = res.send; res.send = (html)=>{ html = this.insertTags(req, html); return send.call(res, html); }; next(); }; insertTags = (req, html)=>{ html = String(html); if (!html.includes("__VERDACCIO_BASENAME_UI_OPTIONS") && !html.includes("ui-options.js")) return html; const baseUrl = (0, $52aa339448c7ba66$export$f654b28f82155665)(this.config, req); const basePath = `${baseUrl}${(0, $c0egw.staticPath)}`; const scriptUrl = `${basePath}/verdaccio-6.js`; const scriptTag = `<script defer="defer" src="${scriptUrl}"></script>`; return html.replace(/<\/body>/, [ scriptTag, "</body>" ].join("")); }; } function $a3a7d1f0bae21031$export$532884efc244643() { (0, $jyUGL$globalagent.bootstrap)(); const config = JSON.stringify(GLOBAL_AGENT || {}); (0, $2e3858452e5e4e6f$export$af88d00dbe7f521).log("Proxy config:", config); } var $c0egw = parcelRequire("c0egw"); // Most of this is duplicated Verdaccio code because it is unfortunately not available via API. // https://github.com/verdaccio/verdaccio/blob/master/src/lib/auth-utils.ts#L129 const $06ec612bf930d79b$var$TIME_EXPIRATION_7D = "7d"; const $06ec612bf930d79b$var$defaultSecurity = { api: { legacy: true }, web: { sign: { expiresIn: $06ec612bf930d79b$var$TIME_EXPIRATION_7D }, verify: {} } }; function $06ec612bf930d79b$var$getSecurity(config) { return (0, ($parcel$interopDefault($jyUGL$lodashmerge)))({}, $06ec612bf930d79b$var$defaultSecurity, config.security); } class $06ec612bf930d79b$export$8ba2c65662555ea6 { config; security; auth; constructor(config){ this.config = config; this.security = $06ec612bf930d79b$var$getSecurity(this.config); } setAuth(auth) { this.auth = auth; return this; } async issueNpmToken(user, token) { const jwtSignOptions = this.security?.api?.jwt?.sign; if (jwtSignOptions) return this.issueVerdaccio4PlusJWT(user, jwtSignOptions); else return this.encrypt(user.name + ":" + token); } async issueUiToken(user) { const jwtSignOptions = this.security.web.sign; return this.issueVerdaccio4PlusJWT(user, jwtSignOptions); } // https://github.com/verdaccio/verdaccio/blob/master/src/api/web/endpoint/user.ts#L31 async issueVerdaccio4PlusJWT(user, jwtSignOptions) { return this.auth.jwtEncrypt(user, jwtSignOptions); } encrypt(text) { try { // @ts-expect-error: Argument of type 'Buffer<ArrayBuffer>' is not assignable to parameter of type 'string'.ts(2345) return this.auth.aesEncrypt(Buffer.from(text)).toString("base64"); } catch (error) { if (String(error).includes("TypeError")) // Newer versions of Verdaccio accept a string instead of a buffer and // output base64. I don't get why these APIs keep changing. return this.auth.aesEncrypt(text) ?? ""; throw error; } } } function $82ce310c04ea8ba7$var$logAccess(user, pkg, action, grant) { (0, $2e3858452e5e4e6f$export$af88d00dbe7f521).debug({ package: pkg.name, action: action, user: user.name, grant: grant }); } class $82ce310c04ea8ba7$export$901cf72dabf2112a extends (0, $jyUGL$verdacciocore.pluginUtils).Plugin { config; parsedConfig; verdaccio; constructor(config, options){ super(config, options); this.config = config; const fullConfig = options?.config ?? config; this.parsedConfig = new (0, $e1317433b085d6c5$export$9ec2d706c52a0d56)(fullConfig); this.verdaccio = new (0, $06ec612bf930d79b$export$8ba2c65662555ea6)(fullConfig); (0, $a3a7d1f0bae21031$export$532884efc244643)(); } /** * pluginUtils.ExpressMiddleware */ register_middlewares(app, auth) { this.verdaccio.setAuth(auth); // use static files. app.use((0, $c0egw.staticPath), (0, $jyUGL$express.static)((0, $c0egw.publicRoot))); const children = [ new (0, $db16e73291b78442$export$a0f791cb3d82d3ef)(this.parsedConfig), new (0, $eae2119d3de2a465$export$dcc64a48664bd665)(this.verdaccio, this.parsedConfig) ]; for (const child of children)child.register_middlewares(app); } async userNameAndTokenMatch(userName, userToken) { return true; } /** * pluginUtils.Auth */ async authenticate(userName, userToken, callback) { callback(new Error("Signup/Login Not Implemented"), false); } async _allow(user, pkg, action, callback) { if (!user.name) { // let other auth plugins and verdaccio's default handler deal with unauthenticated users $82ce310c04ea8ba7$var$logAccess(user, pkg, action, false); callback(null, false); return; } /* const requiredGroups = pkg[action] as string[] | undefined const userGroups = await this.cache.getGroups(user.name) const grant = !!requiredGroups?.some((group) => userGroups.includes(group)) const grant = pkgAccess?.some((group) => userGroups.includes(group)) */ const grant = true; $82ce310c04ea8ba7$var$logAccess(user, pkg, action, grant); callback(null, grant); } /** * pluginUtils.Auth */ async allow_access(user, pkg, callback) { await this._allow(user, pkg, "access", callback); } /** * IPluginAuth */ async allow_publish(user, pkg, callback) { await this._allow(user, pkg, "publish", callback); } /** * IPluginAuth */ async allow_unpublish(user, pkg, callback) { if (pkg.unpublish === false) { // let verdaccio's default behavior call allow_publish() for authentication callback(null, undefined); return; } if (pkg.unpublish === true) { // `true` is not a valid value - this should never happen - Verdaccio shouldn't even allow us to end up here // this here mostly to satisfy TypeScript and avoid an `as string[]` cast below callback((0, $jyUGL$verdacciocore.errorUtils).getInternalError("Invalid package unpublish configuration"), false); return; } await this._allow(user, pkg, "unpublish", callback); } } (0, ($parcel$interopDefault($jyUGL$dotenv))).config(); var // plugins must be a default export $81a2a9ce08a8660a$export$2e2bcd8739ae039 = (0, $82ce310c04ea8ba7$export$901cf72dabf2112a); //# sourceMappingURL=index.js.map