LoginSignup
2
1

More than 1 year has passed since last update.

Box カスタムアプリでサーバー認証(クライアント資格情報許可)を使う

Posted at

とりあえずサービスアカウントで実行する場合は、そのままアプリを作るだけでOK

  1. アプリの新規作成
  2. カスタムアプリ
  3. サーバー認証(クライアント資格情報許可)

Client Credentials Grant.png

クライアントシークレットを取得します。
クライアントシークレットの取得には 2要素認証を有効にする必要があるので注意。

忘れないように管理者に「承認」を依頼します。

approve.png
approve.png

承認されてないと invalid_grant になるので必須です。

{"error":"invalid_grant","error_description":"Grant credentials are invalid"}

この辺は JWT と一緒です。

以上で準備完了。

サービスアカウントとして実行する場合は下記のような感じでリクエストすると access_token が返却されるので、それを使って API を実行します。

curl --location --request POST 'https://api.box.com/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=<client_id>' \
--data-urlencode 'client_secret=<client_secret>' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'box_subject_type=enterprise' \
--data-urlencode 'box_subject_id=<enterprise_id>'

本家だと、この辺りのドキュメントに書いてあります。

Box で使えるサーバー認証だと JWT も有りますが、JSONファイル読み込んで実行するとか、ちょっと面倒だったりします。

クライアント資格情報許可を使うとクライアントIDとクライアントシークレットだけで実行できるので楽です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1