|
| 1 | +--- |
| 2 | +title: Set up OAuth |
| 3 | +subtitle: Integrate your OAuth provider with Fern Docs |
| 4 | +--- |
| 5 | + |
| 6 | +<Steps> |
| 7 | +<Step title="Create an OAuth client"> |
| 8 | +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. |
| 9 | +</Step> |
| 10 | + |
| 11 | +<Step title="Allowlist Fern callbacks"> |
| 12 | +You will need to allowlist the following callback in your OAuth provider: |
| 13 | +`https://<your-domain>/api/fern-docs/oauth2/callback`. |
| 14 | + |
| 15 | +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. |
| 16 | +</Step> |
| 17 | + |
| 18 | +<Step title="Send OAuth client details to Fern"> |
| 19 | +Fern will need the following details to configure OAuth authentication: |
| 20 | +- [ ] Docs domain |
| 21 | +- [ ] Client ID |
| 22 | +- [ ] Client secret |
| 23 | +- [ ] Authorization URL (e.g. `https://<your-oauth-tenant>/oauth2/authorize`) |
| 24 | +- [ ] Token URL (e.g. `https://<your-oauth-tenant>/oauth2/token`) |
| 25 | +- [ ] Scopes (e.g. `openid`, `profile`, `email`) |
| 26 | +- [ ] Issuer URL (e.g. `https://<your-domain>`) |
| 27 | + |
| 28 | +Send these details to [email protected] or in your dedicated Slack channel. |
| 29 | +</Step> |
| 30 | + |
| 31 | +<Step title="Wait for Fern to configure OAuth"> |
| 32 | +Wait for Fern to configure OAuth. You will receive a notification when the site is ready to use authentication. |
| 33 | +</Step> |
| 34 | + |
| 35 | +<Step title="Add a custom claim to set user roles"> |
| 36 | +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: |
| 37 | + |
| 38 | +```json {12-15} |
| 39 | +{ |
| 40 | + "iss": "https://your-tenant.us.auth0.com/", |
| 41 | + "sub": "auth0|507f1f77bcf86cd799439011", |
| 42 | + "aud": "your_client_id_here", |
| 43 | + "iat": 1728388800, |
| 44 | + "exp": 1728475200, |
| 45 | + |
| 46 | + "email_verified": true, |
| 47 | + "name": "John Doe", |
| 48 | + "nickname": "johndoe", |
| 49 | + "picture": "https://s.gravatar.com/avatar/...", |
| 50 | + "roles": [ |
| 51 | + "custom-role", |
| 52 | + "user-specific-role" |
| 53 | + ] |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +<AccordionGroup> |
| 58 | +<Accordion title="Using Auth0"> |
| 59 | +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. |
| 60 | + |
| 61 | +1. Go to the **Actions** tab in the Auth0 dashboard. |
| 62 | +2. Create a **Custom Action**. |
| 63 | +3. Select **Login/Post Login**. |
| 64 | +4. Add logic to set a roles. |
| 65 | +5. Click **Create**. |
| 66 | +6. Add the action to your **Post Login Flow**. |
| 67 | +</Accordion> |
| 68 | +<Accordion title="Using another provider"> |
| 69 | +If you are using a different OAuth provider, please reach out to Fern with any questions on setting up a custom claim. |
| 70 | +</Accordion> |
| 71 | +</AccordionGroup> |
| 72 | +</Step> |
| 73 | + |
| 74 | +<Step title="Add roles to your docs"> |
| 75 | +See [RBAC](/docs/authentication/rbac#set-up-rbac) for more information on how to add roles to your docs. |
| 76 | +</Step> |
| 77 | + |
| 78 | +</Steps> |
0 commit comments