Ranch.Bot
Skip to reference

OAuth API

HTTP reference for oauth. Read authentication and access before using these operations. All examples use made-up data and placeholder credentials.

GET /oauth/.well-known/oauth-authorization-server

Discovery

Current oauth HTTP operation. No resource-scope middleware on this operation. Access is resolved for the authenticated user or by the endpoint-specific OAuth checks.

Request example

bash example
curl --fail-with-body -X GET \
  'https://api.ranch.bot/oauth/.well-known/oauth-authorization-server'

Responses

StatusMeaningContent type
200Successapplication/json
400Request validation failed.application/json
401Missing/invalid authentication or insufficient farm role.application/json
403Missing required scope or credential type is disallowed.application/json
404Resource or active farm membership not found.application/json
500Unexpected server failure.application/json

200 response schema (application/json)

FieldTypePresenceConstraints
issuerstringRequired
authorization_endpointstringRequired
token_endpointstringRequired
revocation_endpointstringRequired
userinfo_endpointstringRequired
jwks_uristringRequired
response_types_supportedarrayRequired
response_types_supported[]stringRequired
grant_types_supportedarrayRequired
grant_types_supported[]stringRequired
code_challenge_methods_supportedarrayRequired
code_challenge_methods_supported[]stringRequired
scopes_supportedarrayRequired
scopes_supported[]stringRequired
token_endpoint_auth_methods_supportedarrayRequired
token_endpoint_auth_methods_supported[]stringRequired
json example
{
  "issuer": "example",
  "authorization_endpoint": "example",
  "token_endpoint": "PLACEHOLDER_CREDENTIAL",
  "revocation_endpoint": "example",
  "userinfo_endpoint": "example",
  "jwks_uri": "https://example.com",
  "response_types_supported": [],
  "grant_types_supported": [],
  "code_challenge_methods_supported": [],
  "scopes_supported": [],
  "token_endpoint_auth_methods_supported": []
}

GET /oauth/authorize

Authorize

Current oauth HTTP operation. No resource-scope middleware on this operation. Access is resolved for the authenticated user or by the endpoint-specific OAuth checks.

ParameterInRequiredSchema
client_idqueryYes{"type":"string"}
redirect_uriqueryYes{"type":"string"}
response_typequeryYes{"type":"string","const":"code"}
scopequeryYes{"type":"string"}
statequeryNo{"type":"string"}
code_challengequeryNo{"type":"string"}
code_challenge_methodqueryNo{"type":"string"}

Replace PLACEHOLDER_CLIENT_ID with your registered client ID and https://your-app.example/oauth/callback with your registered callback URL, then URL-encode both values. The example requests read:animals.

Request example

bash example
curl --fail-with-body -X GET \
  'https://api.ranch.bot/oauth/authorize?client_id=PLACEHOLDER_CLIENT_ID&redirect_uri=https%3A%2F%2Fyour-app.example%2Foauth%2Fcallback&response_type=code&scope=read%3Aanimals'

Responses

StatusMeaningContent type
302Redirect to the configured authentication or consent flow.No body
400Request validation failed.application/json
401Missing/invalid authentication or insufficient farm role.application/json
403Missing required scope or credential type is disallowed.application/json
404Resource or active farm membership not found.application/json
500Unexpected server failure.application/json

POST /oauth/device

Device

Current oauth HTTP operation. No resource-scope middleware on this operation. Access is resolved for the authenticated user or by the endpoint-specific OAuth checks. Production rate limit: 30 requests per 15-minute window, per client IP. RateLimit headers report the current window; respect Retry-After on 429. Requires an active registered client and only that client’s allowed scopes. Codes expire after 900 seconds; poll no faster than every 5 seconds. The user approves in the browser. No public self-serve client registration is provided.

Request body (application/json)

FieldTypePresenceConstraints
client_idstringRequiredminLength: 1; maxLength: 255
scopestringOptionalmaxLength: 1024
json example
{
  "client_id": "11111111-1111-4111-8111-111111111111"
}

Request example

