Skip to content

melkorCBA/google-api-common

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google-api-common

npm version downloads

google-api-common is a wrapper around google-api-nodejs-client that provides simpler javaScript APIs for common functions in following libraries.

Getting started

Installation

Run this to install via NPM

npm i @melkorcba-osl/googleapis-common

Authentication and authorization

This library provides both client side and server side Auth clients.

Client side Auth - Implicit Grant Flow

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);

Server side Auth - Explicit Grant Flow (Authorization Code FLow)

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);

Contributions

Contributors are welcomed with open arms. Please mind the Documentation still under development. Feel free to report any issues and support for new APIs.

About

Wrapper around googleapis

Resources

License

Stars

Watchers

Forks

Packages

No packages published