Set up JWT
Self-managed authentication integrated with your login system
Self-managed authentication integrated with your login system
This feature is available only for the Enterprise plan. To get started, reach out to support@buildwithfern.com.
With JWT, you manage the entire auth flow. This involves building and signing a fern_token cookie that integrates your docs with your existing login system. Like OAuth, JWT enables:
fern_token cookie.Reach out to Fern to get your secret key and send them the URL of your authentication page. This is where users are redirected after clicking Login.
Build the fern claim
The JWT payload must include a fern claim. What you include in the token’s fern claim controls which features are enabled: login only, RBAC, or API key injection.
Set the fern_token cookie
Add logic to your service to sign the JWT and set it as a fern_token cookie when a user logs in.
This Next.js endpoint handles the callback from your authentication page. It reads the state parameter to determine where to redirect the user, mints a fern_token JWT using jose, sets it as a cookie, and redirects the user back to the docs.
Once your fern_token is working, configure the features you need:
docs.yml and restrict navigation items or page content by role.playground payload, including custom headers, multiple API keys, and per-environment credentials.