MCPcopy Index your code
hub / github.com/Schachte/cloudflare-google-auth

github.com/Schachte/cloudflare-google-auth @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
10 symbols 16 edges 1 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Google OAuth & Cloudflare Workers

Check out the blog article here

Demo repo

Background

Easiest way to grab an access token for Google OAuth without any external dependencies. This is a simple JS module used to facilitate the OAuth2 flow from within a Cloudflare Worker. This module isn't specific to Cloudflare, but it 's compatible within isolates and doesn't rely on NodeJS.

Usage

Installation: npm i cloudflare-workers-and-google-oauth

This is a fully working code snippet showing how to access Google Cloud Storage (GCS) and returning an image to the browser.

This gist was my inspiration for this implementation.

import GoogleAuth, { GoogleKey } from 'cloudflare-workers-and-google-oauth'

// Add secret using Wranlger or the Cloudflare dash
export interface Env {
    GCP_SERVICE_ACCOUNT: string;
}

export default {
    async fetch(
        request: Request,
        env: Env,
        ctx: ExecutionContext
    ): Promise<Response> {
        // https://developers.google.com/identity/protocols/oauth2/scopes
        const scopes: string[] = ['https://www.googleapis.com/auth/devstorage.full_control']
        const googleAuth: GoogleKey = JSON.parse(env.GCP_SERVICE_ACCOUNT)

        // Initialize the service
        const oauth = new GoogleAuth(googleAuth, scopes)
        const token = await oauth.getGoogleAuthToken()

        // Example with Google Cloud Storage
        const res = await fetch('https://storage.googleapis.com/storage/v1/b/MY_BUCKET/o/MY_OBJECT.png?alt=media', {
            method: 'GET',
            headers: {
                'Authorization': `Bearer ${token}`,
                'Content-Type': 'image/png',
                'Accept': 'image/png',
            },
        })

        return new Response(res.body, { headers: { 'Content-Type': 'image/png' } });
    },
};

Extension points exported contracts — how you extend this code

GoogleKey (Interface)
(no doc)
index.ts

Core symbols most depended-on inside this repo

objectToBase64url
called by 2
index.ts
arrayBufferToBase64Url
called by 2
index.ts
str2ab
called by 2
index.ts
sign
called by 1
index.ts
formatScopes
called by 1
index.ts
constructor
called by 0
index.ts
getGoogleAuthToken
called by 0
index.ts

Shape

Method 7
Class 2
Interface 1

Languages

TypeScript100%

Modules by API surface

index.ts10 symbols

For agents

$ claude mcp add cloudflare-google-auth \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact