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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@arte/ra-apisix-oidc

v1.2.0

Published

## Usage

Readme

@arte/ra-apisix-oidc

Usage

@arte/ra-apisix-oidc provides a React-Admin AuthProvider and HTTP client for authentication via APISIX OIDC endpoints. Use it in your React-Admin app to enable OpenID Connect authentication through APISIX.

Example

import { Admin, ListGuesser, Resource, ShowGuesser } from "react-admin";
import { apisixOidcAuthProvider, httpClient } from '@arte/ra-apisix-oidc';
import simpleRestDataProvider from 'ra-data-simple-rest';

const dataProvider = simpleRestDataProvider('http://localhost:9080/api', httpClient());
const authProvider = apisixOidcAuthProvider();

export const App = () => (
  <Admin
    dataProvider={dataProvider}
    authProvider={authProvider}
    loginPage={false}
  >
    <Resource name="posts" list={ListGuesser} show={ShowGuesser} />
    <Resource name="users" list={ListGuesser} show={ShowGuesser} />
  </Admin>
);

AuthProvider and HTTP Client Options

apisixOidcAuthProvider(options)

You can customize the authentication provider with the following options:

  • loginURL (string, default: ${window.location.origin}/oidc/login): Login endpoint URL.
  • logoutURL (string, default: ${window.location.origin}/oidc/logout): Logout endpoint URL.
  • userInfoURL (string, default: ${window.location.origin}/oidc/me): User info endpoint URL.
  • storage (Storage, default: localStorage): Storage to use for tokens.

Example usage:

import { apisixOidcAuthProvider } from '@arte/ra-apisix-oidc';

const authProvider = apisixOidcAuthProvider({
  loginURL: 'http://localhost:9080/oidc/login',
  logoutURL: 'http://localhost:9080/oidc/logout',
  userInfoURL: 'http://localhost:9080/oidc/me',
  storage: localStorage,
});

httpClient(storage?)

The HTTP client automatically attaches authentication tokens to requests. You can customize its behavior with the following options:

  • storage (Storage, default: localStorage): Storage to use for tokens. The access token is expected to be stored under the key access_token.

Example usage:

import { httpClient } from '@arte/ra-apisix-oidc';

const client = httpClient(localStorage);
client('http://localhost:9080/api/posts');

Configuration

The API must implement the following routes to transmit the APISIX token to the frontend:

/oidc/login

  • Purpose: Initiates the OIDC login flow. Should validate the presence of the x-access-token header and redirect the user to the React-Admin app (e.g., /#/auth-callback) to complete authentication and store the token in local storage.
  • Behavior:
    • If x-access-token is missing, respond with 401 Unauthorized.
    • If present, redirect to the frontend callback route.

Example

app.get('/oidc/login', (req, res) => {
    const accessToken = req.headers['x-access-token'];
    if (!accessToken) {
        return res.status(401).json({
            error: 'Unauthorized',
            message: 'You are not authorized to access this resource.',
        });
    }
    // redirect to the react-admin page to set the access token in the local storage
    res.redirect(`/#/auth-callback`);
});

/oidc/me

  • Purpose: Returns user information and tokens for the authenticated user.
  • Behavior:
    • Requires the x-access-token header.
    • Decodes the access token and returns user info, accessToken.
    • If the token is missing or invalid, respond with 401 Unauthorized.

Example

app.get('/oidc/me', (req, res) => {
    const accessToken = req.headers['x-access-token'];
    if (!accessToken) {
        return res.status(401).json({
            error: 'Unauthorized',
            message: 'You are not authorized to access this resource.',
        });
    }

    const user = jwt.decode(accessToken as string) as jwt.JwtPayload;
    return res.status(200).json({
        user,
        accessToken
    });
});