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

vite-plugin-oidc-auth

v0.3.0

Published

A Vite plugin for OIDC authentication during development (dev mode only)

Readme

vite-plugin-oidc-auth

A Vite plugin that provides OIDC (OpenID Connect) authentication during development. This plugin automatically handles the OAuth flow and injects the access token into your development environment.

Features

  • 🔐 Automatic OIDC authentication flow
  • 🚀 Auto-opens browser for authentication (configurable)
  • 🔑 Injects access token as import.meta.env.VITE_API_TOKEN
  • ⚡ Development-only plugin (doesn't affect production builds)
  • 🎯 PKCE support for secure authentication
  • 📁 Flexible environment variable configuration

Installation

npm install vite-plugin-oidc-auth
# or
yarn add vite-plugin-oidc-auth
# or
pnpm add vite-plugin-oidc-auth

Usage

Basic Setup

  1. Add the plugin to your vite.config.js:
import { defineConfig } from 'vite'
import oidcAuth from 'vite-plugin-oidc-auth'

export default defineConfig({
  plugins: [
    oidcAuth()
  ]
})
  1. Create a .env.local file with your OIDC configuration:
OIDC_DISCOVERY_URL=https://your-provider.com/.well-known/openid-configuration
OIDC_CLIENT_ID=your-client-id
OIDC_CLIENT_SECRET=your-client-secret
OIDC_REDIRECT_URI=http://localhost:3001/callback
OIDC_SCOPE=openid profile email
  1. Start your development server:
npm run dev

The plugin will automatically open your browser to authenticate. After successful authentication, the access token will be available as import.meta.env.VITE_API_TOKEN in your application.

Configuration Options

import oidcAuth from 'vite-plugin-oidc-auth'

export default defineConfig({
  plugins: [
    oidcAuth({
      openBrowser: false, // Disable auto-opening browser
      envFilePath: '.env.development', // Custom env file path
      oidcOptions: {
        // Override environment variables
        discoveryUrl: 'https://custom-provider.com/.well-known/openid-configuration',
        clientId: 'custom-client-id',
        clientSecret: 'custom-client-secret',
        redirectUri: 'http://localhost:3001/callback',
        scope: 'openid profile email'
      }
    })
  ]
})

Using the Token in Your App

// Access the token in your application
const token = import.meta.env.VITE_API_TOKEN

// Use it in API calls
fetch('/api/data', {
  headers: {
    'Authorization': `Bearer ${token}`
  }
})

Environment Variables

| Variable | Required | Description | |----------|----------|-------------| | OIDC_DISCOVERY_URL | Yes | OIDC discovery endpoint URL | | OIDC_CLIENT_ID | Yes | OAuth client ID | | OIDC_CLIENT_SECRET | Yes | OAuth client secret | | OIDC_REDIRECT_URI | Yes | Redirect URI for OAuth callback | | OIDC_SCOPE | Yes | OAuth scopes (e.g., "openid profile email") |

How It Works

  1. When you start the dev server, the plugin creates a temporary HTTP server on the redirect URI
  2. It generates PKCE challenge codes for secure authentication
  3. Opens your browser to the OIDC provider's authorization endpoint
  4. After authentication, the provider redirects to the callback server
  5. The plugin exchanges the authorization code for an access token
  6. The token is injected into your Vite environment as VITE_API_TOKEN

Development Mode Only

This plugin only runs during development (vite dev) and is automatically disabled for production builds. This ensures your authentication flow doesn't interfere with your production application.

TypeScript Support

The plugin includes full TypeScript support with exported types:

import oidcAuth, { OidcOptions, OidcPluginOptions } from 'vite-plugin-oidc-auth'

const options: OidcPluginOptions = {
  openBrowser: true,
  oidcOptions: {
    discoveryUrl: 'https://provider.com/.well-known/openid-configuration',
    clientId: 'client-id',
    clientSecret: 'client-secret',
    redirectUri: 'http://localhost:3001/callback',
    scope: 'openid profile'
  }
}

export default defineConfig({
  plugins: [oidcAuth(options)]
})

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.