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

# IMAP 用 OAuth 2.0

> Google Cloud と Azure でアプリケーションを登録し、認証情報を Consul に保存して、ABBYY Vantage セルフホスト型の IMAP メールインポート用に OAuth 2.0 を設定します。

既定では、Process skill で Input アクティビティを使用してメールサービスからのドキュメントインポートを設定するユーザーが利用できるのは、基本的な IMAP サーバー認証のみです。Google および Microsoft のメールサービスに対する OAuth 2.0 プロトコルによる認証を有効にするには、次の操作が必要です。

1. Google Cloud Platform および/または Azure ポータルでアプリケーションを登録します。
2. それらのアプリケーションの認証情報 (Client ID とクライアントシークレット) を生成します。
3. 生成した認証情報を Consul に渡します。

これらの手順は、Vantage のインストール前でも後でも実行できます。

<div id="registering-the-application-in-google">
  ## Google でのアプリケーション登録
</div>

アプリケーションを作成するには、Google アカウントが必要です。

<div id="creating-a-project-on-the-google-cloud-platform">
  ### Google Cloud Platform でのプロジェクトの作成
</div>

1. Google Cloud Platform の New Project ページを開きます。
2. プロジェクト名を指定し、**Create** をクリックします。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-009.png" alt="プロジェクト名の field が表示された Google Cloud Platform の New Project ページ" style={{ width:"55%" }} />

3. プロジェクトが作成されたことを知らせる通知が表示されるまで待ちます。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-010.png" alt="プロジェクトの作成完了を示す Google Cloud Platform の通知" style={{ width:"46%" }} />

<div id="setting-up-the-application">
  ### アプリケーションの設定
</div>

1. Google Cloud Console に移動し、適切なプロジェクトを選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-011.png" alt="Google Cloud Console のプロジェクト選択用ドロップダウン" style={{ width:"51%" }} />

2. 画面左側のメニューで、**APIs & Services > OAuth consent screen** を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-012.png" alt="OAuth consent screen オプションを含む Google Cloud Console の APIs & Services メニュー" style={{ width:"53%" }} />

3. **External** ユーザータイプを選択し、**Create** をクリックします。
4. アプリケーション名を指定します。**User support email** ドロップダウンリスト field で、Gmail アドレスを選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-013.png" alt="アプリ名とユーザーサポート用メールアドレスの field を含む OAuth consent screen の App information フォーム" style={{ width:"61%" }} />

5. ページ下部の **Developer contact information** セクションで開発者のメールアドレスを指定し、**Save and continue** をクリックします。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-014.png" alt="メールアドレスの field を含む Developer contact information セクション" style={{ width:"62%" }} />

6. **Add or remove scopes** をクリックします。すると、右側に **Update selected scopes** ダイアログが開きます。
7. ダイアログ下部の **Manually add scopes** field に次のテキストをコピー＆ペーストし、**Add to table** をクリックします。

```
openid https://www.googleapis.com/auth2/userinfo.email https://www.googleapis.com/auth2/userinfo.profile https://mail.google.com/
```

<Note>
  スコープは手動で選択することもできます。次のスコープを選択してください。

  * `openid`
  * `https://mail.google.com/`
  * `../auth2/userinfo.email`
  * `../auth2/userinfo.profile`
</Note>

8. **Update** をクリックします。**Update selected scopes** ダイアログが閉じ、選択したスコープが表示されます。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-015.png" alt="必要なOAuthスコープを示すUpdate selected scopesダイアログ" />

9. 画面下部の **Save and continue** をクリックします。
10. **Save and continue** をクリックして **Test users** ページの設定をスキップし、**Summary** ページに移動します。

概要ページには、設定されたアプリケーション、メールアドレス、権限に関する情報が表示されます。

<div id="creating-account-credentials">
  ### アカウントの認証情報を作成する
</div>

1. 画面左側のメニューで **認証情報** を選択します。
2. **+ 認証情報を作成** をクリックし、**OAuth client ID** を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-016.png" alt="OAuth client ID オプションが表示された認証情報作成のドロップダウンメニュー" style={{ width:"61%" }} />

3. 種類として **ウェブ アプリケーション** を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-017.png" alt="アプリケーションの種類のドロップダウンにウェブ アプリケーションが表示された OAuth client ID 作成フォーム" style={{ width:"60%" }} />

