Amazon Cognito のクライアントとオーディエンスの検証 - Amazon Verified Permissions

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon Cognito のクライアントとオーディエンスの検証

ID ソースをポリシーストアに追加すると、Verified Permissions には、ID トークンとアクセストークンが意図したとおりに使用されていることを確認する設定オプションがあります。この検証は、 IsAuthorizedWithTokenおよび BatchIsAuthorizedWithToken API リクエストの処理で行われます。この動作は、ID トークンとアクセストークン、および Amazon Cognito と OIDC ID ソースによって異なります。Amazon Cognito ユーザープールプロバイダーを使用すると、Verified Permissions は ID トークンとアクセストークンの両方でクライアント ID を検証できます。OIDC プロバイダーを使用すると、Verified Permissions は ID トークンのクライアント ID とアクセストークンの対象者を検証できます。

クライアント ID は、アプリケーションが使用する ID プロバイダーインスタンスに関連付けられた識別子です1example23456789。例: 。対象者は、 など、アクセストークンの目的の証明書利用者または送信先に関連付けられた URL パスですhttps://mytoken.example.com。アクセストークンを使用する場合、audクレームは常に対象者に関連付けられます。

Amazon Cognito ID トークンには、アプリケーションクライアント ID を含むaudクレームがあります。アクセストークンには、アプリケーションクライアント ID も含まれるclient_idクレームがあります。

ID ソースにクライアントアプリケーション検証に 1 つ以上の値を入力すると、Verified Permissions はこのアプリケーションクライアント IDs のリストを ID トークンaudクレームまたはアクセストークンclient_idクレームと比較します。Verified Permissions は、Amazon Cognito ID ソースの証明書利用者 URL を検証しません。

JWTs のクライアント側の認可

アプリケーションで JSON ウェブトークンを処理し、ポリシーストア ID ソースを使用せずにそのクレームを Verified Permissions に渡すことができます。JSON ウェブトークン (JWT) からエンティティ属性を抽出し、Verified Permissions に解析できます。

この例では、JWT.1 を使用してアプリケーションから Verified Permissions を呼び出す方法を示します。

async function authorizeUsingJwtToken(jwtToken) { const payload = await verifier.verify(jwtToken); let principalEntity = { entityType: "PhotoFlash::User", // the application needs to fill in the relevant user type entityId: payload["sub"], // the application need to use the claim that represents the user-id }; let resourceEntity = { entityType: "PhotoFlash::Photo", //the application needs to fill in the relevant resource type entityId: "jane_photo_123.jpg", // the application needs to fill in the relevant resource id }; let action = { actionType: "PhotoFlash::Action", //the application needs to fill in the relevant action id actionId: "GetPhoto", //the application needs to fill in the relevant action type }; let entities = { entityList: [], }; entities.entityList.push(...getUserEntitiesFromToken(payload)); let policyStoreId = "PSEXAMPLEabcdefg111111"; // set your own policy store id const authResult = await client .isAuthorized({ policyStoreId: policyStoreId, principal: principalEntity, resource: resourceEntity, action: action, entities, }) .promise(); return authResult; } function getUserEntitiesFromToken(payload) { let attributes = {}; let claimsNotPassedInEntities = ['aud', 'sub', 'exp', 'jti', 'iss']; Object.entries(payload).forEach(([key, value]) => { if (claimsNotPassedInEntities.includes(key)) { return; } if (Array.isArray(value)) { var attibuteItem = []; value.forEach((item) => { attibuteItem.push({ string: item, }); }); attributes[key] = { set: attibuteItem, }; } else if (typeof value === 'string') { attributes[key] = { string: value, } } else if (typeof value === 'bigint' || typeof value ==='number') { attributes[key] = { long: value, } } else if (typeof value === 'boolean') { attributes[key] = { boolean: value, } } }); let entityItem = { attributes: attributes, identifier: { entityType: "PhotoFlash::User", entityId: payload["sub"], // the application needs to use the claim that represents the user-id } }; return [entityItem]; }

¹ このコード例では、aws-jwt-verify ライブラリを使用して OIDC 互換 IdPs によって署名された JWT を検証しています。