Documentation menu

OAuth

2 operations.

MethodEndpointDescription
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

NameTypeRequiredDescription
presetKeystringrequiredIdentifies the OAuth preset whose authorization flow is being requested. Applies to Complete a BYOC OAuth dance and persist the Connection.

query

NameTypeRequiredDescription
codestringoptionalCarries the OAuth provider error code returned during authorization. Applies to Complete a BYOC OAuth dance and persist the Connection.
statestringoptionalOAuth CSRF and correlation token returned by the provider; send it back unchanged.
errorstringoptionalCarries the OAuth provider error identifier returned during authorization. Applies to Complete a BYOC OAuth dance and persist the Connection.
error_descriptionstringoptionalCarries the OAuth provider's human-readable error description. Applies to Complete a BYOC OAuth dance and persist the Connection.

Responses

StatusDescriptionBody
302Redirects the browser to the Studio return URL carrying the flow outcome.none — none
400The request is malformed or cannot be processed.application/json — PublicApiError — error: object (required)
401Authentication failed. The Authorization header is missing, or the credential is invalid or expired.application/json — PublicApiError — error: object (required)
403Access denied. The authenticated user does not have permission to perform this action.application/json — PublicApiError — error: object (required)
404Resource not found.application/json — PublicApiError — error: object (required)
409Request conflicts with current state of the resource, including safe deployment conflict classifications.application/json — PublicApiError — error: object (required)
422Request validation failed. Check the request body, query parameters, or path parameters.application/json — PublicApiError — error: object (required)
429Too many requests. The code foreign_resource_rate_limited means the caller made too many requests for Projects outside its reach: correct the Project id instead of retrying.application/json — PublicApiError — error: object (required)
500The server could not complete the request.application/json — PublicApiError — error: object (required)
503Service temporarily unavailable (e.g. execution capacity exhausted). The response carries a Retry-After header; retry with backoff.application/json — PublicApiError — error: object (required)

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

NameTypeRequiredDescription
presetKeystringrequiredIdentifies the OAuth preset whose authorization flow is being requested. Applies to Begin a BYOC OAuth dance for a Project Environment.

query

NameTypeRequiredDescription
projectIdstringrequiredFilters results to the specified Project. Applies to Begin a BYOC OAuth dance for a Project Environment.
environmentIdstringrequiredSelects the active Project environment coordinate. Applies to Begin a BYOC OAuth dance for a Project Environment.
returnTostringoptionalSets the browser return location after the OAuth flow completes. Applies to Begin a BYOC OAuth dance for a Project Environment.

Responses

StatusDescriptionBody
302Redirects the browser to the provider's authorization URL.none — none
400The request is malformed or cannot be processed.application/json — PublicApiError — error: object (required)
401Authentication failed. The Authorization header is missing, or the credential is invalid or expired.application/json — PublicApiError — error: object (required)
403Access denied. The authenticated user does not have permission to perform this action.application/json — PublicApiError — error: object (required)
404Resource not found.application/json — PublicApiError — error: object (required)
409Request conflicts with current state of the resource, including safe deployment conflict classifications.application/json — PublicApiError — error: object (required)
422Request validation failed. Check the request body, query parameters, or path parameters.application/json — PublicApiError — error: object (required)
429Too many requests. The code foreign_resource_rate_limited means the caller made too many requests for Projects outside its reach: correct the Project id instead of retrying.application/json — PublicApiError — error: object (required)
500The server could not complete the request.application/json — PublicApiError — error: object (required)
503Service temporarily unavailable (e.g. execution capacity exhausted). The response carries a Retry-After header; retry with backoff.application/json — PublicApiError — error: object (required)