4. **承認済みのリダイレクト URI** セクションで、**+ URI を追加** を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-018.png" alt="URI を追加ボタンがある承認済みのリダイレクト URI セクション" style={{ width:"47%" }} />

5. 表示された field に、リダイレクト URI を指定します。

```
https://<Vantage host name>/connectors-tokens-callback.html
```

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-019.png" alt="Vantage の callback URL と CREATE ボタンを含む Redirect URI field" style={{ width:"60%" }} />

6. **Create** をクリックします。

表示されるポップアップダイアログには、**Client ID** と **クライアントシークレット** の値が表示されます。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-020.png" alt="Client ID とクライアントシークレットの値を示す、作成済みの OAuth クライアントのダイアログ" style={{ width:"66%" }} />

このデータは、Vantage で tokenmanagement サービス を設定するために必須です。すぐに保存することも、後で **APIs & Services > Credentials** に移動し、作成した OAuth 2.0 クライアント識別子を選択してコピーすることもできます。

<div id="publishing-and-verification">
  ### 公開と検証
</div>

アプリケーションの公開ステータスは、**APIs & Services > OAuth consent screen** セクションに表示されます。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-021.png" alt="公開ステータスが Testing で、Publish App ボタンが表示されている OAuth consent screen" style={{ width:"27%" }} />

**Testing** ステータスのアプリケーションは、テスター一覧に追加されたユーザーのみが利用できます。アプリケーションを公開すると、Google アカウントを持つすべてのユーザーが利用可能になります。

**Publish app** をクリックします。`https://mail.google.com/` スコープでは、アプリケーションが機密性の高いユーザーデータにアクセスできるため、アプリケーションの検証が必要であることを示すメッセージが表示されます。

アプリケーションを検証するには、次の情報を提出する必要があります。

* アプリケーションのプライバシーポリシーへの公式リンク
* アプリケーションを使用して Google ユーザーデータを取得する目的を示す YouTube 動画
* 機密性の高いユーザーデータへのアクセスが必要な理由の説明を含む、Google 宛てのテキスト
* Google Search Console で検証済みのすべてのドメインの完全な一覧

**Confirm** をクリックします。アプリケーションのステータスが **In Production** に変わります。

また、**Prepare for verification** ボタンも表示され、必要な検証データをすべて入力できるようになります。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-022.png" alt="ステータスが In Production で、検証の警告と Prepare for Verification ボタンが表示されている OAuth consent screen" style={{ width:"55%" }} />

<Note>
  アプリケーションが検証されるまでは、利用できるのは 100 ユーザーまでです。ユーザーカウンターは OAuth consent screen セクションの下部にあり、Project の存続期間中はリセットできません。
</Note>

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-023.png" alt="ユーザー上限 100 人中 0 人を示す OAuth ユーザー上限" style={{ width:"61%" }} />

<div id="registering-the-application-in-microsoft-azure">
  ## Microsoft Azure でのアプリケーションの登録
</div>

アプリケーションを作成するには、アプリケーション登録と編集の権限を持つ Azure Active Directory テナントが必要です。

**Portal settings | Directories + subscriptions** ページで、正しいディレクトリに切り替えることができます。

<div id="registering-the-application">
  ### アプリケーションの登録
</div>

1. **App registrations** ページに移動します。
2. **New registration** をクリックします。
3. アプリケーションの名前を指定し、サポートされているアカウントの種類を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-024.png" alt="Name field と Supported account types オプションが表示された Azure のアプリケーション登録フォーム" />

<Note>
  アプリケーションで **Multitenant** 型を選択すると、そのアプリケーションは任意の Azure AD テナントのユーザーが利用できるようになります。このようなアプリケーションは検証を受ける必要がありますが、これは Microsoft Partner Network の参加者のみが利用できます。参加者でない場合は、**Single tenant** を選択してください。これにより、アプリはご利用の Azure AD テナント内のユーザーのみが利用できるようになります。
</Note>

4. **Redirect URI** セクションで **Web** プラットフォームを選択し、リダイレクト URI を指定します。

```
https://<Vantage host name>/connectors-tokens-callback.html
```

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-025.png" alt="Web プラットフォームを選択した Azure の Redirect URI セクション" style={{ width:"77%" }} />

5. **Register** をクリックします。

<div id="setting-up-application-permissions">
  ### アプリケーションの権限を設定する
</div>

1. **API permissions** タブに移動します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-026.png" alt="API permissions メニュー オプションが強調表示された Azure ポータルのサイドバー" style={{ width:"73%" }} />

