DecodeJWS 정책

이 페이지는 ApigeeApigee Hybrid에 적용됩니다.

Apigee Edge 문서를 보세요.

정책 아이콘

제목

JWS의 서명을 확인하지 않고 JWS 헤더를 디코딩하여 각 헤더를 흐름 변수에 씁니다. 이 정책은 JWS의 서명을 확인하기 전에 JWS 내의 헤더 값을 알아야 하는 경우 VerifyJWS 정책과 함께 사용할 때 가장 유용합니다.

JWS는 연결된 페이로드를 포함하여 다음과 같은 형식입니다.

header.payload.signature

또는 JWS에서 페이로드를 생략하고(분리된 페이로드) 다음과같은 형식입니다.

header..signature

DecodeJWS 정책은 JWS의 헤더 부분만 디코딩하므로 두 형식 모두에서 작동합니다. 또한 DecodeJWS 정책은 JWS 서명에 사용된 알고리즘과 관계없이 작동합니다.

JWS 형식에 대한 자세한 소개와 개요를 보려면 JWS 및 JWT 정책 개요를 참조하세요.

이 정책은 확장 가능한 정책이며, 이 정책을 사용하면 Apigee 라이선스에 따라 비용 또는 사용률이 영향을 받을 수 있습니다. 정책 유형 및 사용 영향에 대한 자세한 내용은 정책 유형을 참조하세요.

동영상

JWT를 디코딩하는 방법을 알아보려면 짧은 동영상을 시청하세요. 이 동영상은 JWT에 해당하지만 대부분의 개념은 JWS와 동일합니다.

샘플: JWS 디코딩

아래에 표시된 정책은 흐름 변수 var.JWS에 있는 JWS를 디코딩합니다. 이 변수는 존재해야 하며 실행 가능한(취소 가능한) JWS를 포함해야 합니다. 이 정책은 모든 흐름 변수에서 JWS를 가져올 수 있습니다.

<DecodeJWS name="JWS-Decode-HS256">
    <DisplayName>JWS Verify HS256</DisplayName>
    <Source>var.JWS</Source>
</DecodeJWS>

정책은 JWS의 헤더 부분에 있는 각 헤더에 대해 다음과 같은 흐름 변수를 설정합니다.

jws.policy-name.header.header-name

JWS에 연결된 페이로드가 있으면 jws.policy-name.header.payload 흐름 변수를 페이로드로 설정합니다. 분리된 페이로드의 경우 payload가 비어 있습니다. 이 정책에서 설정한 전체 변수 목록은 흐름 변수를 참조하세요.

Decode JWS에 대한 요소 참조

정책 참조는 Decode JWS 정책의 요소 및 속성을 설명합니다.

최상위 요소에 적용되는 속성

<DecodeJWS name="JWS" continueOnError="false" enabled="true" async="false">

다음 속성은 모든 정책 상위 요소에 공통적으로 적용됩니다.

속성 설명 기본 Presence
이름 정책의 내부 이름입니다. 이름에 사용할 수 있는 문자는 A-Z0-9._\-$ %로 제한됩니다. 그러나 Apigee UI는 영숫자가 아닌 문자를 자동으로 삭제하는 등 추가 제한사항을 적용합니다.

선택적으로 <displayname></displayname> 요소를 사용하여 관리 UI 프록시 편집기에서 다른 자연어 이름으로 정책에 라벨을 지정합니다.

해당 없음 필수
continueOnError 정책이 실패할 경우 오류가 반환되도록 하려면 false로 설정합니다. 이는 대부분의 정책에서 예상되는 동작입니다.

정책이 실패해도 흐름 실행이 계속되도록 하려면 true로 설정합니다.

false 선택사항
사용 설정됨 정책을 시행하려면 true로 설정합니다.

false로 설정하여 정책을 '사용 중지'합니다. 정책이 흐름에 연결되어 있어도 정책이 시행되지 않습니다.

true 선택사항
비동기 이 속성은 지원이 중단되었습니다. false 지원 중단됨

<DisplayName>

<DisplayName>Policy Display Name</DisplayName>

이름 속성 외에도 이 요소를 사용하여 관리 UI 프록시 편집기에서 다른 자연어 이름으로 정책에 라벨을 지정합니다.

기본 이 요소를 생략하면 정책 이름 속성 값이 사용됩니다.
Presence 선택사항
유형 문자열

