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
json: ServiceAccountJSON
A JSON object representing the data from a service account JSON file obtained from Google Cloud.
Returns
Promise<OAuth2Token>