2. **Add permission** をクリックします。
3. 開いたダイアログで、**Microsoft Graph** セクションを選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-027.png" alt="Microsoft Graph オプションが強調表示された Request API permissions ダイアログ" style={{ width:"69%" }} />

4. **Delegated permissions** を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-028.png" alt="Delegated permissions オプションが選択された Microsoft Graph permissions ダイアログ" style={{ width:"73%" }} />

5. 次の権限を追加します。
   * `email`
   * `IMAP.AccessAsUser.All`
   * `offline_access`
   * `openid`
   * `profile`
6. **Add permissions** をクリックします。ダイアログが閉じ、選択した権限が表示されます。

<div id="creating-client-secrets">
  ### クライアントシークレットの作成
</div>

1. **Authentication** タブに移動します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-029.png" alt="Authentication メニュー オプションが強調表示された Azure ポータルのサイドバー" />

2. **Implicit grant and hybrid flows** セクションで、**ID tokens (used for implicit and hybrid flows)** をオンにします。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-030.png" alt="ID tokens チェック ボックスが表示された Implicit grant and hybrid flows セクション" />

3. 画面上部の **Save** をクリックします。
4. **Certificates & secrets** タブに移動し、**New client secret** をクリックします。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-031.png" alt="New client secret ボタンが表示された Certificates & secrets タブ" />

5. 開いたダイアログで、クライアントシークレットの名前と有効期限を指定します。

<Note>
  有効期限は最大 24 か月です。
</Note>

6. **Add** をクリックします。ダイアログが閉じ、新しいクライアントシークレットの情報が表示されます。

<Warning>
  **Value** は必ずコピーして保存してください。ページを閉じると、再度確認できなくなります。この値は、Vantage で tokenmanagement サービス を構成する際に必要です。
</Warning>

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-032.png" alt="シークレットの Value 列が強調表示されたクライアントシークレットの一覧" />

また、クライアント識別子も必要です。これは、**Overview** タブの **Application (client) ID** フィールドからコピーできます。識別子の値にマウスカーソルを合わせると、コピー アイコンが表示されます。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-033.png" alt="Application (client) ID field が強調表示された Azure アプリケーションの Overview" />

<div id="verifying-the-application">
  ### アプリケーションの検証
</div>

任意の Azure AD テナントのユーザーがこのアプリケーションを利用できるようにするには、検証が必要です。1 つの Azure AD テナントのアカウントのみを使用する場合は、検証は不要です。

検証を受けられるのは、Microsoft Partner Network の参加者のみです。

1. **Branding & properties** タブに移動します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-034.png" alt="Branding & properties メニュー オプションが強調表示された Azure ポータルのサイドバー" />

2. **Publisher domain** field にドメインが指定されていることを確認します。必要に応じて、**Configure a domain** をクリックしてドメインを設定します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-035.png" alt="Update domain オプション付きの Publisher domain field を示す Azure の Branding & properties ページ" style={{ width:"72%" }} />

<Note>
  ドメイン名の横に表示される警告アイコンは、指定したドメインを持つアプリケーションを検証できないことを示します。**Update domain** をクリックして、Azure Active Directory テナントに関連付けられた別の有効なドメインを指定してください。あるいは、新しいドメインを検証してください。
</Note>

3. **Publisher verification** セクションで MPN ID を指定し、**Verify and save** をクリックします。

<Note>
  MPN ID を追加するために必要な権限がない場合は、発行元の検証に必要なすべての要件が満たされていることを確認してください。
</Note>

検証が正常に完了すると、該当するアイコンが **Publisher display name** field の横に表示されます。

<div id="passing-credentials-to-consul">
  ## Consul への認証情報の設定
</div>

Vantage がすでにインストールされている場合は、Microsoft および/または Google のメールサービスの認証用に生成された認証情報を手動で入力するため、Consul を使用する必要があります。

OAuth 2.0 プロトコルに固有の機能については、TokenManagement サービスに記載されています。

<Note>
  設定を始める前に、`kubectl` コマンドラインツールがインストールされており、Kubernetes クラスターに接続されていることを確認してください。
</Note>

1. 次のコマンドを実行して、Consul の Web インターフェイスにアクセスします。

```bash theme={null}
kubectl port-forward -n abbyy-infrastructure service/consul-ui 8500:80
```

次に、`http://localhost:8500/ui/dc1/kv/secret/`に移動します。

