やりたいこと
設定方法
アプリケーション
- Application -> Advanced Settings -> Application Metadataに呼び出し可能なAPIを定義する。
- Key:
allowed_api_list
- Value:
事前定義したAPIのIdentifier
(複数指定したい場合は、カンマ区切りで入力する)
- Key:
Actions
-
Loginフローに
check_api
というActionを定義する。 -
以下のコードを記述する。
exports.onExecutePostLogin = async (event, api) => { // クライアントの呼び出し可能APIリストを取得する。 const api_list = event.client.metadata.allowed_api_list.split(','); // 認可リクエストに指定されたAPI(audience)がAPIリストに含まれているか確認する。 if(!api_list.includes(event.request.query['audience'])){ api.access.deny("This client not allowed"); } };
動作確認
-
正常系確認
-
認可エンドポイントへアクセスする。
GET /authorize?state=aobraoenbaoer134r493yhvahro&redirect_uri=http://localhost:3000&client_id={client_id}&response_type=code&scope=test&audience={Appication MetadataのAllowed APIリストに定義したAPI identifier} HTTP/1.1 Host: {YOUR_TENANT_ID}
※
audience
にアプリケーションメタデータのallowed_api_list
に定義したIdentifier
を設定する。 -
ログインする。(クエリに認可コードが付与され、リダイレクトURIにリダイレクトされる)
-
-
異常系確認
-
認可エンドポイントへアクセスする。
GET /authorize?state=aobraoenbaoer134r493yhvahro&redirect_uri=http://localhost:3000&client_id={client_id}&response_type=code&scope=test&audience={Appication MetadataのAllowed APIリストに定義していないAPI identifier} HTTP/1.1 Host: {YOUR_TENANT_ID}
※
audience
にアプリケーションメタデータのallowed_api_list
に定義していないIdentifier
を設定する。 -
ログインする。(クエリに
error=access_denied&error_description=This%20client%20not%20allowed
が付与され、リダイレクトURIにリダイレクトされる)
-