Set up OAuth for RBAC
This guide walks you through connecting your OAuth provider to Fern so that users are authenticated and assigned roles for role-based access control (RBAC). If you haven’t already, start by defining your roles in docs.yml.
Create an OAuth client
Go to your OAuth provider’s dashboard. Create a new web application client. This is the client that will be used by Fern to authenticate users with your OAuth provider.
Allowlist Fern callbacks
You will need to allowlist the following callback in your OAuth provider:
https://<your-domain>/api/fern-docs/oauth2/callback.
Replace <your-domain> with whatever domain you are using for your Fern Docs site. If you want to authenticate both your .docs.buildwithfern.com and custom domain, you will need to allowlist both.
Send OAuth client details to Fern
Fern will need the following details to configure OAuth authentication:
- Docs domain
- Client ID
- Client secret
- Authorization URL (e.g.
https://<your-oauth-tenant>/oauth2/authorize) - Token URL (e.g.
https://<your-oauth-tenant>/oauth2/token) - Scopes (e.g.
openid,profile,email) - Issuer URL (e.g.
https://<your-domain>)
Specifying an audience
If your client is connected to an API, you may need to specify an audience in the authentication request.
The updated authorization URL may look like this: https://<your-oauth-tenant>/oauth2/authorize?audience=<your-api-identifier>
Send these details to support@buildwithfern.com or in your dedicated Slack channel.
Wait for Fern to configure OAuth
Wait for Fern to configure OAuth. You will receive a notification when the site is ready to use authentication.
Add a custom claim to set user roles
Add a custom claim to your OAuth provider’s token response. This claim will be used to set the user’s roles in Fern Docs. The resulting token response should look something like this:
Using a claim other than roles
Some OAuth providers have strict requirements for custom claims. If you need to use a claim other than roles, reach out to Fern and specify which claim should be parsed for the user’s roles.
Using Auth0
To add a custom claim to Auth0, you need to create a custom action. This action will be used to add the custom claim to the token response.
- Go to the Actions tab in the Auth0 dashboard.
- Create a Custom Action.
- Select Login/Post Login.
- Add logic to set a roles.
Example Action
- Click Create.
- Add the action to your Post Login Flow.
Using another provider
If you are using a different OAuth provider, reach out to Fern with any questions on setting up a custom claim.