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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@loxjs/google-auth

v1.0.1

Published

A Node.js package designed to simplify the process of authenticating users with Google OAuth2.

Downloads

3

Readme

GoogleAuth Module

The @loxjs/google-auth module is a Node.js package designed to simplify the process of authenticating users with Google OAuth2. It provides an easy-to-use interface for obtaining user information using Google's OAuth2 API.

Features

  • Easy Google OAuth2 integration.
  • Supports proxy configuration for requests.
  • Simplified method to obtain user information from Google ID tokens.

Installation

To install the @loxjs/google-auth module, run the following command in your project directory:

npm install @loxjs/google-auth

Usage

To use the GoogleAuth class, you need to create an instance and provide it with your Google client secret details. You can also specify a timeout and proxy settings.

Parameters

  • secret (Required): An object containing your Google app's client_id, client_secret, and grant_type.
  • timeout (Optional): A number representing the request timeout in milliseconds. Default is 120000 (2 minutes).
  • proxy (Optional): An object specifying the proxy configuration. Click here for more information.

Dependencies

This module relies on the following npm packages:

Please refer to the respective package pages on npmjs for more information.

API

The GoogleAuth module exposes a single class, GoogleAuth, which contains the following method:

getUserInfo

This method retrieves user information using a given code and redirect URI.

Parameters

  • code (Required): The authorization code you received from Google after user consent.
  • redirect_uri (Required): The URI where the user was redirected after consent.

Example

const GoogleAuth = require('@loxjs/google-auth');

const googleAuth = new GoogleAuth({
    secret: {
        client_id: 'YOUR_CLIENT_ID',
        client_secret: 'YOUR_CLIENT_SECRET',
        grant_type: 'authorization_code'
    },
    timeout: 1000 * 60 * 2, // Optional, 2 minutes timeout
    proxy: { // Optional
        protocol: 'http',
        host: 'localhost',
        port: 8080,
        proxyAuth: 'user:password',
        headers: {
            'User-Agent': 'Node'
        }
    }
});

async function authenticate() {
    try {
        const userInfo = await googleAuth.getUserInfo({
            code: 'AUTHORIZATION_CODE',
            redirect_uri: 'YOUR_REDIRECT_URI'
        });
        console.log(userInfo);
    } catch (error) {
        console.error('Authentication failed:', error);
    }
}

authenticate();

Replace 'YOUR_CLIENT_ID', 'YOUR_CLIENT_SECRET', 'AUTHORIZATION_CODE', and 'YOUR_REDIRECT_URI' with your actual client ID, client secret, authorization code, and redirect URI, respectively.

Note

When using the proxy option, make sure the proxy settings are correct and the proxy server is properly configured to handle HTTPS over HTTP tunneling.

Error Handling

Errors are handled using the @loxjs/errors package. If the id_token is not present in the response, the Account.InvalidGoogleAuthToken error is thrown. Make sure to catch and handle errors appropriately in your implementation.

For more information on error handling, please visit @loxjs/errors on npmjs.


This README provides a basic overview of the @loxjs/google-auth module. For further details and advanced usage, please refer to the source code and the official Google OAuth2 documentation.

Contributing

Contributions to @loxjs/google-auth are welcome! Please ensure that your contributions adhere to the following guidelines:

  • Write clear, readable, and maintainable code.
  • Follow existing coding styles and practices.
  • Write meaningful commit messages.
  • Update the documentation accordingly.

For more detailed information, please read the contributing guide.

Enjoy using @loxjs/google-auth!