npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@microfox/google-sdk

v1.1.0

Published

Google SDK for Microfox

Readme

Google OAuth SDK

A lightweight TypeScript SDK for Google OAuth token management with built-in token validation and refresh capabilities. This module is part of the @microfox/google-sdk npm package.

Installation

npm install @microfox/google-sdk

Features

  • Token validation against Google's tokeninfo endpoint
  • Automatic token refresh using refresh tokens
  • Strong typing with Zod schema validation
  • Simple interface for token management
  • Reusable across multiple Google API SDKs

Usage

Basic Usage

import { createGoogleOAuthManager } from '@microfox/google-sdk';

// Set up token management
const tokens = await createGoogleOAuthManager({
  accessToken: 'your-access-token',
  refreshToken: 'your-refresh-token',
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
});

// Use the validated/refreshed token
console.log(tokens.accessToken); // Valid token
console.log(tokens.expiresAt); // Expiration timestamp

Integrating with API Clients

This module is designed to be integrated with other Google API clients like Drive SDK, YouTube SDK, etc.

import {
  createGoogleOAuthManager,
  GoogleOAuthOptions,
} from '@microfox/google-sdk';
import { createRestSDK } from '@microfox/rest-sdk';

const createMyGoogleApiClient = async (options: GoogleOAuthOptions) => {
  // Validate and refresh tokens if needed
  const tokens = await createGoogleOAuthManager(options);

  // Create API client with the valid token
  const restSdk = createRestSDK({
    baseUrl: 'https://api.google.com/some-service',
    headers: {
      Authorization: `Bearer ${tokens.accessToken}`,
    },
  });

  // Return your API methods
  return {
    // Your API methods using restSdk
  };
};

API Reference

createGoogleOAuthManager(options)

Main function that checks if a token is valid and refreshes it if necessary.

Parameters:

  • options (GoogleOAuthOptions): Object containing:
    • accessToken (string): The access token to validate/use
    • refreshToken (string, optional): Refresh token to use if access token is invalid
    • clientId (string, optional): OAuth client ID required for token refresh
    • clientSecret (string, optional): OAuth client secret required for token refresh

Returns:

  • Promise<Tokens>: Object containing:
    • accessToken (string): A valid access token (if refresh was successful) or the original token
    • refreshToken (string, optional): The refresh token provided
    • expiresAt (number, optional): Timestamp when the token expires
    • tokenType (string, optional): Token type (usually "Bearer")

isTokenValid(accessToken)

Checks if an access token is valid by querying the Google tokeninfo endpoint.

Parameters:

  • accessToken (string): The access token to validate

Returns:

  • Promise<boolean>: True if the token is valid, false otherwise

refreshAccessToken(refreshToken, clientId, clientSecret)

Refreshes an access token using a refresh token.

Parameters:

  • refreshToken (string): The refresh token
  • clientId (string): OAuth client ID
  • clientSecret (string): OAuth client secret

Returns:

  • Promise<object | null>: Object containing the new access token and expiration, or null if refresh failed

Type Definitions

GoogleOAuthOptions

interface GoogleOAuthOptions {
  accessToken: string;
  refreshToken?: string;
  clientId?: string;
  clientSecret?: string;
}

Tokens

interface Tokens {
  accessToken: string;
  refreshToken?: string;
  expiresAt?: number;
  tokenType?: string;
}

Environment Variables

The SDK can also use these environment variables for client credentials:

GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
OAUTH_CLIENT_ID=your-client-id
OAUTH_CLIENT_SECRET=your-client-secret

Error Handling

The SDK uses Zod for validation and provides meaningful error messages when validation fails. All asynchronous operations are properly try-catched to prevent uncaught promise rejections.

Related Packages

  • @microfox/drive-sdk - Google Drive API SDK
  • @microfox/youtube-sdk - YouTube API SDK
  • @microfox/rest-sdk - REST client used by Google SDKs