# 制限付き API キー認証

ユーザーがアプリをインストールするときに、制限付き API キー (RAK) を生成します。

Stripe Apps では、Stripe API での認証に制限付き API キー (RAK) を使用することができます。ユーザーがアプリをインストールした後、特定の権限を持つ RAK がユーザーに提供されます。

システムがこれまでユーザーによるシークレットキーの提供に依存していた場合は、代わりに RAK Stripe アプリを使用できます。RAK はシークレットキーと同じように機能するため、オーソリに使用する場合、バックエンドコードを変更する必要はありません (例外を除く)。

### RAK 認証のメリット

- アプリによって生成されるキーにはアプリが機能するために必要な権限のみ含まれているため、ユーザーはアカウントのデータをより安全に管理することが可能です。
- アプリにはすでに権限が定義されているため、インストールするユーザーが手動で権限を選択して制限付きキーに追加する必要はありません。ユーザーは、アプリをインストールしてボタンをクリックするだけでキーを生成できます。

### RAK 認証の制限事項

- RAK 認証を使用する場合は、ユーザーの操作が必要です。ユーザーはアプリでキーを生成し、パートナーまたはシステムにそれを提供する必要があります。
- アプリで RAK 認証を使用する場合、UI Extensions が正しく機能しないことがあります。[アプリの設定ページ](https://docs.stripe.com/stripe-apps/app-settings.md)では RAK 認証がサポートされていますが、UI Extensions はその他のダッシュボード機能にはアクセスできません。

## インストール

RAK 認証を使用する Stripe アプリをインストールするユーザーは、以下の手順に従ってください。

1. App Marketplace から、または[インストールリンク](https://docs.stripe.com/stripe-apps/install-links.md)を使用して、ユーザーは適切なアカウントを選択し、アプリのインストール権限を取得します。
2. ユーザーがアプリをインストールすると、Stripe はアプリの設定ページにユーザーをリダイレクトし、適切な権限がプロビジョニングされた制限付き API キーを生成します。
![RAK アプリの設定ページにある「API キーを表示」ボタン](https://b.stripecdn.com/docs-statics-srv/assets/view-app-keys-button.226d90da9686e24a146d50c7371c4a28.png)

1. ユーザーは生成されたキーをコピーして、そのキーをサイトに提供します。
![設定ページからアプリキーをコピー](https://b.stripecdn.com/docs-statics-srv/assets/copy-app-keys.89fd5ca5d68b91c105164092b4de5029.png)

## アプリを開発する

1. [Stripe Apps CLI プラグインをインストールする](https://docs.stripe.com/stripe-apps/create-app.md#install-stripe-apps-cli) (まだインストールしていない場合)。

2. テンプレートを使用してアプリを作成します。

   ```bash
   stripe apps create <app-name> --template restricted-api-key-app
   ```

   既存のアプリがある場合は、Stripe CLI でこのコマンドを実行します。

   ```bash
   stripe apps set api-access-type restricted_api_key
   ```

3. アプリに必要な[権限](https://docs.stripe.com/stripe-apps/reference/permissions.md)をすべて追加します。

4. [アプリの設定ページ](https://docs.stripe.com/stripe-apps/app-settings.md)を編集します。上記のテンプレートを使用している場合は、設定ビューが自動生成されます。ユーザーがアプリを設定するときの参考になるように、このページに手順やドキュメントへのリンクを追加することをお勧めします。
![アプリの権限を示すインストールリンクのページ](https://b.stripecdn.com/docs-statics-srv/assets/settingsview.ca0e43bcc311ea9819da61b2949e6ed1.png)
   
   アプリの設定ページの例

5. アプリを Stripe に[アップロード](https://docs.stripe.com/stripe-apps/upload-install-app.md)します。

   > RAK アプリをアップロードした後に、[API 認証方法](https://docs.stripe.com/stripe-apps/api-authentication.md)を変更することはできません。

   ```bash
   stripe apps upload
   ```

## アプリをテストする

自分のアカウントで RAK 認証をテストできます。

Install the app in a general sandbox using the path for its distribution type:

- **Private app**: Use the Stripe CLI to log in to the sandbox and upload the app. Then, in the sandbox Dashboard, go to [Created apps](https://dashboard.stripe.com/test/apps/created), select your app, open the **Versions** tab, and click **Install** or **Change version**.
- **Public app**: [Enable general sandbox support](https://docs.stripe.com/stripe-apps/enable-sandbox-support.md), upload the updated app to your live account, and [create an external test link](https://docs.stripe.com/stripe-apps/test-app.md) for that version. Open a general sandbox, then visit the external test link to install the app in that sandbox.

1. In the sandbox Dashboard, go to your [installed apps page](https://dashboard.stripe.com/settings/apps) and select the app.
2. On the app settings page, click **View API keys**. Copy this secret key to test your integration.

If you’re developing a public app, use [external testing](https://docs.stripe.com/stripe-apps/test-app.md) to test it on a different Stripe account than the one used to develop it.
