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

@hapic/oauth2

v4.0.1

Published

A oauth2 api client based on axios.

Readme

@hapic/oauth2 🛡️

npm version main Known Vulnerabilities Conventional Commits

This client provides an easy way to authenticate and authorize users, clients, robots, ... using OAuth2 and OpenID Connect standards. With this API client, developers can easily interact with the server's endpoints, such as authentication flows, token issuance, and user management. The client offers a range of abstractions to simplify interactions with the server and speed up the development process. Whether you are an experienced developer or new to OAuth2/OpenID, this API client is a powerful tool to help you implement secure users, clients & robots authentication and authorization in your applications.

Table of Contents

Documentation

To read the docs, visit https://hapic.tada5hi.net

Installation

npm install @hapic/oauth2 --save

Usage

Authorize

URL

import { OAuth2Client } from '@hapic/oauth2';

const client = new OAuth2Client({
    request: {
        baseURL: 'http://localhost:3000/',
    },
    options: {
        /**
         * default: /authorize
         */
        authorizationEndpoint: 'https://example.com/authorize'
    }
});

const authorizeUrl = client.authorize.buildURL({
    client_id: 'client',
    /**
     * Relative or absolute url.
     */
    redirect_uri: 'http://localhost:3000/redirect-callback'
});

console.log(authorizeUrl);
// https://example.com/authorize?
//     response_type=code&
//     client_id=client&
//     redirect_uri=http://localhost:3000/redirect-callback

Token

Create

import { OAuth2Client } from '@hapic/oauth2';

const client = new OAuth2Client({
    request: {
        baseURL: 'http://localhost:3000/'
    },
    options: {
        /**
         * default: /token
         */
        tokenEndpoint: 'https://example.com/authorize',
        clientId: 'client',
        clientSecret: 'secret',
    }
});

let token = await client.token.createWithRefreshTokenGrant({
    refresh_token: 'refresh_token'
});

token = await client.token.createWithClientCredentialsGrant({
    // optional, if defined globally
    client_id: 'foo',
    client_secret: 'bar',
});

token = await client.token.createWithPasswordGrant({
    username: 'admin',
    password: 'start123'
});

token = await client.token.createWithAuthorizationCodeGrant({
    state: 'state',
    code: 'code'
});

token = await client.token.createWithRobotCredentialsGrant({
    id: 'system',
    secret: 'start123'
});

console.log(token);
// { token_type: 'Bearer', access_token: 'xxx', refres_token: 'xxx', ...}

Introspect

import { OAuth2Client } from '@hapic/oauth2';

const client = new OAuth2Client({
    request: {
        baseURL: 'http://localhost:3000/'
    },
    options: {
        /**
         * default: /token/introspect
         */
        introspectionEndpoint: 'https://example.com/token/introspect'
    }
});

let token = await client.token.introspect({
    token: 'xxx',
    // token_type_hint: 'xxx',
});

// authorize introspection request with custom header
token = await client.token.introspect(
    {
        token: 'xxx',
        // token_type_hint: 'xxx'
    },
    {
        authorizationHeader: 'xxx',
    }
)

// authorize introspection request with existing client token.
token = await client.token.introspect(
    {
        token: 'xxx',
        // token_type_hint: 'xxx'
    },
    {
        authorizationHeaderInherit: true,
    }
)

// authorize introspection request with client credentials
token = await client.token.introspect(
    {
        token: 'xxx',
        client_id: 'client',
        client_secret: 'secret'
    }
)

// authorize introspection request with client credentials header
token = await client.token.introspect(
    {
        token: 'xxx'
    },
    {
        clientId: 'client',
        clientSecret: 'secret'
    }
);

console.log(token);
// { active: true, ... }

UserInfo

import { OAuth2Client } from '@hapic/oauth2';

const client = new OAuth2Client({
    request: {
        baseURL: 'http://localhost:3000/'
    },
    options: {
        /**
         * default: /userinfo
         */
        userInfoEndpoint: 'https://example.com/users/@me'
    }
});

// authenticate by authorization string
let userInfo = await client.userInfo.get('Bearer xxx');

// authenticate by authorization object configuration
userInfo = await client.userInfo.get({
    type: 'Basic',
    username: 'admin',
    password: 'start123'
});

// authenticate by existing client token
userInfo = await client.userInfo.get();

console.log(userInfo);
// { id: 'xxx', name: 'admin', ...}

License

Made with 💚

Published under MIT License.