> ## 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 Applications

`oauthApplications` lưu các client OAuth mà web biết. Mỗi document là một client. Trong Ayakaleaf Pro, chỉ có module web `git-bridge` ghi vào đây: nó tạo một client tên `Overleaf Git Bridge` khi web khởi động. Schema nằm ở `services/web/app/src/models/OauthApplication.mjs`.

#### Các trường

| Trường | Kiểu | Ý nghĩa | Nguồn |
| - | - | - | - |
| `_id` | ObjectId | Id của document client. `oauthAccessTokens.oauthApplication_id` và `oauthAuthorizationCodes.oauthApplication_id` trỏ tới nó. | `OauthApplication.mjs:5` |
| `id` | String | Id client: 64 chữ thường và chữ số ngẫu nhiên. | `OauthApplication.mjs:7`, `services/web/modules/git-bridge/index.mjs:25` |
| `clientSecret` | String | Secret của client, ghi dưới dạng `v1.` cộng 32 ký tự ngẫu nhiên. Chỉ `getClient` đọc nó, và không có gì gọi `getClient` (xem Ghi chú). | `OauthApplication.mjs:8`, `git-bridge/index.mjs:26` |
| `grants` | Array of String | Các loại grant. Client git-bridge có `['password']`. Được trả về cùng client khi kiểm tra token (`services/web/modules/oauth2-server/app/src/OAuth2Model.mjs:67-72`). | `OauthApplication.mjs:9`, `git-bridge/index.mjs:27` |
| `name` | String | Tên client. Module git-bridge và mã personal access token tìm client theo tên `Overleaf Git Bridge`. | `OauthApplication.mjs:10`, `git-bridge/index.mjs:15-16,28` |
| `redirectUris` | Array of String | Các URI chuyển hướng được phép. `[]` với client git-bridge. | `OauthApplication.mjs:11`, `git-bridge/index.mjs:29` |
| `scopes` | Array of String | Các scope client được dùng. `['git_bridge']` với client git-bridge. | `OauthApplication.mjs:12`, `git-bridge/index.mjs:30` |
| `pkceEnabled` | Boolean | Chỉ có trong schema: không có mã nào trong repo này ghi nó, và chỉ `getClient` (không được dùng) đọc nó (`OAuth2Model.mjs:207`). | `OauthApplication.mjs:13` |

#### Ai ghi

| Mã | Chức năng |
| - | - |
| `git-bridge/index.mjs:9-35` (module `git-bridge`) | Khi `GIT_BRIDGE_ENABLED` là `true`, tạo client `Overleaf Git Bridge` lúc web khởi động nếu chưa có client nào mang tên đó. |

#### Ai đọc

| Mã | Chức năng |
| - | - |
| `services/web/modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager.mjs:53-61` (module `oauth2-server`) | Tìm client `Overleaf Git Bridge` theo tên và lưu `_id` của nó vào mỗi personal access token mới. Không có client thì không tạo được token. |
| `OAuth2Model.mjs:31-39,67-72` (`getAccessToken`) | Tải client của một token qua `oauthApplication_id` và trả về `id` cùng `grants` của nó. |
| `OAuth2Model.mjs:185-209,241,275` (`getClient`, `saveToken`, `saveAuthorizationCode`) | Tra cứu client theo `id`. Không bao giờ được gọi tới trong repo này, xem Ghi chú. |

#### Chỉ mục

Chỉ có chỉ mục mặc định trên `_id`. Chỉ mục duy nhất `id_1` chỉ đến từ các migration gắn tag `saas` (`20190912145016_create_oauthApplications_indexes.mjs`) và `server-pro` (`20230502180757_server_pro_oauth_indexes.mjs`), mà Community Edition không chạy.

#### Ghi chú

* Web chỉ dùng `@node-oauth/oauth2-server` để kiểm tra bearer token (`server.authenticate` trong `services/web/app/src/Features/Authentication/AuthenticationController.mjs:409-450`), vốn chỉ gọi `getAccessToken` và `verifyScope` của model. Không route nào phục vụ `/oauth/token` hay `/oauth/authorize`, nên `getClient`, `saveToken` và `saveAuthorizationCode` không bao giờ được gọi.
* Module tìm client theo tên rồi mới tạo, và Community Edition không có chỉ mục duy nhất trên `name` hay `id`. Vì vậy không có gì ngăn một client thứ hai trùng tên. Mã cần client sẽ lấy client mà `findOne` trả về.


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