# Register an OAuth client dynamically

RFC 7591 dynamic client registration, open to any caller once the org has enabled it and chosen a base client (403 access_denied otherwise, or when the...

`POST /api/v1/auth/oauth2/register`

- Sign-in: None at the router: the operation is public, or checks its own proof (a signature, a token in the body, a signed link).
- Rate limit: Up to 500 requests every 3 seconds per IP address; up to 1,000 requests a minute per API key (some requests are not counted); up to 5 requests a minute per IP address; up to 10 requests an hour per dcrAddressLimiterKey.

RFC 7591 dynamic client registration, open to any caller once the org has enabled it and chosen a base client (403 `access_denied` otherwise, or when the org's client limit is reached). The new client is an agent client that requires PKCE and inherits the base client's app-bridge URLs; it answers 201 with the client credentials (no secret for `token_endpoint_auth_method` none) and an RFC 7592 registration access token. Records an audit entry.

## Request

Send the body as `application/json` or `application/x-www-form-urlencoded`.

| Field                        | Type            | Required | Constraints                        | Description |
| ---------------------------- | --------------- | -------- | ---------------------------------- | ----------- |
| `redirect_uris`              | array of string | Yes      | at least 1 items, at most 20 items | -           |
| `client_name`                | string          | No       | at most 200 characters             | -           |
| `scope`                      | string          | No       | at most 2000 characters            | -           |
| `grant_types`                | array of string | No       | at most 20 items                   | -           |
| `response_types`             | array of string | No       | at most 20 items                   | -           |
| `token_endpoint_auth_method` | string          | No       | at most 200 characters             | -           |
| `contacts`                   | array of string | No       | at most 20 items                   | -           |
| `logo_uri`                   | string          | No       | at most 2000 characters            | -           |
| `client_uri`                 | string          | No       | at most 2000 characters            | -           |
| `policy_uri`                 | string          | No       | at most 2000 characters            | -           |
| `tos_uri`                    | string          | No       | at most 2000 characters            | -           |
| `software_id`                | string          | No       | at most 200 characters             | -           |
| `software_version`           | string          | No       | at most 200 characters             | -           |

## Example request

Replace each `YOUR_...` value with your own.

```bash title="cURL"
curl -X POST "https://api.console.buildbase.app/api/v1/auth/oauth2/register" \
  -H "Content-Type: application/json" \
  -d '{
  "redirect_uris": [
    "string"
  ]
}'
```

```ts title="TypeScript"
const response = await fetch(
  'https://api.console.buildbase.app/api/v1/auth/oauth2/register',
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      redirect_uris: ['string'],
    }),
  }
);
if (!response.ok) {
  throw new Error(`${response.status}: ${await response.text()}`);
}
const data = await response.json();
```

```python title="Python"
import requests

response = requests.post(
    "https://api.console.buildbase.app/api/v1/auth/oauth2/register",
    json={
        "redirect_uris": [
            "string",
        ],
    },
    timeout=30,
)
response.raise_for_status()
data = response.json()
```

## Responses

### 201 Created

Created

```json title="Example"
{
  "client_id": "lyNLqehujJcQdxcET2INCEQEE0s77ABUNqHAECvL",
  "client_id_issued_at": 1794380685,
  "client_name": "Sec Agent",
  "client_secret": "[REDACTED]",
  "client_secret_expires_at": 0,
  "grant_types": ["authorization_code", "refresh_token"],
  "redirect_uris": [
    "https://app.example.com/cb0",
    "https://app.example.com/cb1",
    "https://app.example.com/cb2",
    "https://app.example.com/cb3",
    "https://app.example.com/cb4",
    "https://app.example.com/cb5",
    "https://app.example.com/cb6",
    "https://app.example.com/cb7",
    "https://app.example.com/cb8",
    "https://app.example.com/cb9"
  ],
  "registration_access_token": "[REDACTED]",
  "registration_client_uri": "http://localhost:3000/api/v1/auth/oauth2/register/lyNLqehujJcQdxcET2INCEQEE0s77ABUNqHAECvL?org=000000000000000000000001",
  "response_types": ["code"],
  "scope": "",
  "token_endpoint_auth_method": "[REDACTED]"
}
```

### Any other status

Any other answer the handler sends itself (its own refusals). Not described yet.

## Errors

Each refusal, what it means, and what to do. The request changed nothing.

### 400 Bad Request

**What it means:** The request failed a `validate()` schema, or an id in the path is not a valid id. `path` names the field.

**What to do:** Fix the field the body names in `path` (or read `message`) and send the request again. Nothing was changed.

```json title="Example"
{
  "error": true,
  "success": false,
  "path": "string",
  "message": "string"
}
```

### 429 Too Many Requests

**What it means:** A rate limit in `x-rateLimit` was reached. `retryAfter` and the `Retry-After` header say how many seconds until the window resets.

**What to do:** Wait the number of seconds in the `Retry-After` header (also `retryAfter` in the body), then retry. Slow down repeated calls.

```json title="Example"
{
  "success": false,
  "message": "string",
  "reason": "rate_limited",
  "retryAfter": 1
}
```

## Events

A successful call can send these [webhook events](/webhooks/overview) to the endpoints that subscribe to them:

- [`auth.client_self_registered`](/webhooks/overview#when-each-event-fires)

## Related

- [OAuth 2.0 guide](/authentication/overview): how this part of BuildBase works
- [All OAuth 2.0 operations](/http-api/reference/oauth-2-0)
- [API reference](/http-api/reference): every operation, by tag
- [Sign-in and credentials for the HTTP API](/http-api/authentication)
- [How the HTTP API reports errors](/http-api/errors)
- [Make your first call](/http-api/first-call)
- [Error codes](/reference/error-codes): every `code` the API returns
- OpenAPI: operation `oauth2.register.create` in [public-v1.json](https://docs.buildbase.app/openapi/public-v1.json)
