@intuitionrobotics/google-services
Version:
34 lines • 1.39 kB
JavaScript
import { ImplementationMissingException, Module, NotImplementedYetException } from "@intuitionrobotics/ts-common";
import { JWT, GoogleAuth, } from "google-auth-library";
export class AuthModule_Class extends 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 GoogleAuth(opts) };
}
getAuthConfig(authKey) {
const projectAuth = this.config.auth[authKey];
if (!projectAuth)
throw new ImplementationMissingException(`Config of AuthModule_Class for authKey: ${authKey} was not found`);
return projectAuth;
}
async getJWT(authKey, scopes) {
const authConfig = this.getAuthConfig(authKey);
if (typeof authConfig === 'string') {
return new JWT({ keyFile: authConfig, scopes }).authorize();
}
throw new NotImplementedYetException("cannot create a JWT from a raw credentials.. need path to file");
}
;
}
export const AuthModule = new AuthModule_Class();
//# sourceMappingURL=AuthModule.js.map