bash example
curl --fail-with-body -X POST \
  'https://api.ranch.bot/oauth/device' \
  -H "Content-Type: application/json" \
  --data '{"client_id":"11111111-1111-4111-8111-111111111111"}'

Responses

StatusMeaningContent type
200Successapplication/json
400Request validation failed.application/json
401Missing/invalid authentication or insufficient farm role.application/json
403Missing required scope or credential type is disallowed.application/json
404Resource or active farm membership not found.application/json
429Rate limit exceeded. Retry after the indicated delay.application/json
500Unexpected server failure.application/json

200 response schema (application/json)

FieldTypePresenceConstraints
device_codestringRequired
user_codestringRequired
verification_uristringRequired
verification_uri_completestringRequired
expires_innumberRequired
intervalnumberRequired
json example
{
  "device_code": "example",
  "user_code": "example",
  "verification_uri": "https://example.com",
  "verification_uri_complete": "example",
  "expires_in": 1,
  "interval": 1
}

POST /oauth/device/token

Device Token

Current oauth HTTP operation. No resource-scope middleware on this operation. Access is resolved for the authenticated user or by the endpoint-specific OAuth checks. Production rate limit: 240 requests per 15-minute window, per client IP. RateLimit headers report the current window; respect Retry-After on 429. Poll with the returned device_code and original client_id. Pending authorization returns an OAuth 400 body. Malformed request bodies return the standard validation 400 envelope. Invalid, consumed, expired, mismatched-client, or disallowed-permission device codes return the standard 401 envelope.

Request body (application/json)

FieldTypePresenceConstraints
grant_typestringRequiredconst: "urn:ietf:params:oauth:grant-type:device_code"
device_codestringRequiredminLength: 1; maxLength: 128
client_idstringRequiredminLength: 1; maxLength: 255
json example
{
  "grant_type": "urn:ietf:params:oauth:grant-type:device_code",
  "device_code": "example",
  "client_id": "11111111-1111-4111-8111-111111111111"
}

Request example

bash example
curl --fail-with-body -X POST \
  'https://api.ranch.bot/oauth/device/token' \
  -H "Content-Type: application/json" \
  --data '{"grant_type":"urn:ietf:params:oauth:grant-type:device_code","device_code":"example","client_id":"11111111-1111-4111-8111-111111111111"}'

Responses

StatusMeaningContent type
200Successapplication/json
400Pending authorization returns an OAuth error object; malformed request bodies return the standard validation error envelope.application/json
401Invalid, consumed, expired, mismatched-client, or disallowed-permission device code; returns the standard error envelope.application/json
403Missing required scope or credential type is disallowed.application/json
404Resource or active farm membership not found.application/json
429Rate limit exceeded. Retry after the indicated delay.application/json
500Unexpected server failure.application/json

200 response schema (application/json)

FieldTypePresenceConstraints
scopestringRequired
access_tokenstringRequired
token_typestringRequiredconst: "Bearer"
expires_innumberRequired
refresh_tokenstringOptional
json example
{
  "scope": "read:animals",
  "access_token": "PLACEHOLDER_ACCESS_TOKEN",
  "refresh_token": "PLACEHOLDER_REFRESH_TOKEN",
  "token_type": "Bearer",
  "expires_in": 900
}

400 response schema (application/json)

FieldTypePresenceConstraints
(variant 1)objectRequired
(variant 1).errorstringRequired
(variant 1).error_descriptionstringRequired
(variant 2)objectRequired
(variant 2).successbooleanRequiredconst: false
(variant 2).errorsarrayRequired
(variant 2).errors[]objectRequired
(variant 2).errors[].codeintegerOptional
(variant 2).errors[].namestringOptional
(variant 2).errors[].messagestringRequired
(variant 2).datanullOptional
json example
{
  "error": "authorization_pending",
  "error_description": "The authorization request is still pending"
}

POST /oauth/revoke

Revoke

Current oauth HTTP operation. No resource-scope middleware on this operation. Access is resolved for the authenticated user or by the endpoint-specific OAuth checks. Production rate limit: 240 requests per 15-minute window, per client IP. RateLimit headers report the current window; respect Retry-After on 429.

