UNPKG

@intuitionrobotics/google-services

Version:
49 lines 2.36 kB
"use strict"; 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthModule = exports.AuthModule_Class = void 0; const ts_common_1 = require("@intuitionrobotics/ts-common"); const google_auth_library_1 = require("google-auth-library"); class AuthModule_Class extends ts_common_1.Module { constructor() { super("AuthModule"); } getAuth(authKey, scopes, version = 'v2', clientOptions) { const authConfig = this.getAuthConfig(authKey); let opts; if (typeof authConfig === 'string') { opts = { keyFile: authConfig, scopes, clientOptions }; } else { opts = { credentials: authConfig, scopes, clientOptions }; } return { version, auth: new google_auth_library_1.GoogleAuth(opts) }; } getAuthConfig(authKey) { const projectAuth = this.config.auth[authKey]; if (!projectAuth) throw new ts_common_1.ImplementationMissingException(`Config of AuthModule_Class for authKey: ${authKey} was not found`); return projectAuth; } getJWT(authKey, scopes) { return __awaiter(this, void 0, void 0, function* () { const authConfig = this.getAuthConfig(authKey); if (typeof authConfig === 'string') { return new google_auth_library_1.JWT({ keyFile: authConfig, scopes }).authorize(); } throw new ts_common_1.NotImplementedYetException("cannot create a JWT from a raw credentials.. need path to file"); }); } ; } exports.AuthModule_Class = AuthModule_Class; exports.AuthModule = new AuthModule_Class(); //# sourceMappingURL=AuthModule.js.map