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

# 토큰 발행

> Client ID와 Client Secret으로 Dayfin API 호출에 필요한 Access Token을 발급받는 토큰 발행 API의 요청 및 응답 명세입니다.

Client Credentials 방식으로 Access Token을 발급합니다. 발급받은 토큰은 `Authorization: Bearer {ACCESS_TOKEN}` 헤더에 담아 API를 호출할 때 사용합니다. 전체 이용 절차는 [토큰 발급 및 이용 안내](https://docs.bonanzalab.io/oauth.md)를 참고하세요.

## 인증

HTTP Basic 인증을 사용합니다. Client ID와 Client Secret을 `:`로 연결한 뒤 Base64로 인코딩하여 전달합니다.

```text theme={null}
Authorization: Basic Base64({CLIENT_ID}:{CLIENT_SECRET})
```

## 요청 헤더

**Authorization** `string` *required*

`Basic Base64(Client ID:Client Secret)`

**Content-Type** `string` *required*

`application/x-www-form-urlencoded` 권장 (`application/json`도 지원)

**Accept** `string`

`application/json`

## 요청 파라미터

**grant\_type** `string` *required*

`client_credentials` 고정

**scope** `string` *required*

계약 시 할당받은 Scope

## 응답 필드

**rspCode** `string`

처리 결과 코드. 성공 시 `A0000`

**rspMessage** `string`

처리 결과 메시지

**access\_token** `string`

API 호출에 사용할 Access Token (JWT)

**token\_type** `string`

토큰 타입. `bearer`

**expires\_in** `number`

토큰의 남은 유효시간(초)

**scope** `string`

요청한 Scope

**jti** `string`

발급된 토큰의 고유 식별자

> [!NOTE]
>
> `expires_in`은 고객사별 설정에 따라 달라질 수 있습니다. 고정값을 사용하지 말고 응답값을 기준으로 만료 시점을 계산해 주세요. Refresh Token은 제공되지 않으므로 만료 전에 이 API를 다시 호출해 새 토큰을 받아 주세요.

## 오류 코드

| HTTP 상태 | rspCode | 발생 조건 |
| :-: | - | - |
| 401 | `A7771` | `grant_type` 누락 |
| 401 | `A7772` | `scope` 누락 |
| 401 | `A7773` | Client ID 또는 Client Secret 불일치 |
| 401 | `A7774` | 허용되지 않은 Scope |
| 401 | `A7775` | 허용되지 않은 Grant Type |
| 401 | `A1015` | 등록되지 않은 IP에서 요청 |
| 500 | `A7779` | 토큰 생성 실패 |
| 500 | `A1002` | 요청 처리 중 서버 오류 |

```bash Form theme={null}
curl --request POST \
  --url "https://api.dayfin.io/oauth/token" \
  --user "{CLIENT_ID}:{CLIENT_SECRET}" \
  --header "Accept: application/json" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "grant_type=client_credentials" \
  --data-urlencode "scope={ASSIGNED_SCOPE}"
```

```bash JSON theme={null}
curl --request POST \
  --url "https://api.dayfin.io/oauth/token" \
  --user "{CLIENT_ID}:{CLIENT_SECRET}" \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --data '{
    "grant_type": "client_credentials",
    "scope": "{ASSIGNED_SCOPE}"
  }'
```

```json 200 theme={null}
{
  "rspCode": "A0000",
  "rspMessage": "정상",
  "access_token": "{ACCESS_TOKEN}",
  "token_type": "bearer",
  "expires_in": 3599,
  "scope": "{ASSIGNED_SCOPE}",
  "jti": "550e8400-e29b-41d4-a716-446655440000"
}
```

```json 401 theme={null}
{
  "rspCode": "A7773",
  "rspMessage": "등록된 기관정보가 없습니다."
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.