OIDC 공급자를 위한 클라이언트 및 대상 검증 - Amazon Verified Permissions

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

OIDC 공급자를 위한 클라이언트 및 대상 검증

정책 스토어에 자격 증명 소스를 추가하면 Verified Permissions에는 ID 및 액세스 토큰이 의도한 대로 사용되고 있는지 확인하는 구성 옵션이 있습니다. 이 검증은 IsAuthorizedWithTokenBatchIsAuthorizedWithToken API 요청을 처리할 때 발생합니다. 동작은 ID와 액세스 토큰 간에, 그리고 Amazon Cognito와 OIDC 자격 증명 소스 간에 다릅니다. Amazon Cognito 사용자 풀 공급자를 사용하면 Verified Permissions가 ID 및 액세스 토큰 모두에서 클라이언트 ID를 검증할 수 있습니다. OIDC 공급자를 사용하면 Verified Permissions가 ID 토큰의 클라이언트 ID와 액세스 토큰의 대상을 검증할 수 있습니다.

클라이언트 ID는 애플리케이션이 사용하는 자격 증명 공급자 인스턴스와 연결된 식별자입니다. 예: 1example23456789. 대상은와 같은 액세스 토큰의 의도된 신뢰 당사자 또는 대상과 연결된 URL 경로입니다https://mytoken.example.com. 액세스 토큰을 사용할 때 aud 클레임은 항상 대상과 연결됩니다.

OIDC ID 토큰에는와 같은 클라이언트 ID가 포함된 aud 클레임이 있습니다1example23456789. IDs

OIDC 액세스 토큰에는와 같은 토큰의 대상 URL이 포함된 aud 클레임https://myapplication.example.com과와 같은 클라이언트 ID가 포함된 client_id 클레임이 있습니다1example23456789. IDs

정책 스토어를 설정할 때 정책 스토어가 토큰의 대상을 검증하는 데 사용하는 대상 검증 값을 하나 이상 입력합니다.

  • ID 토큰 - Verified Permissions는 aud 클레임의 클라이언트 ID 중 하나 이상이 대상 검증 값과 일치하는지 확인하여 클라이언트 IDs를 검증합니다.

  • 액세스 토큰 - Verified Permissions는 aud 클레임의 URL이 대상 검증 값과 일치하는지 확인하여 대상을 검증합니다. aud 클레임이 없는 경우 cid 또는 client_id 클레임을 사용하여 대상을 검증할 수 있습니다. 자격 증명 공급자에게 문의하여 올바른 대상 클레임 및 형식을 확인하세요.

JWTs 대한 클라이언트 측 권한 부여

정책 스토어 자격 증명 소스를 사용하지 않고 애플리케이션에서 JSON 웹 토큰을 처리하고 해당 클레임을 Verified Permissions에 전달할 수 있습니다. JSON 웹 토큰(JWT)에서 개체 속성을 추출하여 Verified Permissions로 구문 분석할 수 있습니다.

이 예제는 JWT를 사용하여 애플리케이션에서 Verified Permissions를 호출하는 방법을 보여줍니다.1

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 호환 IdP가 서명한 JWT를 검증합니다.