Request body (application/json)

FieldTypePresenceConstraints
tokenstringRequiredminLength: 1; maxLength: 2048
client_idstringRequiredminLength: 1; maxLength: 255
json example
{
  "token": "PLACEHOLDER_CREDENTIAL",
  "client_id": "11111111-1111-4111-8111-111111111111"
}

Request example

bash example
curl --fail-with-body -X POST \
  'https://api.ranch.bot/oauth/revoke' \
  -H "Content-Type: application/json" \
  --data '{"token":"PLACEHOLDER_CREDENTIAL","client_id":"11111111-1111-4111-8111-111111111111"}'

Responses

StatusMeaningContent type
200Successapplication/json
400Request validation failed.application/json
401Missing/invalid authentication or insufficient farm role.application/json
403Missing required scope or credential type is disallowed.application/json
404Resource or active farm membership not found.application/json
429Rate limit exceeded. Retry after the indicated delay.application/json
500Unexpected server failure.application/json

200 response schema (application/json)

FieldTypePresenceConstraints
revokedbooleanRequired
json example
{
  "revoked": true
}

POST /oauth/token

Token

Current oauth HTTP operation. No resource-scope middleware on this operation. Access is resolved for the authenticated user or by the endpoint-specific OAuth checks. Production rate limit: 240 requests per 15-minute window, per client IP. RateLimit headers report the current window; respect Retry-After on 429. Authorization-code exchange requires code and redirect_uri. A refresh-token grant requires refresh_token. Use the configured client and its directed setup; do not infer a working public client from endpoint existence.

Request body (application/json)

FieldTypePresenceConstraints
grant_typestringRequiredenum: ["authorization_code","refresh_token"]
codestringOptional
redirect_uristringOptional
refresh_tokenstringOptional
client_idstringRequired
client_secretstringOptional
code_verifierstringOptional
json example
{
  "grant_type": "authorization_code",
  "client_id": "11111111-1111-4111-8111-111111111111"
}

Request example

bash example
curl --fail-with-body -X POST \
  'https://api.ranch.bot/oauth/token' \
  -H "Content-Type: application/json" \
  --data '{"grant_type":"authorization_code","client_id":"11111111-1111-4111-8111-111111111111"}'

Responses

StatusMeaningContent type
200Successapplication/json
400Request validation failed.application/json
401Missing/invalid authentication or insufficient farm role.application/json
403Missing required scope or credential type is disallowed.application/json
404Resource or active farm membership not found.application/json
429Rate limit exceeded. Retry after the indicated delay.application/json
500Unexpected server failure.application/json

200 response schema (application/json)

FieldTypePresenceConstraints
(variant 1) (variant 1)objectRequired
(variant 1) (variant 1).access_tokenstringRequired
(variant 1) (variant 1).token_typestringRequired
(variant 1) (variant 1).expires_innumberRequired
(variant 1) (variant 1).refresh_tokenstringRequired
(variant 1) (variant 1).scopestringRequired
(variant 1) (variant 2)objectRequired
(variant 1) (variant 2).refresh_tokenstringRequired
(variant 1) (variant 2).scopestringRequired
(variant 1) (variant 2).access_tokenstringRequired
(variant 1) (variant 2).token_typestringRequiredconst: "Bearer"
(variant 1) (variant 2).expires_innumberRequired
(variant 2)objectRequired
(variant 2).access_tokenstringRequired
(variant 2).token_typestringRequired
(variant 2).expires_innumberRequired
(variant 2).refresh_tokenstringRequired
json example
{
  "access_token": "PLACEHOLDER_CREDENTIAL",
  "token_type": "PLACEHOLDER_CREDENTIAL",
  "expires_in": 1,
  "refresh_token": "PLACEHOLDER_CREDENTIAL",
  "scope": "example"
}

Error body

Validation and authentication errors generally use this envelope. Rate-limit errors omit data; OAuth polling also has protocol-specific errors shown in its reference.

json example
{
  "success": false,
  "errors": [
    {
      "code": 400,
      "name": "ValidationError",
      "message": "Example validation failure"
    }
  ]
}