Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { google } from 'googleapis';
- export async function getAccessToken(scopes: string[]): Promise<string | null> {
- const key = require(SERVICE_ACCOUNT_JSON_FILE_PATH);
- const jwtClient = new google.auth.JWT(
- key.client_email,
- undefined,
- key.private_key,
- scopes,
- undefined
- );
- const result = await jwtClient.authorize();
- const accessToken = result.access_token;
- if (accessToken) {
- console.log(accessToken);
- return accessToken;
- } else {
- console.log('Provided service account does not have permission to generate access tokens');
- return null;
- }
- }
Add Comment
Please, Sign In to add comment