OAuth
2 operations.
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/oauth/callback/{presetKey} | Complete a BYOC OAuth dance and persist the Connection |
| GET | /api/oauth/start/{presetKey} | Begin a BYOC OAuth dance for a Project Environment |
Complete a BYOC OAuth dance and persist the Connection
GET/api/oauth/callback/{presetKey}
Receives the redirect from the provider after the user grants consent.
Reads the signed state cookie set by /api/oauth/start/:presetKey,
verifies it, exchanges the authorization code for tokens at the provider's
token endpoint, captures the granted scopes and account identity, encrypts
the tokens, and upserts the Connection row for the Project Environment
selected by the signed state.
After authentication, OAuth flow outcomes use a 302 redirect to the
signed state's returnTo URL, or the Studio root if state is invalid.
Authentication failures return 401; unexpected server failures remain 5xx.
Use a browser session or Bearer API key with current permission to connect the Project Environment pinned in the signed state. Permission is checked again before exchanging the code. API clients must return the retained state cookie and provider state value and handle the redirect manually.
Parameters
path
| Name | Type | Required | Description |
|---|---|---|---|
| presetKey | string | required | Identifies the OAuth preset whose authorization flow is being requested. Applies to Complete a BYOC OAuth dance and persist the Connection. |
query
| Name | Type | Required | Description |
|---|---|---|---|
| code | string | optional | Carries the OAuth provider error code returned during authorization. Applies to Complete a BYOC OAuth dance and persist the Connection. |
| state | string | optional | OAuth CSRF and correlation token returned by the provider; send it back unchanged. |
| error | string | optional | Carries the OAuth provider error identifier returned during authorization. Applies to Complete a BYOC OAuth dance and persist the Connection. |
| error_description | string | optional | Carries the OAuth provider's human-readable error description. Applies to Complete a BYOC OAuth dance and persist the Connection. |
Responses
| Status | Description | Body |
|---|---|---|
| 400 | Bad Request | application/json object
|
| 401 | Authentication failed. Possible reasons: - Authorization header is not provided - Invalid API key - Session expired | application/json object
|
| 403 | Access denied. The authenticated user does not have permission to perform this action. | application/json object
|
| 404 | Resource not found. | application/json object
|
| 422 | Request validation failed. Check the request body, query parameters, or path parameters. | application/json object
|
| 429 | Rate limited by an upstream dependency. Retry after the Retry-After interval. | application/json object
|
| 500 | Response for status 500 | application/json object
|
| 503 | Service temporarily unavailable (e.g. execution capacity exhausted). The response carries a Retry-After header; retry with backoff. | application/json object
|
Begin a BYOC OAuth dance for a Project Environment
GET/api/oauth/start/{presetKey}
Generates a PKCE pair and signed state cookie, then redirects the browser
to the provider's authorization endpoint. The companion
/api/oauth/callback/:presetKey endpoint completes the exchange.
Use a browser session or Bearer API key with the required Project operation permission. The Project and Environment must exist in the caller's organization, and the organization must have a verified Integration registered for the preset. OAuth state pins the selected Integration Version until the callback completes. API clients must handle the redirect manually and retain the state cookie for the callback; never forward the Perstack API key to the provider.
Parameters
path
| Name | Type | Required | Description |
|---|---|---|---|
| presetKey | string | required | Identifies the OAuth preset whose authorization flow is being requested. Applies to Begin a BYOC OAuth dance for a Project Environment. |
query
| Name | Type | Required | Description |
|---|---|---|---|
| projectId | string | required | Filters results to the specified Project. Applies to Begin a BYOC OAuth dance for a Project Environment. |
| environmentId | string | required | Selects the active Project environment coordinate. Applies to Begin a BYOC OAuth dance for a Project Environment. |
| returnTo | string | optional | Sets the browser return location after the OAuth flow completes. Applies to Begin a BYOC OAuth dance for a Project Environment. |
Responses
| Status | Description | Body |
|---|---|---|
| 400 | Bad Request | application/json object
|
| 401 | Authentication failed. Possible reasons: - Authorization header is not provided - Invalid API key - Session expired | application/json object
|
| 403 | Access denied. The authenticated user does not have permission to perform this action. | application/json object
|
| 404 | Resource not found. | application/json object
|
| 422 | Request validation failed. Check the request body, query parameters, or path parameters. | application/json object
|
| 429 | Rate limited by an upstream dependency. Retry after the Retry-After interval. | application/json object
|
| 500 | Response for status 500 | application/json object
|
| 503 | Service temporarily unavailable (e.g. execution capacity exhausted). The response carries a Retry-After header; retry with backoff. | application/json object
|