Skip to content

Quickstart

This guide walks through adding OIDC authentication to your app using any spec-compliant OIDC provider (like Autentico, Auth0, or Keycloak).

  1. Install your framework adapter

    Terminal window
    npm install oidc-js-react # or oidc-js-vue, oidc-js-svelte, oidc-js-angular, etc.
  2. Add authentication

    You’ll need an issuer URL, client ID, and redirect URI from your OIDC provider.

    import { AuthProvider, RequireAuth, useAuth } from "oidc-js-react";
    const config = {
    issuer: "https://auth.example.com",
    clientId: "my-app",
    redirectUri: "http://localhost:5173/callback",
    scopes: ["openid", "profile", "email", "offline_access"],
    };
    function App() {
    return (
    <AuthProvider config={config}>
    <RequireAuth fallback={<p>Loading...</p>}>
    <Dashboard />
    </RequireAuth>
    </AuthProvider>
    );
    }
    function Dashboard() {
    const { user, actions } = useAuth();
    return (
    <div>
    <p>Welcome, {user?.profile?.name}!</p>
    <button onClick={() => actions.logout()}>Log out</button>
    </div>
    );
    }
  1. The auth provider fetches the OIDC discovery document from {issuer}/.well-known/openid-configuration
  2. When login is triggered, it generates PKCE parameters, saves auth state to sessionStorage, and redirects to the IdP’s authorization endpoint
  3. After the user authenticates, the IdP redirects back with an authorization code
  4. The provider detects the code in the URL, exchanges it for tokens, fetches the user profile, and cleans up the URL
  5. The auth guard (RequireAuth / authGuard) checks token expiry and automatically refreshes expired tokens using the refresh token