Kebijakan DecodeJWS

Anda sedang melihat dokumentasi Apigee Edge.
Buka Dokumentasi Apigee X.
info

Apa

Mendekode header JWS tanpa memverifikasi tanda tangan di JWS, dan menulis setiap header variabel flow. Kebijakan ini paling berguna jika digunakan bersama dengan kebijakan VerifikasiJWS, ketika nilai {i>header<i} dari dalam JWS harus diketahui sebelum memverifikasi tanda tangan JWS.

JWS dapat memiliki payload yang terlampir, seperti dalam bentuk:

header.payload.signature

Atau, JWS dapat menghilangkan payload, yang disebut payload detached, dan berformat:

header..signature

Kebijakan DecodeJWS berfungsi dengan kedua formulir karena hanya mendekode bagian header JWS. Kebijakan DecodeJWS juga berfungsi terlepas dari algoritma yang digunakan untuk menandatangani JWS.

Lihat ringkasan kebijakan JWS dan JWT untuk pengantar mendetail dan gambaran umum tentang format JWS.

Video

Tonton video singkat untuk mempelajari cara mendekode JWT. Selama video ini khusus untuk JWT, banyak konsep yang sama untuk JWS.

Contoh: Mendekode JWS

Kebijakan yang ditampilkan di bawah mendekode JWS yang ditemukan dalam variabel alur var.JWS. Ini variabel harus ada dan berisi JWS yang layak (dapat didekode). Kebijakan ini dapat memperoleh JWS dari variabel {i>flow<i} apa pun.

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

Untuk setiap header di bagian header JWS, kebijakan tersebut akan menetapkan variabel alur bernama:

jws.policy-name.header.header-name

Jika JWS memiliki payload yang terpasang, JWS akan menetapkan jws.policy-name.header.payload variabel {i>flow<i} ke payload. Untuk payload yang dilepas, payload kosong. Lihat Variabel flow untuk mengetahui daftar lengkap variabel yang ditetapkan oleh kebijakan ini.

Referensi elemen untuk Decode JWS

Referensi kebijakan menjelaskan elemen dan atribut kebijakan Dekode JWS.

Atribut yang diterapkan pada elemen tingkat atas

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

Atribut berikut umum untuk semua elemen induk kebijakan.

Atribut Deskripsi Default Kehadiran
nama Nama internal kebijakan. Karakter yang dapat Anda gunakan dalam nama dibatasi untuk: A-Z0-9._\-$ %. Namun, UI pengelolaan Edge menerapkan seperti menghapus karakter yang bukan alfanumerik secara otomatis.

Secara opsional, gunakan elemen <displayname></displayname> untuk melabeli kebijakan di editor proxy UI pengelolaan dengan bahasa natural nama.

T/A Wajib
continueOnError Tetapkan ke false untuk menampilkan error saat kebijakan gagal. Diharapkan untuk sebagian besar kebijakan.

Setel ke true agar eksekusi alur dapat dilanjutkan bahkan setelah kebijakan gagal.

salah Opsional
diaktifkan Setel ke true untuk menerapkan kebijakan.

Setel ke false untuk "matikan" kebijakan tersebut. Kebijakan ini tidak akan diterapkan bahkan jika data itu tetap terlampir pada aliran.

true Opsional
asinkron Atribut ini tidak digunakan lagi. salah Tidak digunakan lagi

&lt;DisplayName&gt;

<DisplayName>Policy Display Name</DisplayName>

Gunakan selain atribut nama untuk memberi label kebijakan di editor proxy UI pengelolaan dengan nama natural language yang berbeda.

Default Jika Anda menghapus elemen ini, nilai atribut nama kebijakan akan digunakan.
Kehadiran Opsional
Jenis String

&lt;Source&gt;

<Source>JWS-variable</Source>

Jika ada, tentukan variabel alur yang diharapkan oleh kebijakan untuk menemukan JWS melakukan dekode.

Default request.header.authorization (Lihat catatan di atas untuk mengetahui informasi penting tentang {i>default<i}).
Kehadiran Opsional
Jenis String
Nilai yang valid Nama variabel aliran Edge

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 payload, 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.

Referensi error

This section describes the fault codes and error messages that are returned and fault variables that are set by Edge 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>