
# 애플리케이션 자격 증명 생성

`POST /v1/applications/{application_id}/credentials` · 권한 `applications:write` · `Idempotency-Key` 선택사항

애플리케이션에 자격 증명을 추가합니다: 플랫폼에서 생성된 클라이언트 시크릿(`type: client_secret`) 또는 `private_key_jwt`용 등록된 공개 키(`type: public_key`).

- **클라이언트 시크릿.** 응답에는 `client_secret`이 한 번만 포함됩니다. 다시 검색할 수 없습니다. 즉시 저장하십시오. 애플리케이션은 최대 2개의 활성 시크릿을 보유하므로 다운타임 없이 시크릿을 회전할 수 있습니다.
- **공개 키.** `jwk`에서 공개 JWK를 보냅니다. 개인 멤버(`d`, `p`, `q`, `dp`, `dq`, `qi`, `oth`, `k`)가 있거나 16KiB보다 큰 JWK는 거부됩니다. 애플리케이션은 최대 5개의 키를 보유합니다.
- **멱등성 재생.** 동일한 `Idempotency-Key`로 요청을 반복하면 시크릿 없이 저장된 응답을 재생합니다: 본문에는 `secret_redacted: true`가 있고 `client_secret`이 없습니다. 시크릿이 손실된 경우 새 자격 증명을 생성합니다.

## 요청

| 매개변수 | 위치 | 설명 |
|---|---|---|
| `application_id` | yol | Application id (`app_…`). |

Body:

| 필드 | 유형 | 설명 |
|---|---|---|
| `type` | string | Required. `client_secret` or `public_key`. |
| `expires_at` | string (date-time) | Optional, `client_secret` only; must be in the future. |
| `jwk` | object | Required for `public_key`; a public JWK, at most 16 KiB. |

## 응답

`201 Created` with `Cache-Control: no-store`. The credential object as in the list response; for `client_secret` it also has `client_secret`.

```json
{
  "id": "cred_0000000000000000000000001z",
  "type": "client_secret",
  "secret_last4": "abcd",
  "client_secret": "<shown once>",
  "expires_at": null
}
```

## 오류

| HTTP | `code` | 언제 |
|---|---|---|
| 401 | `unauthenticated` | The key is missing, invalid or revoked. |
| 403 | `insufficient_permissions` | The key lacks the required permission. |
| 404 | `not_found` | The application does not exist in this environment. |
| 409 | `credential_limit_reached` | The application already has the maximum number of active secrets (2) or keys (5). |
| 409 | `conflict` | The same public key is already registered for the application. |
| 422 | `validation_failed` | The body is invalid: unknown `type`, missing `jwk`, private JWK members, JWK too large, `expires_at` in the past or sent with `public_key`, or a credential type the application type does not allow (`/type: not_allowed`: `client_secret` only for `web` and `m2m`; `public_key` for `web`, `m2m`, `device` and `management`; `spa` and `native` are public clients and take no credentials). |
| 503 | `service_unavailable` | The credential registry is temporarily unavailable; retry after the `Retry-After` delay. |

## 예제

```bash
curl -X POST https://api.eu.keenauth.com/v1/applications/app_6f8d0cjgbmf0gtn2rg6pscp3cg/credentials \
  -H "Authorization: Bearer $KEENAUTH_SECRET_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"type":"client_secret"}'
```
