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AAS,QAAU,KAAK,MAC1B,IAEA,IAAS,QAAU,KAGhB,IAAS,WACZ,IACE,IAAI,QAAa,KAAK,OAAO,YAAY,GACzC,KAAK,MAAM,GAAY,CACrB,YACA,WAAY,EAAK,OACjB,QAAS,IAEb,CAAE,MAAO,GACP,IAAI,EAAM,QACZ,CAGF,OAAO,IAAS,YAAc,EAChC,EAIF,QAAQ,QAAU","file":"/npm/verdaccio-gitlab-oauth@1.0.4/dist/server.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/verdaccio-gitlab-oauth@1.0.4/dist/server.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\nfunction _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\nvar lodash = require('lodash');\nvar querystring = require('querystring');\nvar got = _interopDefault(require('got'));\nvar chalk = _interopDefault(require('chalk'));\nvar express = require('express');\nvar fs = require('fs');\nvar globalAgent = require('global-agent');\n\nfunction _defineProperty(obj, key, value) {\n  if (key in obj) {\n    Object.defineProperty(obj, key, {\n      value: value,\n      enumerable: true,\n      configurable: true,\n      writable: true\n    });\n  } else {\n    obj[key] = value;\n  }\n\n  return obj;\n}\n\nclass GitLabClient {\n  constructor(gitlabHost) {\n    this.gitlabHost = gitlabHost;\n\n    _defineProperty(this, \"defaultOptions\", {\n      json: true\n    });\n\n    _defineProperty(this, \"getAuthorizationUrl\", (clientId, redirectUri) => {\n      const query = {\n        client_id: clientId,\n        redirect_uri: redirectUri,\n        response_type: \"code\",\n        scope: \"read_user openid\"\n      };\n      return this.webBaseUrl + `/oauth/authorize?` + querystring.stringify(query).replace('%20', '+');\n    });\n\n    _defineProperty(this, \"requestAccessToken\", async (code, clientId, clientSecret, redirect_uri) => {\n      const url = this.webBaseUrl + \"/oauth/token\";\n      const options = {\n        body: {\n          client_id: clientId,\n          client_secret: clientSecret,\n          code: code,\n          redirect_uri: redirect_uri,\n          grant_type: \"authorization_code\"\n        }\n      };\n      return this.request(url, options);\n    });\n\n    _defineProperty(this, \"requestUser\", async accessToken => {\n      const url = this.webBaseUrl + \"/oauth/userinfo\";\n      const options = {\n        headers: {\n          Authorization: \"Bearer \" + accessToken\n        }\n      };\n      return this.request(url, options);\n    });\n  }\n\n  get webBaseUrl() {\n    return this.gitlabHost || \"https://gitlab.com\";\n  }\n\n  get apiBaseUrl() {\n    return this.webBaseUrl.replace(/\\/?$/, \"\") + \"/api/v4\";\n  }\n\n  async request(url, additionalOptions) {\n    const options = lodash.merge({}, this.defaultOptions, additionalOptions);\n    const response = await got(url, options);\n    return response.body;\n  }\n\n}\n\n// This is duplicated here because it is unfortunately not availabel via API.\nconst TIME_EXPIRATION_7D = \"7d\";\nconst defaultWebTokenOptions = {\n  sign: {\n    // The expiration token for the website is 7 days\n    expiresIn: TIME_EXPIRATION_7D\n  },\n  verify: {}\n};\nconst defaultApiTokenConf = {\n  legacy: true\n};\nconst defaultSecurity = {\n  web: defaultWebTokenOptions,\n  api: defaultApiTokenConf\n};\nfunction getSecurity(config) {\n  if (lodash.isNil(config.security) === false) {\n    return lodash.merge(defaultSecurity, config.security);\n  }\n\n  return defaultSecurity;\n}\n\nconst pluginName = \"gitlab-oauth\";\nfunction getConfig(config, key) {\n  const value =  lodash.get(config, `middlewares[${pluginName}][${key}]`) || lodash.get(config, `auth[${pluginName}][${key}]`);\n  return process.env[value] || value;\n}\n/**\n * user_agent: e.g. \"verdaccio/4.3.4\" --> 4\n */\n\nfunction getMajorVersion(config) {\n  return +config.user_agent[10];\n}\n\nfunction ensurePropExists(config, key) {\n  const value = getConfig(config, key);\n\n  if (!value) {\n    console.error(chalk.red(`[${pluginName}] ERR: Missing configuration \"auth[${pluginName}][${key}]\". Please check your verdaccio config.`));\n    process.exit(1);\n  }\n}\n\nfunction validateConfig(config) {\n  ensurePropExists(config, \"group\");\n  ensurePropExists(config, \"client-id\");\n  ensurePropExists(config, \"client-secret\");\n}\n\nclass Callback {\n  constructor(config, auth) {\n    this.config = config;\n    this.auth = auth;\n\n    _defineProperty(this, \"requiredGroup\", getConfig(this.config, \"group\"));\n\n    _defineProperty(this, \"clientId\", getConfig(this.config, \"client-id\"));\n\n    _defineProperty(this, \"clientSecret\", getConfig(this.config, \"client-secret\"));\n\n    _defineProperty(this, \"gitlabHost\", getConfig(this.config, \"gitlab-host\"));\n\n    _defineProperty(this, \"gitlab\", new GitLabClient(this.gitlabHost));\n\n    _defineProperty(this, \"version\", getMajorVersion(this.config));\n\n    _defineProperty(this, \"middleware\", async (req, res, next) => {\n      try {\n        const code = req.query.code;\n        const callbackUrl = Callback.getCallbackUrl(req, this.config);\n        const gitlabOauth = await this.gitlab.requestAccessToken(code, this.clientId, this.clientSecret, callbackUrl);\n        const gitlabUser = await this.gitlab.requestUser(gitlabOauth.access_token);\n\n        if (this.requiredGroup == \"*\" || gitlabUser.groups.includes(this.requiredGroup)) {\n          await this.grantAccess(res, gitlabOauth, gitlabUser);\n        } else {\n          await this.denyAccess(res);\n        }\n      } catch (error) {\n        next(error);\n      }\n    });\n  }\n  /**\n   * After a successful OAuth authentication, gitLab redirects back to us.\n   * We use the OAuth code to get an OAuth access token and the username associated\n   * with the GitLab account.\n   *\n   * The token and username are encryped and base64 encoded and configured as npm\n   * credentials for this registry. There is no need to later decode and decrypt the token.\n   * This process is automatically reversed before the token is passed to the authenticate\n   * middleware.\n   *\n   * We then issue a JWT token using these values and pass them back to the frontend\n   * as query parameters so they can be stored in the browser.\n   */\n\n\n  /**\n   * This is where itLab should redirect back to.\n   */\n  static getCallbackUrl(req, config) {\n    return Callback.getRegistryUrl(req, config) + Callback.path;\n  }\n  /**\n   * This is the same as what `npm config get registry` returns.\n   */\n\n\n  static getRegistryUrl(req, config) {\n    const prefix = lodash.get(config, \"url_prefix\", \"\");\n\n    if (prefix) {\n      return prefix.replace(/\\/?$/, \"\"); // Remove potential trailing slash\n    }\n\n    const protocal = req.get(\"X-Forwarded-Proto\") || req.protocol;\n    return protocal + \"://\" + req.get(\"host\");\n  }\n\n  async grantAccess(res, gitlabOauth, gitlabUser) {\n    const npmAuth = gitlabUser.nickname + \":\" + gitlabOauth.access_token;\n    const encryptedNpmToken = this.encrypt(npmAuth);\n    const user = {\n      name: gitlabUser.nickname,\n      groups: [this.requiredGroup],\n      real_groups: [this.requiredGroup]\n    };\n    const encryptedJWT = this.version === 3 ? await this.issueJWTVerdaccio3(user) : await this.issueJWTVerdaccio4(user);\n    const frontendUrl = \"/?\" + querystring.stringify({\n      username: gitlabUser.nickname,\n      jwtToken: encryptedJWT,\n      npmToken: encryptedNpmToken\n    });\n    res.redirect(frontendUrl);\n  }\n\n  denyAccess(res) {\n    res.send(`\n      Access denied: you are not a member of \"${this.requiredGroup}\"<br>\n      <a href=\"/\">Go back</a>\n    `);\n  } // https://github.com/verdaccio/verdaccio/blob/3.x/src/api/web/endpoint/user.js#L15\n\n\n  async issueJWTVerdaccio3(user) {\n    return this.auth.issueUIjwt(user, \"24h\");\n  } // https://github.com/verdaccio/verdaccio/blob/master/src/api/web/endpoint/user.ts#L31\n\n\n  async issueJWTVerdaccio4(user) {\n    const jWTSignOptions = getSecurity(this.config).web.sign;\n    return this.auth.jwtEncrypt(user, jWTSignOptions);\n  }\n\n  encrypt(text) {\n    return this.auth.aesEncrypt(new Buffer(text)).toString(\"base64\");\n  }\n\n}\n\n_defineProperty(Callback, \"path\", \"/-/oauth/callback\");\n\nclass Authorization {\n  constructor(config) {\n    this.config = config;\n\n    _defineProperty(this, \"clientId\", getConfig(this.config, \"client-id\"));\n\n    _defineProperty(this, \"gitlabHost\", getConfig(this.config, \"gitlab-host\"));\n\n    _defineProperty(this, \"gitlab\", new GitLabClient(this.gitlabHost));\n\n    _defineProperty(this, \"middleware\", (req, res, next) => {\n      try {\n        const id = req.params.id || \"\";\n        const callbackUrl = Callback.getCallbackUrl(req, this.config) + (id ? `/${id}` : \"\");\n        const url = this.gitlab.getAuthorizationUrl(this.clientId, callbackUrl);\n        res.redirect(url);\n      } catch (error) {\n        next(error);\n      }\n    });\n  }\n  /**\n   * Initiates the GitLab OAuth flow by redirecting to GitLab.\n   * The callback URL can be customized by subpathing the request.\n   *\n   * Example:\n   *   A request to `/-/oauth/authorize/cheese-cake` will be called back at\n   *   `/-/oauth/callback/cheese-cake`.\n   */\n\n\n}\n\n_defineProperty(Authorization, \"path\", \"/-/oauth/authorize/:id?\");\n\nconst pluginOAuthId = \"/gitlab-oauth-cli\";\nconst cliAuthorizeUrl = \"/oauth/authorize\";\nconst cliCallbackUrl = \"http://localhost:8239\";\nclass GitlabOAuthCliSupport {\n  constructor(config, auth) {\n    this.config = config;\n    this.auth = auth;\n\n    _defineProperty(this, \"clientId\", getConfig(this.config, \"client-id\"));\n\n    _defineProperty(this, \"clientSecret\", getConfig(this.config, \"client-secret\"));\n\n    _defineProperty(this, \"gitlabHost\", getConfig(this.config, \"gitlab-host\"));\n\n    _defineProperty(this, \"gitlab\", new GitLabClient(this.gitlabHost));\n  }\n  /**\n   * Implements the middleware plugin interface.\n   */\n\n\n  register_middlewares(app) {\n    app.get(cliAuthorizeUrl, (req, res) => {\n      res.redirect(Authorization.path.replace(\"/:id?\", pluginOAuthId));\n    });\n    app.get(Callback.path + pluginOAuthId, async (req, res, next) => {\n      try {\n        const code = req.query.code;\n        const id = req.params.id || \"\";\n        const callbackUrl = Callback.getCallbackUrl(req, this.config) + (id ? `/${id}` : \"\");\n        const gitlabOauth = await this.gitlab.requestAccessToken(code, this.clientId, this.clientSecret, callbackUrl);\n        const gitlabUser = await this.gitlab.requestUser(gitlabOauth.access_token);\n        const npmAuth = gitlabUser.nickname + \":\" + gitlabOauth.access_token;\n        const encryptedNpmToken = this.encrypt(npmAuth);\n        const query = {\n          token: encodeURIComponent(encryptedNpmToken)\n        };\n        const url = cliCallbackUrl + \"?\" + querystring.stringify(query);\n        res.redirect(url);\n      } catch (error) {\n        next(error);\n      }\n    });\n  }\n\n  encrypt(text) {\n    return this.auth.aesEncrypt(new Buffer(text)).toString(\"base64\");\n  }\n\n}\n\nconst publicRoot = __dirname + \"/public\";\n/**\n * Injects additional tags into the DOM that modify the login button.\n */\n\nclass InjectHtml {\n  /**\n   * Serves the injected style and script imports.\n   */\n  constructor(config) {\n    this.config = config;\n\n    _defineProperty(this, \"serveAssetsMiddleware\", express.static(publicRoot));\n\n    _defineProperty(this, \"version\", getMajorVersion(this.config));\n\n    _defineProperty(this, \"scriptTag\", `<script src=\"${InjectHtml.path}/verdaccio-${this.version}.js\"></script>`);\n\n    _defineProperty(this, \"styleTag\", `<style>${fs.readFileSync(`${publicRoot}/verdaccio-${this.version}.css`)}</style>`);\n\n    _defineProperty(this, \"headWithStyle\", [this.styleTag, \"</head>\"].join(\"\"));\n\n    _defineProperty(this, \"bodyWithScript\", [this.scriptTag, \"</body>\"].join(\"\"));\n\n    _defineProperty(this, \"injectAssetsMiddleware\", (req, res, next) => {\n      const send = res.send;\n\n      res.send = html => {\n        html = this.insertImportTags(html);\n        return send.call(res, html);\n      };\n\n      next();\n    });\n\n    _defineProperty(this, \"insertImportTags\", html => {\n      html = String(html);\n\n      if (!html.includes(\"VERDACCIO_API_URL\")) {\n        return html;\n      }\n\n      return html.replace(/<\\/head>/, this.headWithStyle).replace(/<\\/body>/, this.bodyWithScript);\n    });\n  }\n  /**\n   * Monkey-patches `res.send` in order to inject style and script imports.\n   */\n\n\n}\n\n_defineProperty(InjectHtml, \"path\", \"/-/static/\" + pluginName);\n\nfunction registerGlobalProxyAgent() {\n  globalAgent.bootstrap();\n  console.log(`${[pluginName]}] Proxy config:`, JSON.stringify(GLOBAL_AGENT || {}));\n}\n\nconst cacheTTLms = 1000 * 5; // 5s\n\nfunction log(...args) {\n  console.log(`${[pluginName]}`, ...args);\n}\n/**\n * Implements the verdaccio plugin interfaces.\n */\n\n\nclass GitlabOauthUiPlugin {\n  constructor(config) {\n    this.config = config;\n\n    _defineProperty(this, \"requiredGroup\", getConfig(this.config, \"group\"));\n\n    _defineProperty(this, \"gitlabHost\", getConfig(this.config, \"gitlab-host\"));\n\n    _defineProperty(this, \"gitlab\", new GitLabClient(this.gitlabHost));\n\n    _defineProperty(this, \"cache\", {});\n\n    validateConfig(config);\n    registerGlobalProxyAgent();\n  }\n  /**\n   * Implements the middleware plugin interface.\n   */\n\n\n  register_middlewares(app, auth) {\n    if (lodash.get(this.config, \"web.enable\", true)) {\n      const injectHtml = new InjectHtml(this.config);\n      app.use(injectHtml.injectAssetsMiddleware);\n      app.use(InjectHtml.path, injectHtml.serveAssetsMiddleware);\n    }\n\n    const cliSupport = new GitlabOAuthCliSupport(this.config, auth);\n    cliSupport.register_middlewares(app);\n    const authorization = new Authorization(this.config);\n    app.get(Authorization.path, authorization.middleware);\n    const callback = new Callback(this.config, auth);\n    app.get(Callback.path, callback.middleware);\n  }\n  /**\n   * Implements the auth plugin interface.\n   */\n\n\n  async authenticate(username, authToken, cb) {\n    const userOrgs = await this.getGroupNames(username, authToken);\n\n    if (this.requiredGroup == \"*\" || userOrgs.includes(this.requiredGroup)) {\n      cb(null, [this.requiredGroup]);\n    } else {\n      log(`Unauthenticated: user \"${username}\" is not a member of \"${this.requiredGroup}\"`);\n      cb(null, false);\n    }\n  }\n\n  allow_access(user, pkg, cb) {\n    const requiredAccess = [...(pkg.access || [])];\n\n    if (requiredAccess.includes(\"$authenticated\")) {\n      requiredAccess.push(this.config.auth[pluginName].group);\n    }\n\n    const grantedAccess = lodash.intersection(user.groups, requiredAccess);\n\n    if (grantedAccess.length === requiredAccess.length) {\n      cb(null, user.groups);\n    } else {\n      log(`Access denied: user \"${user.name}\" is not a member of \"${this.config.group}\"`);\n      cb(null, false);\n    }\n  }\n\n  async getGroupNames(username, authToken) {\n    const invalidate = () => delete this.cache[username];\n\n    const cached = () => this.cache[username] || {};\n\n    const nearFuture = () => Date.now() + cacheTTLms;\n\n    if (cached().authToken !== authToken) {\n      invalidate();\n    }\n\n    if (cached().expires < Date.now()) {\n      invalidate();\n    } else {\n      cached().expires = nearFuture();\n    }\n\n    if (!cached().groupNames) {\n      try {\n        let user = await this.gitlab.requestUser(authToken);\n        this.cache[username] = {\n          authToken,\n          groupNames: user.groups,\n          expires: nearFuture()\n        };\n      } catch (error) {\n        log(error.message);\n      }\n    }\n\n    return cached().groupNames || [];\n  }\n\n}\n\nexports.default = GitlabOauthUiPlugin;\n"]}