- Serve
/.well-known/poppy.jsonand/.well-known/oauth-protected-resource. - Accept the login that ends a join.
- Tell who is driving the browser, and never treat a guest as a user.
- Apply the agent’s scopes, and keep its session short.
@auth0/auth0-server-js builds each piece, and your code mounts it.
Prerequisites
- Your tenant set up for the Personal Agent Protocol, with the Auth0 CLI or manually, and the
poppy.jsonit produced. - A Regular Web Application with the browser join turned on.
- The beta release of your SDK:
@auth0/nextjs-auth0@4.34.0-beta.0,@auth0/auth0-express@1.1.0-beta.0, or@auth0/auth0-server-js@1.18.0-beta.0. - Your website served over HTTPS at the root of your company domain. Agents look for the discovery files at the root, so the site can’t sit under a path.
- Your web application logs in with the same API audience that agents get tokens for. Auth0 refuses a join login for another audience. The examples below set it from
AUTH0_AUDIENCE.
Configure the application
In Dashboard > Applications > Applications, select your web application:- Set Application Login URI to your SDK’s login route, such as
https://shop.example/auth/login. - Add your callback route, such as
https://shop.example/auth/callback, to Allowed Callback URLs. - (Recommended) Configure back-channel logout, so your application can end an agent’s session when Auth0 does.
Turn on Personal Agent Protocol in the SDK
Give the SDK your Poppy discovery document, thepoppy.json file that auth0 poppy setup (or auth0 poppy config) writes. Every Auth0 web SDK takes it as it is. It serves the file unchanged at /.well-known/poppy.json, builds /.well-known/oauth-protected-resource from it, and checks only organization.domain and auth.issuer at startup. It serves the protocol version the file names and doesn’t check it. auth0 poppy doctor checks the rest of the file.
The poppy.json file holds no secrets, so you can commit it. The sample app keeps it out of Git and writes one from its environment when a build has none.
poppy.json
- Next.js
- Express
- Other Node.js frameworks
lib/auth0.ts
/.well-known/*. This matcher does, because it excludes only static assets:proxy.ts
middleware.ts and the function middleware.iss parameter against your issuer, and sends the browser to target_link_uri only when it’s on your own origin.
Tell who is driving the browser
After a join, the SDK classifies the login from the ID token:- Person: a normal login with no Poppy
actclaim. - Agent guest: an anonymous subject with a Poppy
actclaim.getSession()andgetUser()return no user. Express and@auth0/auth0-server-jskeep the guest in their own cookie. Next.js keeps it in the anonymous-session cookie, sogetAnonymousSession()returns it. - Signed-in agent: the user’s session, with the agent kept in the session.
- Next.js
- Express
- Other Node.js frameworks
poppy.getContext() from @auth0/nextjs-auth0/client returns the same through the /auth/poppy-context route. It throws a PoppyError with poppy_not_enabled when the poppy option isn’t set.Correlate activity with Sessions
Key Session state and events, such as a cart, by the Session ID and the User ID together, never by the Session ID alone. Agents choose their own Session IDs, so the Sessions of two users can have the same one. The key stays the same when a guest signs in, as long as the agent signs in within the same Poppy Session and with the same User ID. If either one differs, the key changes, so move the guest’s cart when the agent signs in if you need to keep it.- Express and other Node.js frameworks: use
visitor.poppy.key, which the SDK builds from the Session ID and the User ID. - Next.js: combine
poppy.act.poppy_sidandpoppy.act.poppy_user_id. The guest cookie is deleted when the agent signs in, so save the guest’s key in your own storage first.
Guard pages from guests
Scope what a guest can do as you would for any visitor who isn’t logged in. Route protection treats a guest as signed out. A guest can’t sign in from your login page: they sign in through the agent, which joins the browser again. As a result, don’t send a guest to your login page. In Express,requiresAuth() answers a guest with 403 instead of redirecting to login. To handle guests differently, use onGuest.
Apply the agent’s scopes
In scoped mode, the default, Auth0 limits your web application’s access token to the API and scopes the user approved for the agent. Ask for your API’s scopes at login (authorizationParameters.scope in Next.js, authorizationParams.scope with @auth0/auth0-server-js), so the joined token carries them and your API can check them. Your API calls from the web application are then limited for you. @auth0/auth0-express has no option for login scopes, so a joined token from an Express website carries none of your API’s scopes.
Actions that your web application performs without calling that API aren’t limited by Auth0. Check the agent’s scopes before them, or set web.unscoped and describe poppy:browser-sign-in as full access. When you refuse an action for a missing scope, show an error that names the scope, so the agent can ask the user for it.
Refuse agents on account changes that no scope covers, such as changing the email address or password.
For sensitive operations, such as a payment, you can also require the user’s own confirmation when the tokens include an acting agent, for example with Client-Initiated Backchannel Authentication (CIBA).
Session lifetime and logout
- Lifetime: the session a join creates lasts at most 2 hours, and Auth0 issues no refresh token for it. The SDKs cap the agent’s session at the ID token’s expiry. If your Sessions end sooner, end the website session too.
- Sign-out at the agent: during the beta, revoking the agent’s refresh token doesn’t end the website’s signed-in session. It ends when it expires.
- Logout: the SDK’s logout route ends the website session, including a guest’s, and the Auth0 session.
Check it works
Deploy your website, or open a tunnel to it, and fetch both discovery files. Each must name the other exactly, including the issuer’s trailing slash:
For more troubleshooting steps, read Test Your Setup.