Skip to content

Commit c243677

Browse files
DC-5694 OAuth Clarification (#7205)
* updated docs * link updated * Buidl error fix * unrelated github action update * update clarity * caching max age adjusted * lychee params adjusted * cache size updates * lychee updates * retry removed * chore: trigger link checker workflow
1 parent 2619584 commit c243677

File tree

3 files changed

+69
-44
lines changed

3 files changed

+69
-44
lines changed

.github/workflows/lychee.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@ jobs:
2323
output: ../lychee/out.md
2424
args: >
2525
--cache
26-
--max-cache-age 3h
26+
--max-cache-age 5m
2727
--verbose
2828
--no-progress
2929
--accept 200,201,204,304,403,429
3030
--timeout 20
31-
--max-retries 5
31+
--max-retries 8
3232
--retry-wait-time 5
33-
--max-concurrency 16
3433
--exclude 'http://localhost.*'
3534
--exclude 'https://localhost.*'
36-
--exclude 'https://dev.mysql.com/.*'
37-
--exclude 'https://www.mysql.com/.*'
38-
--exclude 'https://www.gnu.org/.*'
39-
--exclude 'https://www.cockroachlabs.com/.*'
35+
--exclude 'https://cockroachlabs.com'
4036
--exclude '^/.*'
4137
'./**/*.md' './**/*.mdx'
4238
workingDirectory: "content"
@@ -54,7 +50,7 @@ jobs:
5450
cat > lychee/formatted.md << 'EOF'
5551
## 🍈 Lychee Link Check Report
5652
57-
> **Note:** Links are cached for 3 hours to avoid unnecessary requests, and speed up consecutive runs.
53+
> **Note:** Links are cached for 5 minutes to avoid unnecessary requests, and speed up consecutive runs.
5854
5955
### 📊 Results Overview
6056

content/250-postgres/100-introduction/230-management-api.mdx

Lines changed: 64 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ We have three guides to help you use the Management API for common scenarios:
2020
- [Partner database provisioning & user claim flow](/guides/management-api)
2121
:::
2222

23-
2423
## Base URL
2524

2625
The base URL for a Prisma Postgres API request is:
@@ -37,52 +36,83 @@ https://api.prisma.io/v1/projects/{projectId}
3736

3837
## Authentication
3938

40-
### Bearer tokens
39+
The Prisma Postgres API supports two authentication methods:
40+
41+
- **Service tokens** — for accessing resources in your own workspace
42+
- **OAuth 2.0 access tokens** — for accessing or managing resources on behalf of users
43+
44+
### Service tokens
4145

42-
The Prisma Postgres API uses _Bearer Token Authentication_ and supports two kinds of tokens:
43-
- Service tokens (manually created in your [Prisma Console](https://console.prisma.io) workspace)
44-
- OAuth 2 access tokens
46+
Service tokens are manually created in your [Prisma Console](https://console.prisma.io) workspace. They're ideal for server-to-server integrations or provisioning databases in your own workspace.
4547

46-
To adhere to the Bearer Token Authentication, you need to format your `Authorization` header like this:
48+
To authenticate with a service token, include it in the `Authorization` header:
4749

4850
```
4951
Authorization: Bearer $TOKEN
5052
```
5153

5254
#### Creating a service token
5355

54-
You can create a service token to use the Management API like this:
55-
5656
1. Open the [Prisma Console](https://console.prisma.io/).
5757
2. Navigate to your workspace.
58-
3. Navigate to the **Settings** page of your workspace and select **Service Tokens**.
59-
4. Click **New Service Token**.
60-
5. Copy the generated token and store it in a safe location for future use.
58+
3. Go to the **Settings** page of your workspace and select **Service Tokens**.
59+
4. Click **New Service Token** and copy the generated token for future use.
60+
61+
### OAuth 2.0 authentication
62+
63+
Use OAuth 2.0 if you want to act on behalf of users and create or manage databases directly in their workspaces.
6164

6265
#### Creating OAuth credentials
6366

64-
To obtain a client ID and client secret, go through this flow:
67+
To obtain a client ID and client secret:
6568

6669
1. Open the [Prisma Console](https://console.prisma.io).
67-
1. Click the 🧩 **Integrations** tab in the sidenav.
68-
1. In the **Published Applications** section, click the **New Application** button to start creating a new OAuth app.
69-
1. Enter a **Name**, **Description**, and **Callback URL** for your OAuth app.
70-
1. Click **Continue**.
70+
2. Click the 🧩 **Integrations** tab.
71+
3. Under **Published Applications**, click **New Application**.
72+
4. Enter a **Name**, **Description**, and **Redirect URI** (the URL where users will be redirected after authorization).
73+
5. Click **Continue**, then copy and store your **Client ID** and **Client Secret** to a secure location.
74+
75+
#### OAuth authorization flow
76+
77+
To use OAuth 2.0, your application must:
78+
79+
1. **Redirect users to the authorization URL** with your client ID and redirect URI:
80+
```
81+
https://auth.prisma.io/authorize?client_id=$CLIENT_ID&redirect_uri=$REDIRECT_URI&response_type=code&scope=workspace:admin
82+
```
83+
84+
2. **Receive the authorization code**: After the user authorizes your application, they'll be redirected to your redirect URI with a `code` parameter:
85+
```
86+
https://your-app.com/callback?code=abc123...
87+
```
88+
89+
3. **Exchange the code for an access token**: Use the code from step 2 in the following request
90+
91+
```bash
92+
curl -X POST https://auth.prisma.io/token \
93+
-H "Content-Type: application/x-www-form-urlencoded" \
94+
-d "client_id=$CLIENT_ID" \
95+
-d "client_secret=$CLIENT_SECRET" \
96+
-d "code=$CODE" \
97+
-d "grant_type=authorization_code" \
98+
-d "redirect_uri=$REDIRECT_URI"
99+
```
71100

72-
On the next screen, copy and store the client ID and client secret for your OAuth app in a secure location.
101+
:::note
102+
The `$CODE` is the authorization code received in step 2 above. The `$REDIRECT_URI` must match exactly what you configured when creating your OAuth credentials.
103+
:::
73104

74-
### Example
105+
Once you have an access token from the response, include it in requests to the Management API:
75106

76-
```terminal
107+
```bash
77108
curl --location "https://api.prisma.io/v1/projects" \
78109
-H "Accept: application/json" \
79-
-H "Authorization: Bearer $TOKEN" \
110+
-H "Authorization: Bearer $ACCESS_TOKEN" \
80111
-H "Content-Type: application/json" \
81-
--data \
82-
"{
83-
\"name\": \"my_project\",
84-
\"region\": \"us-east-1\"
85-
}"
112+
--data '{
113+
"name": "my_project",
114+
"region": "us-east-1"
115+
}'
86116
```
87117

88118
### Instructions
@@ -101,13 +131,13 @@ curl --location "https://api.prisma.io/v1/projects" \
101131

102132
1. In the **Authorization** tab, set type to **OAuth 2.0**.
103133
2. Click **Get New Access Token** and fill in the details:
104-
- **Token Name**: Any name
105-
- **Grant Type**: Authorization Code
106-
- **Callback URL**: `http://localhost:8789/swagger/oauth2-redirect.html`
107-
- **Auth URL** / **Access Token URL**: Your local OAuth URLs
108-
- **Client ID / Secret**: From the script output
109-
- **Scope**: (as needed)
110-
1. After completing the flow, use the token in your requests.
134+
- **Token Name**: Any name
135+
- **Grant Type**: Authorization Code
136+
- **Redirect URI**: Your app's redirect URI (must match what you configured in OAuth credentials)
137+
- **Auth URL**: `https://auth.prisma.io/authorize`
138+
- **Client ID / Secret**: From your OAuth app
139+
- **Scope**: `workspace:admin offline_access` (as needed)
140+
3. Complete the flow and use the token in your requests.
111141

112142
</details>
113143

@@ -360,7 +390,6 @@ Retrieve integrations for the given workspace.
360390
- `401 Unauthorized`: Missing or invalid authentication token
361391
- `404 Not Found`: Workspace not found
362392

363-
364393
#### `DELETE /workspaces/{workspaceId}/integrations/{clientId}`
365394

366395
Revokes the integration tokens with the given client ID.
@@ -383,7 +412,7 @@ Retrieve all available regions.
383412
- `200 OK`: Returns list of available/unsupported regions
384413
- `401 Unauthorized`
385414

386-
<!-- ## Management API playground
415+
{/* ## Management API playground
387416
388417
You can explore and interact with all endpoints in a live Swagger UI playground.
389418
@@ -401,4 +430,4 @@ Use your service token or OAuth 2.0 access token to authorize requests in the UI
401430
overflow: 'hidden'
402431
}}
403432
title="Prisma API Swagger Editor"
404-
></iframe> -->
433+
></iframe> */}

content/800-guides/330-management-api-basic.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ community_section: true
1212

1313
This guide walks you through setting up a basic TypeScript project that uses the [Prisma Postgres Management API](/postgres/introduction/management-api) to create a new [Prisma Console project](/platform/about#project) with a [Prisma Postgres](/postgres/introduction/overview) database, and print out all connection details.
1414

15-
You'll authenticate via a [service token](/postgres/introduction/management-api#bearer-tokens), set up your environment, and run a script to interact with the API.
15+
You'll authenticate via a [service token](/postgres/introduction/management-api#service-tokens), set up your environment, and run a script to interact with the API.
1616

1717
:::tip OpenApi
1818
The API reference is also available via an [OpenAPI 3.1. spec](https://api.prisma.io/v1/swagger-editor).

0 commit comments

Comments
 (0)