> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Collection OAuth Authorization Codes

`oauthAuthorizationCodes` được thiết kế cho các mã của luồng OAuth authorization code: mỗi mã một document, và client đổi mã đó lấy access token. Schema là `services/web/app/src/models/OauthAuthorizationCode.mjs`, và module web `oauth2-server` chứa mã lẽ ra sẽ ghi vào đây. Trong Ayakaleaf Pro không có gì gọi tới mã đó, nên collection luôn trống (xem Ghi chú).

#### Các trường

| Trường | Kiểu | Ý nghĩa | Nguồn |
| - | - | - | - |
| `_id` | ObjectId | Id document. | `OauthAuthorizationCode.mjs:6` |
| `authorizationCode` | String | Bản thân mã, lưu nguyên dạng (không hash). | `OauthAuthorizationCode.mjs:8`, `services/web/modules/oauth2-server/app/src/OAuth2Model.mjs:280` |
| `expiresAt` | Date | Thời điểm hết hiệu lực. Sau đó `getAuthorizationCode` từ chối mã, và chỉ mục TTL xóa nó. | `OauthAuthorizationCode.mjs:9`, `OAuth2Model.mjs:150-153,281` |
| `oauthApplication_id` | ObjectId | Client trong [OAuth Applications](https://ayakaleaf-pro.mintlify.site/vi/dev/data-model/oauth-applications-collection.md) đã yêu cầu mã. | `OauthAuthorizationCode.mjs:10`, `OAuth2Model.mjs:275-284` |
| `redirectUri` | String | URI chuyển hướng của yêu cầu. | `OauthAuthorizationCode.mjs:11`, `OAuth2Model.mjs:282` |
| `scope` | String | Scope được yêu cầu. | `OauthAuthorizationCode.mjs:12`, `OAuth2Model.mjs:283` |
| `user_id` | ObjectId | Người dùng đã cấp mã. | `OauthAuthorizationCode.mjs:13`, `OAuth2Model.mjs:285` |
| `codeChallenge`, `codeChallengeMethod` | String | PKCE challenge và phương thức của nó. | `OauthAuthorizationCode.mjs:14-15`, `OAuth2Model.mjs:286-287` |

#### Ai ghi

| Mã | Chức năng |
| - | - |
| `OAuth2Model.mjs:274-300` (`saveAuthorizationCode`) | Chèn một mã. Không bao giờ được gọi tới, xem Ghi chú. |
| `OAuth2Model.mjs:307-312` (`revokeAuthorizationCode`) | Xóa mã sau khi dùng. Không bao giờ được gọi tới. |

#### Ai đọc

| Mã | Chức năng |
| - | - |
| `OAuth2Model.mjs:137-177` (`getAuthorizationCode`) | Tải một mã cùng người dùng và client của nó. Không bao giờ được gọi tới. |

#### Chỉ mục

| Tên | Khóa | Tùy chọn | Migration |
| - | - | - | - |
| `expiresAt_1` | `{ expiresAt: 1 }` | TTL, `expireAfterSeconds: 0`, partial: `expiresAt` tồn tại | `20230406125632_oauth_tokens_ttl.mjs` |

Các migration nằm trong `tools/migrations/`. Chỉ mục duy nhất `authorizationCode_1` chỉ đến từ các migration gắn tag `saas` và `server-pro`, mà Community Edition không chạy.

#### Ghi chú

* Các phương thức model ở trên chỉ được gọi bởi handler authorize và token của `@node-oauth/oauth2-server`. Web chỉ dùng thư viện này để kiểm tra bearer token (`services/web/app/src/Features/Authentication/AuthenticationController.mjs:409-450`), và không route nào phục vụ `/oauth/authorize` hay `/oauth/token`, nên không mã nào được ghi. Personal access token được tạo trực tiếp, xem [OAuth Access Tokens](https://ayakaleaf-pro.mintlify.site/vi/dev/data-model/oauth-access-tokens-collection.md).


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