Skip to content

Commit e3b10e1

Browse files
committed
add docs for oauth
1 parent 5a9a24c commit e3b10e1

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

advanced/user-auth/choosing-an-auth-method.mdx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Before your users can access personalized content, they must be authenticated. M
77

88
1. **Shared Session**: Utilize the same session token used by your dashboard to authenticate users.
99
2. **JWT**: Use your own login flow to send user info to your docs via a JWT in the URL.
10+
3. **OAuth 2.0**: Integrate with your OAuth server to enable user login via the PKCE flow.
1011

1112
## Prerequisites
1213

@@ -23,10 +24,15 @@ Before your users can access personalized content, they must be authenticated. M
2324
- If your dashboard is at `*.foo.com`, your **docs** must be hosted at `foo.com` or `*.foo.com`
2425
</Tab>
2526
<Tab title="JWT">
26-
27+
2728
- You have some existing login flow.
2829
- You can add a final step in this login flow that creates a JWT and redirects to the docs.
2930
</Tab>
31+
<Tab title="OAuth 2.0">
32+
33+
- You have an existing OAuth server that supports the PKCE flow.
34+
- You can create a new API endpoint that can be accessed by the returned OAuth access token.
35+
</Tab>
3036
</Tabs>
3137

3238
## Pros & Cons
@@ -42,20 +48,34 @@ Before your users can access personalized content, they must be authenticated. M
4248
Cons:
4349

4450
- Your docs will make a request to your backend, which may be undesirable
51+
- You must have a dashboard that uses session authentication
52+
- CORS configuration is usually required
4553
</Tab>
4654
<Tab title="JWT">
4755
Pros:
4856

49-
- No dashboard needed
5057
- Reduced risk of API endpoint abuse
5158
- Zero CORS configuration
59+
- No restrictions on API URLs
5260

5361
Cons:
5462

55-
- Must build new functionality around your existing login flow
63+
- Must be able to hook into your existing login flow
5664
- Dashboard sessions and docs authentication are completely decoupled, so users will need to log in to your dashboard and your docs separately
5765
- Every time you want to refresh user data, your users must re-login to your docs
5866
- If your users' data changes frequently, you must require your users to log in frequently or risk having stale data in the docs
5967
- If your users' data rarely changes, this shouldn't be a problem
6068
</Tab>
69+
<Tab title="OAuth 2.0">
70+
Pros:
71+
72+
- Heightened security standard
73+
- No restrictions on API URLs
74+
75+
Cons:
76+
77+
- Requires significant work if setting up OAuth server for the first time
78+
- Dashboard sessions and docs authentication are completely decoupled, so users will need to log in to your dashboard and your docs separately
79+
- Might be overkill for some applications
80+
</Tab>
6181
</Tabs>

advanced/user-auth/jwt.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ If you don’t have a dashboard, or if you want to keep your dashboard and docs
99

1010
<Steps>
1111
<Step title="Generate a private key">
12-
Go to your [Mintlify dashboard settings](https://dashboard.mintlify.com/settings/integrations) and generate a private key. Store this key somewhere secure where it can be accessed by your backend.
12+
Go to your [Mintlify dashboard settings](https://dashboard.mintlify.com/mintlify/mintlify/settings/deployment/user-authentication) and generate a private key. Store this key somewhere secure where it can be accessed by your backend.
1313
</Step>
1414
<Step title="Create a login flow">
1515
Create a login flow that does the following:
@@ -19,7 +19,7 @@ If you don’t have a dashboard, or if you want to keep your dashboard and docs
1919
- Create a redirect URL back to your docs, including the JWT as the hash
2020
</Step>
2121
<Step title="Configure your User Auth settings">
22-
Return to your [Mintlify dashboard settings](https://dashboard.mintlify.com/settings/integrations) and add the login URL to your User Auth settings.
22+
Return to your [Mintlify dashboard settings](https://dashboard.mintlify.com/mintlify/mintlify/settings/deployment/user-authentication) and add the login URL to your User Auth settings.
2323
</Step>
2424
</Steps>
2525

advanced/user-auth/oauth.mdx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: 'OAuth 2.0'
3+
description: 'Integrate with your OAuth server to enable user login via the PKCE flow'
4+
---
5+
6+
If you have an existing OAuth server that supports the PKCE flow, you can integrate with Mintlify for a seamless login experience.
7+
8+
## Implementation
9+
10+
<Steps>
11+
<Step title="Create your Info API">
12+
Create an API endpoint that can be accessed with an OAuth access token, and responds with a JSON payload following the [UserInfo](./sending-data) format. Take note of the scope or scopes required to access this endpoint.
13+
</Step>
14+
<Step title="Configure your User Auth settings">
15+
Go to your [Mintlify dashboard settings](https://dashboard.mintlify.com/mintlify/mintlify/settings/deployment/user-authentication), select the OAuth option, and fill out the required fields:
16+
17+
- **Authorization URL**: The base URL for the authorization request, to which we will add the appropriate query parameters.
18+
- **Client ID**: An ID for the OAuth 2.0 client to be used.
19+
- **Scopes**: An array of scopes that will be requested.
20+
- **Token URL**: The base URL for the token exchange request.
21+
- **Info API URL**: The endpoint that will be hit to retrieve user info.
22+
</Step>
23+
<Step title="Configure your OAuth client">
24+
Copy the Redirect URL listed in the [Mintlify dashboard settings](https://dashboard.mintlify.com/mintlify/mintlify/settings/deployment/user-authentication) and add it as an authorized redirect URL for your OAuth server.
25+
</Step>
26+
</Steps>
27+
28+
## Example
29+
30+
I have an existing OAuth server that supports the PKCE flow. I want to set up authentication for my docs hosted at `foo.com/docs`.
31+
32+
To set up authentication with Mintlify, I create an endpoint `api.foo.com/docs/user-info` which requires an OAuth access token with the `docs-user-info` scope, and responds with the user's custom data according to Mintlify’s specification.
33+
34+
I then go to the Mintlify dashboard settings, navigate to the User Auth settings, select OAuth, and enter the relevant values for the OAuth flow and Info API endpoint:
35+
- **Authorization URL**: `https://auth.foo.com/authorization`
36+
- **Client ID**: `ydybo4SD8PR73vzWWd6S0ObH`
37+
- **Scopes**: `['docs-user-info']`
38+
- **Token URL**: `https://auth.foo.com/exchange`
39+
- **Info API URL**: `https://api.foo.com/docs/user-info`
40+
41+
Finally, I copy the Redirect URL displayed in the dashboard settings and add it as an authorized redirect URL in my OAuth client configuration settings.

advanced/user-auth/shared-session.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This method utilizes the session authentication info already stored in your user
1919
</Warning>
2020
</Step>
2121
<Step title="Configure your User Auth settings">
22-
Go to your [Mintlify dashboard settings](https://dashboard.mintlify.com/settings/integrations) and add the API URL and your Login URL to your User Auth settings.
22+
Go to your [Mintlify dashboard settings](https://dashboard.mintlify.com/mintlify/mintlify/settings/deployment/user-authentication) and add the API URL and your Login URL to your User Auth settings.
2323
</Step>
2424
</Steps>
2525

mint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@
158158
"pages": [
159159
"advanced/user-auth/choosing-an-auth-method",
160160
"advanced/user-auth/shared-session",
161-
"advanced/user-auth/jwt"
161+
"advanced/user-auth/jwt",
162+
"advanced/user-auth/oauth"
162163
]
163164
},
164165
"advanced/user-auth/sending-data"

0 commit comments

Comments
 (0)