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

# OAuth Applications コレクション

`oauthApplications` には、web が認識している OAuth クライアントが格納されます。1 つのドキュメントが 1 つのクライアントです。Ayakaleaf Pro でここに書き込むのは web モジュール `git-bridge` だけで、web の起動時に `Overleaf Git Bridge` という名前のクライアントを 1 つ作成します。スキーマは `services/web/app/src/models/OauthApplication.mjs` です。

#### フィールド

| フィールド | 型 | 意味 | 出典 |
| - | - | - | - |
| `_id` | ObjectId | クライアントのドキュメント id。`oauthAccessTokens.oauthApplication_id` と `oauthAuthorizationCodes.oauthApplication_id` がこれを参照します。 | `OauthApplication.mjs:5` |
| `id` | String | クライアント id。ランダムな小文字と数字 64 文字です。 | `OauthApplication.mjs:7`, `services/web/modules/git-bridge/index.mjs:25` |
| `clientSecret` | String | クライアントシークレット。`v1.` とランダムな 32 文字で書き込まれます。読み取るのは `getClient` だけで、`getClient` を呼び出すものはありません（補足を参照）。 | `OauthApplication.mjs:8`, `git-bridge/index.mjs:26` |
| `grants` | Array of String | グラントタイプ。git-bridge クライアントは `['password']` です。トークンの検証時にクライアントと一緒に返されます（`services/web/modules/oauth2-server/app/src/OAuth2Model.mjs:67-72`）。 | `OauthApplication.mjs:9`, `git-bridge/index.mjs:27` |
| `name` | String | クライアント名。git-bridge モジュールと個人アクセストークンのコードは、名前 `Overleaf Git Bridge` でクライアントを探します。 | `OauthApplication.mjs:10`, `git-bridge/index.mjs:15-16,28` |
| `redirectUris` | Array of String | 許可されたリダイレクト URI。git-bridge クライアントは `[]` です。 | `OauthApplication.mjs:11`, `git-bridge/index.mjs:29` |
| `scopes` | Array of String | クライアントが使用できるスコープ。git-bridge クライアントは `['git_bridge']` です。 | `OauthApplication.mjs:12`, `git-bridge/index.mjs:30` |
| `pkceEnabled` | Boolean | スキーマにのみ存在します。このリポジトリのコードは書き込まず、使われていない `getClient` だけが読み取ります（`OAuth2Model.mjs:207`）。 | `OauthApplication.mjs:13` |

#### 書き込み元

| コード | 処理内容 |
| - | - |
| `git-bridge/index.mjs:9-35` (module `git-bridge`) | `GIT_BRIDGE_ENABLED` が `true` のとき、同じ名前のクライアントがなければ、web の起動時に `Overleaf Git Bridge` クライアントを作成します。 |

#### 読み取り元

| コード | 処理内容 |
| - | - |
| `services/web/modules/oauth2-server/app/src/OAuthPersonalAccessTokenManager.mjs:53-61` (module `oauth2-server`) | 名前で `Overleaf Git Bridge` クライアントを探し、その `_id` を新しい個人アクセストークンごとに保存します。クライアントがなければトークンは作成されません。 |
| `OAuth2Model.mjs:31-39,67-72` (`getAccessToken`) | `oauthApplication_id` を通じてトークンのクライアントを読み込み、その `id` と `grants` を返します。 |
| `OAuth2Model.mjs:185-209,241,275` (`getClient`, `saveToken`, `saveAuthorizationCode`) | `id` でクライアントを検索します。このリポジトリでは実行されません。補足を参照してください。 |

#### インデックス

デフォルトの `_id` インデックスのみです。一意インデックス `id_1` は、タグ `saas`（`20190912145016_create_oauthApplications_indexes.mjs`）と `server-pro`（`20230502180757_server_pro_oauth_indexes.mjs`）のマイグレーションからのみ作成され、Community Edition はこれらを実行しません。

#### 補足

* web は `@node-oauth/oauth2-server` を bearer トークンの検証にのみ使用します（`services/web/app/src/Features/Authentication/AuthenticationController.mjs:409-450` の `server.authenticate`）。これはモデルの `getAccessToken` と `verifyScope` しか呼び出しません。`/oauth/token` や `/oauth/authorize` を提供するルートはないため、`getClient`、`saveToken`、`saveAuthorizationCode` は呼び出されません。
* モジュールは名前でクライアントを探してから作成しますが、Community Edition には `name` にも `id` にも一意インデックスがありません。そのため、同じ名前の 2 つ目のクライアントを防ぐものはありません。クライアントを必要とするコードは、`findOne` が返したものを使います。


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