2. 開いた **Key/Value** タブで、適切な Vantage のデプロイメントスコープを選択します。次に、**vantage** Project を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-036.png" alt="tokenmanagement が強調表示されたサービス一覧を示す Consul の vantage project" style={{ width:"65%" }} />

3. **tokenmanagement** サービスを選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-037.png" alt="oAuthClientConfiguration セクションを示す Consul の tokenmanagement service" style={{ width:"68%" }} />

4. **oAuthClientConfiguration** セクションに移動します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-038.png" alt="google と microsoft のオプションを示す Consul の oAuthClientConfiguration" style={{ width:"67%" }} />

5. ユーザーデータを指定するサービス (**google** または **microsoft**) を選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-039.png" alt="clientId キーと clientSecret キーが表示された google service を示す Consul の oAuthClientConfiguration セクション" style={{ width:"66%" }} />

6. **clientId** キーを選択します。
7. 先ほど保存した Client ID の値を入力フィールドにコピー＆ペーストし、**Save** をクリックします。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-040.png" alt="Save ボタンを含む Consul の clientId 値エディター" style={{ width:"65%" }} />

8. **clientSecret** キーについても、手順 6 と 7 を繰り返します。

必要に応じて、別のメールサービスに対して手順 5 ～ 8 を繰り返します。

9. 次のコマンドを実行して、**tokenmanagement** サービスを再起動します。

```bash theme={null}
kubectl -n abbyy-vantage rollout restart $(kubectl -n abbyy-vantage get deployments -l app.kubernetes.io/component=tokenmanagement -o name)
```

<div id="updating-client-secret">
  ## クライアントシークレットの更新
</div>

クライアントシークレットの値は、サーバー側でクライアントを識別するために使用されるもので、秘密情報に当たります。セキュリティ上の理由から、この情報は定期的に更新する必要があります。Azure Active Directory など、一部のサービスでは、この種の情報の有効期間が制限されています。

新しいクライアントシークレットを作成したら、対応する Consul キーの値も更新する必要があります。

<Warning>
  クライアントシークレットを更新すると、ユーザーは Document skill の Input アクティビティでメールサービスへの接続を一から設定し直す必要があります。そうしないと、Vantage はメールボックスに接続できず、そこからメールをインポートできません。
</Warning>

<div id="updating-the-client-secret-in-google">
  ### Google でクライアントシークレットを更新する
</div>

1. Google Cloud Console に移動し、該当するプロジェクトを選択します。
2. 左側のメニューで、**APIs & Services > Credentials** を選択します。
3. **OAuth 2.0 Client IDs** セクションで、IMAP サーバーへの接続時の認証に使用する識別子を選択します。
4. **Reset secret** をクリックします。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-041.png" alt="Reset Secret ボタンが表示された Google Cloud OAuth クライアントの詳細" style={{ width:"75%" }} />

5. ポップアップダイアログで **Reset** をクリックします。これにより、クライアントシークレットの値が更新され、以前の値が呼び出されます。
6. 認証情報を含む JSON ファイルをダウンロードします。 または、画面右側からクライアントシークレットの値をコピーします。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-042.png" alt="Download JSON ボタンとクライアントシークレット field が表示された Google Cloud OAuth クライアントの詳細" />

<div id="updating-the-client-secret-in-microsoft-azure">
  ### Microsoft Azure でのクライアントシークレットの更新
</div>

1. **App registrations** ページに移動し、IMAP サーバーでの認証に使用しているアプリケーションを選択します。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/abbyy/images/vantage/self-hosted/misc-p01-043.png" alt="Owned applications リストに Example App が表示された Azure App registrations ページ" />

2. **Certificates & secrets** タブに移動し、**New client secret** をクリックします。
3. 表示されたダイアログで、クライアントシークレットの名前と有効期限を指定します。
4. **Add** をクリックします。ダイアログが閉じ、新しいクライアントシークレットの情報が表示されます。ページを閉じると **Value** には再度アクセスできなくなるため、必ずコピーして保存しておいてください。
5. 現在のクライアントシークレットがまだ有効期限切れでない場合は、削除することで、クライアントの識別には新しいクライアントシークレットのみを使用できるようになります。

<div id="updating-the-client-secret-in-consul">
  ### Consul でクライアントシークレットを更新する
</div>

[認証情報を Consul に渡す](#passing-credentials-to-consul)に記載された手順に従ってください。ただし、手順 6 と 7 (clientId 値のコピー) は省略します。
