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IAAI,MAAM,qCAGrB,MAAM,EAAO,EAAa,IAAI,SACxB,OAAE,SAAiB,EAAO,SAAS,CACrC,KAAM,EACN,aAAc,EAAY,aAE9B,EAAO,YAAc,EACrB,EAAQ,GACR,EAAI,IAAI,2DACZ,CACA,MAAO,GACH,EAAO,EACX,CACA,QAEI,EAAO,SACX,KAEJ,IAAI,EAAa,IACb,EAAQ,UAER,EAAa,EAEa,KAArB,EAAY,OACjB,EAAa,OAAO,EAAY,OAEpC,EAAO,OAAO,GAAY,KACtB,MAAM,EAAU,EAAO,UACnB,cAAc,KACd,EAAY,KAAO,OAAO,EAAQ,OAEtC,MAAM,EAAS,OAAO,EAAQ,QAAU,IAElC,EAAe,EAAO,gBAAgB,CACxC,aAAc,EAAY,WAC1B,YAAa,UACb,MAAO,EAAO,KAAK,OAEvB,IAAI,EAAc,CAAE,MAAM,IAAS,MAAK,GAAM,EAAG,SAAQ,IAE7D,UAAU,EAAO,GAEzB,CACA,QAAQ,aAAe","file":"/npm/@google-cloud/local-auth@3.0.1/build/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@google-cloud/local-auth@3.0.1/build/src/index.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// Copyright 2020 Google LLC\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//    http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.authenticate = void 0;\n/**\n * This is used by several samples to easily provide an oauth2 workflow.\n */\nconst google_auth_library_1 = require(\"google-auth-library\");\nconst http = require(\"http\");\nconst url_1 = require(\"url\");\nconst opn = require(\"open\");\nconst arrify = require(\"arrify\");\nconst destroyer = require(\"server-destroy\");\nconst path_1 = require(\"path\");\nconst invalidRedirectUri = `The provided keyfile does not define a valid\nredirect URI. There must be at least one redirect URI defined, and this sample\nassumes it redirects to 'http://localhost:3000/oauth2callback'.  Please edit\nyour keyfile, and add a 'redirect_uris' section.  For example:\n\n\"redirect_uris\": [\n  \"http://localhost:3000/oauth2callback\"\n]\n`;\nfunction isAddressInfo(addr) {\n    return addr.port !== undefined;\n}\n// Open an http server to accept the oauth callback. In this\n// simple example, the only request to our webserver is to\n// /oauth2callback?code=<code>\nasync function authenticate(options) {\n    var _a;\n    if (!options ||\n        !options.keyfilePath ||\n        typeof options.keyfilePath !== 'string') {\n        throw new Error('keyfilePath must be set to the fully qualified path to a GCP credential keyfile.');\n    }\n    // eslint-disable-next-line @typescript-eslint/no-var-requires\n    const keyFile = require((0, path_1.resolve)(options.keyfilePath));\n    const keys = keyFile.installed || keyFile.web;\n    if (!keys.redirect_uris || keys.redirect_uris.length === 0) {\n        throw new Error(invalidRedirectUri);\n    }\n    const redirectUri = new url_1.URL((_a = keys.redirect_uris[0]) !== null && _a !== void 0 ? _a : 'http://localhost');\n    if (redirectUri.hostname !== 'localhost') {\n        throw new Error(invalidRedirectUri);\n    }\n    // create an oAuth client to authorize the API call\n    const client = new google_auth_library_1.OAuth2Client({\n        clientId: keys.client_id,\n        clientSecret: keys.client_secret,\n    });\n    return new Promise((resolve, reject) => {\n        const server = http.createServer(async (req, res) => {\n            try {\n                const url = new url_1.URL(req.url, 'http://localhost:3000');\n                if (url.pathname !== redirectUri.pathname) {\n                    res.end('Invalid callback URL');\n                    return;\n                }\n                const searchParams = url.searchParams;\n                if (searchParams.has('error')) {\n                    res.end('Authorization rejected.');\n                    reject(new Error(searchParams.get('error')));\n                    return;\n                }\n                if (!searchParams.has('code')) {\n                    res.end('No authentication code provided.');\n                    reject(new Error('Cannot read authentication code.'));\n                    return;\n                }\n                const code = searchParams.get('code');\n                const { tokens } = await client.getToken({\n                    code: code,\n                    redirect_uri: redirectUri.toString(),\n                });\n                client.credentials = tokens;\n                resolve(client);\n                res.end('Authentication successful! Please return to the console.');\n            }\n            catch (e) {\n                reject(e);\n            }\n            finally {\n                // eslint-disable-next-line @typescript-eslint/no-explicit-any\n                server.destroy();\n            }\n        });\n        let listenPort = 3000;\n        if (keyFile.installed) {\n            // Use emphemeral port if not a web client\n            listenPort = 0;\n        }\n        else if (redirectUri.port !== '') {\n            listenPort = Number(redirectUri.port);\n        }\n        server.listen(listenPort, () => {\n            const address = server.address();\n            if (isAddressInfo(address)) {\n                redirectUri.port = String(address.port);\n            }\n            const scopes = arrify(options.scopes || []);\n            // open the browser to the authorize url to start the workflow\n            const authorizeUrl = client.generateAuthUrl({\n                redirect_uri: redirectUri.toString(),\n                access_type: 'offline',\n                scope: scopes.join(' '),\n            });\n            opn(authorizeUrl, { wait: false }).then(cp => cp.unref());\n        });\n        destroyer(server);\n    });\n}\nexports.authenticate = authenticate;\n"]}