Auth0 SDKs
Updated SDKs now include enhanced support for securing AI agent workflows, including improved token management, API protection, and identity integration for AI-powered apps.Next.js
This SDK streamlines integrating Auth0 authentication and authorization services into Next.js applications. It supports:- User authentication
- Tools for getting access tokens for supported social and enterprise identity providers
nextjs-auth0 in AI-related use cases.
Each example highlights common patterns for building secure and scalable generative AI applications.
For additional examples, click here.
Getting access tokens for connections
Getting access tokens for connections
You can retrieve an access token for a connection using the
getAccessTokenForConnection() method, which accepts an object with the following properties:connection: The federated connection for which an access token should be retrieved.login_hint: The optional login_hint parameter to pass to the /authorize endpoint.
Accessing the authenticated user
Accessing the authenticated user
In the browser
To access the currently authenticated user on the client, you can use the useUser() hook, like so:On the server (App Router)
On the server, the getSession() helper can be used in Server Components, Server Routes, and Server Actions to get the session of the currently authenticated user and to protect resources, like so:Protect an API Route
Protect an API Route
Requests to /api/protected without a valid session cookie will fail with 401.Then you can access your API from the frontend with a valid session cookie.
app/api/protected/route.js
app/products/page.jsx
Using Client-Initiated Backchannel Authentication
Using Client-Initiated Backchannel Authentication
Using Client-Initiated Backchannel Authentication can be done by calling
getTokenByBackchannelAuth():bindingMessage: A human-readable message to be displayed at the consumption device and authentication device. This allows the user to ensure the transaction initiated by the consumption device is the same that triggers the action on the authentication device.loginHint.sub: The sub claim of the user that is trying to login using Client-Initiated Backchannel Authentication, and to which a push notification to authorize the login will be sent.
Node SDK
This library streamlines integrating Auth0’s authentication and authorization services into Node.js applications. It supports:- User authentication
- Tools for signing up users, managing user profiles, and securing API endpoints.
Fastify SDK
This SDK streamlines integrating Auth0 authentication and authorization services into Fastify applications. It supports:- User authentication
- Tools for getting access tokens to call first-party APIs
Protecting APIs
Protecting APIs
This example shows how to protect API routes using Auth0 in a Fastify server. You can secure endpoints by requiring authentication or specific scopes using the
@auth0/auth0-fastify-api plugin. Public routes stay open to everyone, while private ones require a valid access token.Protecting Views & Routes
Protecting Views & Routes
This example shows how to integrate Auth0 into a Fastify web app:
- You register
@auth0/auth0-fastifywith your domain, client credentials, base URL, and session secret. - Use
fastify.auth0Client.getUser(...)to check if a user is logged in and fetch their profile. - To protect a route (like
/private), you use apreHandlerthat checks for a valid session and redirects to Auth0’s login page if needed. - Auth0 handles the login, callback, and logout flows internally via the plugin’s built-in routes.
Auth0 AI SDKs
Auth0 AI SDKs to streamline integrating your application with popular agentic frameworks:Auth0 AI SDK
This SDK provides base abstractions for authentication and authorization in AI applications. It supports:- Asynchronous user authentication using the Client Initiated Backchannel Authentication (CIBA) protocol
- OpenFGA-based filter for RAG
Auth0 AI Components
This library helps to set up the React components that can be used in AI applications using Auth0 for AI Agents. The components are styled using Tailwind CSS. It supports:- Tools for getting access tokens for supported social and enterprise identity providers
Using with LangGraph
Using with LangGraph
This React Chat example shows how to integrate streaming with Auth0’s token-vault interrupts: it submits messages, refocuses input after loading, and displays a consent popup when a TokenVault interrupt occurs.
Using with AI SDK
Using with AI SDK
This React Chat example illustrates how to integrate AI SDK streaming with Auth0’s token-vault interrupts: it sends messages via the SDK, manages input focus during loading, and prompts users via a consent popup when a TokenVault interrupt is triggered.
Redis Store for Auth0 AI
This SDK provides a secure Redis-based data store implementation for use with the Auth0 AI SDKs. It supports:- Securely encrypting data before storing it in Redis
- Organizing keys using namespaces
- Setting expiration times for stored data