auth0-chrome-extension
v1.0.0
Published
A lightweight library for integrating Auth0 into Chrome Manifest V3 extensions using PKCE and Offscreen Documents.
Maintainers
Readme
Auth0 Chrome Extension Library
A lightweight, zero-dependency library for integrating Auth0 (and Okta) into Chrome Manifest V3 extensions using PKCE and Offscreen Documents.
Features
- Zero-Tab Flow: Uses
chrome.identity.launchWebAuthFlowfor a seamless login experience. - Manifest V3 Ready: Built from the ground up for Service Workers and Offscreen Documents.
- Secure: Uses Authorization Code Flow with PKCE.
- Small: Zero production dependencies.
Installation
npm install auth0-chrome-extensionSetup
1. Register Callback URL
In your Auth0 Dashboard (Application Settings), add:
https://<extension-id>.chromiumapp.org/ to Allowed Callback URLs.
2. Manifest Settings
Add the following to your manifest.json:
{
"permissions": ["storage", "identity", "offscreen"],
"host_permissions": ["https://YOUR_DOMAIN.us.auth0.com/*"],
"background": {
"service_worker": "background.js"
}
}3. Usage
Background Script (background.js)
import { initializeAuth0Background } from "auth0-chrome-extension";
initializeAuth0Background({
domain: "YOUR_DOMAIN.us.auth0.com",
clientId: "YOUR_CLIENT_ID",
scopes: "openid profile email",
});Offscreen Document (offscreen.js)
Create an offscreen.html that loads an offscreen.js with:
import { initializeAuth0Offscreen } from "auth0-chrome-extension";
initializeAuth0Offscreen();Popup / UI (popup.js)
import { Auth0Client } from "auth0-chrome-extension";
const auth0 = new Auth0Client();
// Login
const profile = await auth0.login();
// Get Current User
const user = await auth0.getUser();
// Logout
await auth0.logout();License
MIT
