auth0-cross-site-single-sign-on
v1.9.0
Published
Here’s a sample README.md file for your auth0-cross-site-sso package. This file includes installation instructions, setup, and usage for integrating the package with Next.js applications.
Downloads
574
Maintainers
Readme
Here’s a sample README.md file for your auth0-cross-site-sso package. This file includes installation instructions, setup, and usage for integrating the package with Next.js applications.
Auth0 Cross-Site SSO auth0-cross-site-sso is an NPM package for implementing cross-site single sign-on (SSO) with Auth0 in Next.js applications. It provides custom handlers for login, logout, and callback requests, enabling smooth authentication workflows across multiple domains.
Features Customizable login, logout, and callback handlers for Auth0 Supports Next.js 13+ applications Facilitates cross-site SSO with federated logout Installation Install auth0-cross-site-sso as a dependency in your Next.js project:
bash Copy code npm install auth0-cross-site-sso Note: Ensure @auth0/nextjs-auth0, next, and react are also installed.
Setup To use this package, add the required Auth0 environment variables to your Next.js environment file:
env Copy code
.env.local
AUTH0_BASE_URL=https://your-domain.com AUTH0_ISSUER_BASE_URL=https://your-auth0-domain.auth0.com AUTH0_CLIENT_ID=YOUR_CLIENT_ID AUTH0_CLIENT_SECRET=YOUR_CLIENT_SECRET AUTH0_SECRET=YOUR_LONG_RANDOM_STRING Usage In your Next.js application, import and use the handlers from the auth0-cross-site-sso package.
Example Create an API route for each of the authentication flows in the app or pages directory.
Login Handler
typescript Copy code // app/api/auth/login/route.ts import { loginHandler } from 'auth0-cross-site-sso';
export const GET = loginHandler; Callback Handler
typescript Copy code // app/api/auth/callback/route.ts import { callbackHandler } from 'auth0-cross-site-sso';
export const GET = callbackHandler; Logout Handler
typescript Copy code // app/api/auth/logout/route.ts import { handleLogoutRequest } from 'auth0-cross-site-sso';
export const GET = handleLogoutRequest; Auth Request Handler
Use the main handleAuthRequest function to automatically handle login, callback, and logout based on the incoming request.
typescript Copy code // app/api/auth/[auth].ts import { handleAuthRequest } from 'auth0-cross-site-sso';
export const GET = handleAuthRequest(); API loginHandler: Handles the login process with redirect options. callbackHandler: Handles the callback process and redirects as needed. handleLogoutRequest: Handles logout requests and supports federated logout. handleAuthRequest: A main handler for all Auth0-related requests (login, callback, logout). Example Configuration Below is a sample configuration using handleAuthRequest in a Next.js application:
typescript Copy code // app/api/auth/[...auth]/route.ts import { handleAuthRequest } from 'auth0-cross-site-sso';
export const GET = handleAuthRequest();