Skip to main content
Module

x/google_datastore/auth.ts>createOAuth2Token

A set of APIs that allow interfacing to Google Datastore on GCP from Deno.
Go to Latest
function createOAuth2Token
import { createOAuth2Token } from "https://deno.land/x/google_datastore@0.0.14/auth.ts";

Generates an OAuth2 token against Google APIs for the provided service account and scopes. Provides an instance of OAuth2Token that wraps the response from Google API OAuth2 service.

Example

import { createOAuth2Token } from "https://deno.land/x/deno_gcp_admin/auth.ts";
import keys from "./service-account.json" asserts { type: "json" };

const token = await createOAuth2Token(
  keys,
  "https://www.googleapis.com/auth/cloud-platform"
);

const response = fetch("https://example.googleapis.com/", {
  headers: {
    authorization: token.toString(),
  }
});

Parameters

A JSON object representing the data from a service account JSON file obtained from Google Cloud.

...scopes: string[]

Scopes that the authorization is being requested for.