<Source>

<Source>JWS-variable</Source>

존재하는 경우 정책에서 디코딩할 JWS를 찾고자 하는 흐름 변수를 지정합니다.

기본값 request.header.authorization (기본값에 관한 중요한 정보는 위 참고 사항을 확인하세요.)
Presence 선택사항
유형 문자열
유효한 값 Apigee 흐름 변수 이름

Flow variables

Upon success, the Verify JWS and Decode JWS policies set context variables according to this pattern:

jws.{policy_name}.{variable_name}

For example, if the policy name is verify-jws, then the policy will store the algorithm specified in the JWS to this context variable: jws.verify-jws.header.algorithm

Variable name Description
decoded.header.name The JSON-parsable value of a header in the payload. One variable is set for every header in the payload. While you can also use the header.name flow variables, this is the recommended variable to use to access a header.
header.algorithm The signing algorithm used on the JWS. For example, RS256, HS384, and so on. See (Algorithm) Header Parameter for more.
header.kid The Key ID, if added when the JWS was generated. See also "Using a JSON Web Key Set (JWKS)" at JWT and JWS policies overview to verify a JWS. See (Key ID) Header Parameter for more.
header.type The header type value. See (Type) Header Parameter for more.
header.name The value of the named header (standard or additional). One of these will be set for every additional header in the header portion of the JWS.
header-json The header in JSON format.
payload The JWS payload if the JWS has an attached payload. For a detached paylod, this variable is empty.
valid In the case of VerifyJWS, this variable will be true when the signature is verified, and the current time is before the token expiry, and after the token notBefore value, if they are present. Otherwise false.

In the case of DecodeJWS, this variable is not set.

오류 참조

This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Occurs when
steps.jws.FailedToDecode 401 The policy was unable to decode the JWS. The JWS is possibly corrupted.
steps.jws.FailedToResolveVariable 401 Occurs when the flow variable specified in the <Source> element of the policy does not exist.
steps.jws.InvalidClaim 401 For a missing claim or claim mismatch, or a missing header or header mismatch.
steps.jws.InvalidJsonFormat 401 Invalid JSON found in the JWS header.
steps.jws.InvalidJws 401 This error occurs when the JWS signature verification fails.
steps.jws.InvalidPayload 401 The JWS payload is invalid.
steps.jws.InvalidSignature 401 <DetachedContent> is omitted and the JWS has a detached content payload.
steps.jws.MissingPayload 401 The JWS payload is missing.
steps.jws.NoAlgorithmFoundInHeader 401 Occurs when the JWS omits the algorithm header.
steps.jws.UnknownException 401 An unknown exception occurred.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Occurs when
InvalidAlgorithm The only valid values are: RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, HS256, HS384, HS512.

EmptyElementForKeyConfiguration

FailedToResolveVariable

InvalidConfigurationForActionAndAlgorithmFamily

InvalidConfigurationForVerify

InvalidEmptyElement

InvalidFamiliesForAlgorithm

InvalidKeyConfiguration

InvalidNameForAdditionalClaim

InvalidNameForAdditionalHeader

InvalidPublicKeyId

InvalidPublicKeyValue

InvalidSecretInConfig

InvalidTypeForAdditionalClaim

InvalidTypeForAdditionalHeader

InvalidValueForElement

InvalidValueOfArrayAttribute

InvalidVariableNameForSecret

MissingConfigurationElement

MissingElementForKeyConfiguration

MissingNameForAdditionalClaim

MissingNameForAdditionalHeader

Other possible deployment errors.

Fault variables

These variables are set when a runtime error occurs. For more information, see What you need to know about policy errors.

Variables Where Example
fault.name="fault_name" fault_name is the name of the fault, as listed in the Runtime errors table above. The fault name is the last part of the fault code. fault.name Matches "TokenExpired"
JWS.failed All JWS policies set the same variable in the case of a failure. jws.JWS-Policy.failed = true

Example error response

For error handling, the best practice is to trap the errorcode part of the error response. Do not rely on the text in the faultstring, because it could change.

Example fault rule

<FaultRules>
    <FaultRule name="JWS Policy Errors">
        <Step>
            <Name>JavaScript-1</Name>
            <Condition>(fault.name Matches "TokenExpired")</Condition>
        </Step>
        <Condition>JWS.failed=true</Condition>
    </FaultRule>
</FaultRules>