> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cerca.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Start OAuth authorization



## OpenAPI

````yaml https://app.stainless.com/api/spec/documented/cerca/openapi.documented.yml post /oauth/connect/{provider}
openapi: 3.1.0
info:
  description: API-key accessible routes for Cerca agents.
  title: Cerca API
  version: 0.0.0
servers:
  - url: https://api.cerca.dev
security:
  - bearerAuth: []
paths:
  /oauth/connect/{provider}:
    post:
      tags:
        - OAuth
      summary: Start OAuth authorization
      parameters:
        - schema:
            type: string
            minLength: 1
            example: google
          required: true
          in: path
          name: provider
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/OAuthConnectRequest'
      responses:
        '200':
          description: OAuth authorization start details.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OAuthConnectResponse'
        '400':
          description: Invalid OAuth connect request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Authentication required.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Not authorized for the requested connection owner.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Requested connection fleet was not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        default:
          description: Error response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Cerca from '@cerca-dev/sdk';

            const client = new Cerca({
              apiKey: process.env['CERCA_API_KEY'], // This is the default and can be omitted
            });

            const oauthConnectResponse = await client.oauth.connect('google', {
              owner: { type: 'organization' },
              returnOrigin: 'https://app.example.com',
            });

            console.log(oauthConnectResponse.authorizationUrl);
        - lang: Python
          source: |-
            import os
            from cerca import Cerca

            client = Cerca(
                api_key=os.environ.get("CERCA_API_KEY"),  # This is the default and can be omitted
            )
            oauth_connect_response = client.oauth.connect(
                provider="google",
                owner={
                    "type": "organization"
                },
                return_origin="https://app.example.com",
            )
            print(oauth_connect_response.authorization_url)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/matrices/cerca-go\"\n\t\"github.com/matrices/cerca-go/option\"\n)\n\nfunc main() {\n\tclient := cercago.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\toauthConnectResponse, err := client.OAuth.Connect(\n\t\tcontext.TODO(),\n\t\t\"google\",\n\t\tcercago.OAuthConnectParams{\n\t\t\tOwner: cercago.F[cercago.ConnectionOwnerUnionParam](cercago.ConnectionOwnerOrganizationConnectionOwnerParam{\n\t\t\t\tType: cercago.F(cercago.ConnectionOwnerOrganizationConnectionOwnerTypeOrganization),\n\t\t\t}),\n\t\t\tReturnOrigin: cercago.F(\"https://app.example.com\"),\n\t\t},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", oauthConnectResponse.AuthorizationURL)\n}\n"
        - lang: Ruby
          source: >-
            require "cerca"


            cerca = Cerca::Client.new(api_key: "My API Key")


            oauth_connect_response = cerca.oauth.connect("google", owner: {type:
            :organization}, return_origin: "https://app.example.com")


            puts(oauth_connect_response)
        - lang: CLI
          source: |-
            cerca oauth connect \
              --api-key 'My API Key' \
              --provider google \
              --owner '{type: organization}' \
              --return-origin https://app.example.com
components:
  schemas:
    OAuthConnectRequest:
      type: object
      properties:
        owner:
          $ref: '#/components/schemas/ConnectionOwner'
        scopes:
          type: array
          description: >-
            Provider-specific OAuth scopes. Empty entries are ignored after
            trimming.
          example:
            - email
            - profile
          items:
            type: string
        returnOrigin:
          type: string
          example: https://app.example.com
          description: HTTP(S) origin that receives the OAuth completion message.
      required:
        - owner
        - returnOrigin
      additionalProperties: false
    OAuthConnectResponse:
      type: object
      properties:
        authorizationUrl:
          type: string
          description: Provider authorization URL that the client should open.
          example: https://accounts.google.com/o/oauth2/v2/auth?...
        callbackOrigin:
          type: string
          description: Origin hosting the OAuth callback endpoint.
          example: https://app.cerca.dev
        expiresAt:
          type: string
          description: OAuth state expiration timestamp, when returned.
          example: '2026-04-15T12:00:00.000Z'
        stateNonce:
          type: string
          description: OAuth state nonce, when returned.
          example: nonce_abc123
      required:
        - authorizationUrl
        - callbackOrigin
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        code:
          type: string
          description: Stable machine-readable error code when the API can provide one.
          example: MONTHLY_TOKEN_BUDGET_EXCEEDED
      required:
        - error
    ConnectionOwner:
      oneOf:
        - type: object
          properties:
            type:
              type: string
              enum:
                - organization
              x-stainless-const: true
          required:
            - type
          additionalProperties: false
          title: OrganizationConnectionOwner
          x-stainless-variantName: OrganizationConnectionOwner
        - type: object
          properties:
            fleetId:
              type: string
              example: fleet_abc123
            type:
              type: string
              enum:
                - fleet
              x-stainless-const: true
          required:
            - fleetId
            - type
          additionalProperties: false
          title: FleetConnectionOwner
          x-stainless-variantName: FleetConnectionOwner
      description: >-
        Public owner for a reusable connection. Organization owners use the
        authenticated organization; fleet owners add a fleetId.
      discriminator:
        propertyName: type
  securitySchemes:
    bearerAuth:
      bearerFormat: Cerca API key
      scheme: bearer
      type: http

````