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

ama-oauth-client

v0.0.5

Published

Lightweight OAuth 2.0 Client utilities for Next.js / front apps

Downloads

9

Readme

ama-oauth-client 🚀

ama-oauth-client est une librairie légère TypeScript pour simplifier l'intégration OAuth 2.0 dans vos projets Next.js, Vite, ou Node.js.
Elle gère automatiquement PKCE, state, et l'échange de tokens de manière simple et moderne.


✨ Fonctionnalités

  • Génération automatique du Code Verifier et Code Challenge (PKCE)
  • Support natif de state (protection CSRF)
  • Construction facile d'une Authorization URL
  • Échange de code, refresh_token, client_credentials avec exchangeToken()
  • Écrit en TypeScript, typé à 100%
  • Ultra léger, sans dépendances lourdes
  • Idéal pour Next.js, Vite, Node.js apps modernes

📦 Installation

npm install ama-oauth-client

# ou

yarn add ama-oauth-client

🚀 Utilisation

1. Définir votre configuration OAuth2

import { OAuthConfig } from "ama-oauth-client";

const config: OAuthConfig = {
  id: "my-app",
  name: "My App",
  issuer: "https://my-app.com",
  type: "oauth",
  wellKnown: "https://my-app.com/.well-known/openid-configuration",
  authorization: {
    url: "https://my-app.com/oauth/authorize",
    params: {
      scope: "openid profile email",
    },
  },
  checks: ["pkce", "state"],
  token: "https://my-app.com/oauth/token",
  userinfo: "https://my-app.com/oauth/userinfo",
  clientId: "your-client-id",
  clientSecret: "your-client-secret",
  redirectUri: "https://my-app.com/oauth/callback",
};

2. Générer l'URL de connexion (PKCE + State)

import { buildAuthorizationUrl, generateServerCodeVerifier, generateServerCodeChallenge } from "ama-oauth-client";

const codeVerifier = await generateServerCodeVerifier();
const codeChallenge = await generateServerCodeChallenge(codeVerifier);

const authorizationUrl = buildAuthorizationUrl(config, codeChallenge);
// Redirigez l'utilisateur vers `authorizationUrl`

3. Échanger le Code d'Autorisation pour un Token

import { exchangeToken } from "ama-oauth-client";

const tokenResponse = await exchangeToken(config, {
  grantType: "authorization_code",
  code: "CODE_REÇU",
  codeVerifier,
  state: "STATE_UTILISÉ_OPTIONNEL",
});

4. Rafraîchir un Access Token

const refreshResponse = await exchangeToken(config, {
  grantType: "refresh_token",
  refreshToken: "VOTRE_REFRESH_TOKEN",
});

5. Authentification Client Credentials (facultatif)

const clientCredentialsResponse = await exchangeToken(config, {
  grantType: "client_credentials",
});

💖 Bonus

  • PKCE est automatiquement géré (S256) si vous utilisez "pkce" dans checks
  • State est aussi supporté pour renforcer la sécurité

📚 Fonctions Exportées

| Fonction | Description | |:---------|:------------| | buildAuthorizationUrl(config, codeChallenge) | Génère l'URL d'authentification OAuth2 | | generateServerCodeVerifier() | Génère un Code Verifier (PKCE) | | generateServerCodeChallenge(codeVerifier) | Génère un Code Challenge (PKCE) | | exchangeToken(config, options) | Permet d’échanger authorization_code, refresh_token ou client_credentials |


📝 License

MIT © Michael Amimba


🛠️ À venir ?

  • Génération automatique de state
  • Support des erreurs OAuth détaillées