認証

OAuth 2.0 Client Credentials Flow によるアクセストークンの取得方法。

API の呼び出しには、OAuth 2.0 Client Credentials Flow で取得したアクセストークンが必要です。

流れ

  1. トークンをリクエスト
  2. レスポンスからトークンを取得
  3. RAG 用データ API にトークンを使用してリクエスト

接続情報

項目値
トークンエンドポイントhttps://idcs-47012173cd0e43aa84f5927c17222369.ap-westtokyo-idcs-1.identity.oci.svcl.jp:443/oauth2/v1/token
grant_typeclient_credentials
scopedep-beta:rag-data-api:call
client_id個別に共有
client_secret個別に共有

client_secret は秘密情報です。ソースコード管理・チャット・メール本文などに 貼り付けないでください。

トークンをリクエスト

クライアント認証方式は client_secret_basic と client_secret_post の 2 つに 対応しています。どちらを使っても取得できるトークンは同じです。

client_secret_basic の場合

client_id と client_secret を HTTP Basic 認証で送ります。

項目値
メソッドPOST
Content-Typeapplication/x-www-form-urlencoded
AuthorizationBasic base64(client_id + ":" + client_secret)
ボディgrant_type=client_credentials&scope=dep-beta:rag-data-api:call
TOKEN_URL='https://idcs-47012173cd0e43aa84f5927c17222369.ap-westtokyo-idcs-1.identity.oci.svcl.jp:443/oauth2/v1/token'
CLIENT_ID='<client_id>'
CLIENT_SECRET='<client_secret>'

curl -sS -X POST "$TOKEN_URL" \
  -u "${CLIENT_ID}:${CLIENT_SECRET}" \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode 'scope=dep-beta:rag-data-api:call'

client_secret_post の場合

client_id と client_secret をフォームデータとしてボディに含めます。 Authorization ヘッダを扱いにくい環境向けです。

項目値
メソッドPOST
Content-Typeapplication/x-www-form-urlencoded
grant_typeclient_credentials
client_id受領したクライアント ID
client_secret受領したクライアントシークレット
scopedep-beta:rag-data-api:call
TOKEN_URL='https://idcs-47012173cd0e43aa84f5927c17222369.ap-westtokyo-idcs-1.identity.oci.svcl.jp:443/oauth2/v1/token'
CLIENT_ID='<client_id>'
CLIENT_SECRET='<client_secret>'

curl -sS -X POST "$TOKEN_URL" \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-urlencode 'grant_type=client_credentials' \
  --data-urlencode "client_id=${CLIENT_ID}" \
  --data-urlencode "client_secret=${CLIENT_SECRET}" \
  --data-urlencode 'scope=dep-beta:rag-data-api:call'

レスポンスからトークンを取得

認証に成功すると、以下のような形式のレスポンスが返り、access_token フィールドからトークンが取得できます。

{
  "access_token": "<access_token>",
  "token_type": "Bearer",
  "expires_in": 3600
}

expires_in はトークンの有効期間 (秒) です。 有効期間内は同じトークンを使い回せるため、リクエストごとに取り直さず、期限が近づいたら再取得してください。

RAG 用データ API にトークンを使用してリクエスト

取得した access_token を Authorization ヘッダに Bearer スキームで載せます。

curl -X POST "https://<api-gateway-host>/v1/rag/search" \
  -H "Authorization: Bearer ${ACCESS_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"q": "自己資本比率の推移", "l": 3}'

トークンが無効・期限切れ・スコープ不足の場合、リクエストは API サーバに到達せずゲートウェイが 401 または 403 を返します。 トークンを取り直し、ヘッダが正しく付いているか確認してください。 発生条件と対処の詳細は エラー を参照してください。

On this page