google-api-common is a wrapper around google-api-nodejs-client that provides simpler javaScript APIs for common functions in following libraries.
Run this to install via NPM
npm i @melkorcba-osl/googleapis-common
This library provides both client side and server side Auth clients.
Requesting Auth Token in Client Side
const grantImplicit = require("@melkorcba-osl/googleapis-common/grant-implicit");
const { getTokenRequestURL } = grantImplicit;
const URL = getTokenRequestURL({
client_id:
"<Client ID>",
redirect_uri: "<Redirect URI>",
scope: ['<list Auth scopes here>'],
response_type: "token",
});
window.location.href = URL
Extracting Token From Url
const grantImplicit = require("@melkorcba-osl/googleapis-common/grant-implicit");
const { extractTokenFromUrl } = grantImplicit;
const access_token = extractTokenFromUrl(window.location.href);
Auth Client is created using 0Auth2 Client from googleapis/oAuthClient. The client_id, client_secret, redirect_uris needed to set as environment variables before creating the oAuth2 Client.
const grantExplicit = require("@melkorcba-osl/googleapis-common/grant-explicit");
const { AUTH_SCOPES } = require("@melkorcba-osl/googleapis-common/auth-scopes");
// creating oAuth2 client
const { getAuth, EXECUTION_ENVIRONMENTS } = grantExplicit();
const authClient = getAuth({type:EXECUTION_ENVIRONMENTS.SERVER });
// generate Token request URL and PKCE Codes.
// Scope abbreviations "DRIVE.VED_ALL_FILES" V - View, E - Edit, D - Delete ALL_FILES in the Drive
const scopes = [AUTH_SCOPES.AUTH_SCOPES.DRIVE.VED_ALL_FILES]
const {authUrl, codes} = getAuthData(authClient, scopes);
Contributors are welcomed with open arms. Please mind the Documentation still under development. Feel free to report any issues and support for new APIs.