Halaman ini berlaku untuk Apigee dan Apigee Hybrid.
Lihat dokumentasi
Apigee Edge.
Apa
Mendekode header JWS tanpa memverifikasi tanda tangan pada JWS, dan menulis setiap header ke variabel alur. Kebijakan ini paling berguna jika digunakan bersama dengan kebijakan VerifyJWS, saat nilai header dari dalam JWS harus diketahui sebelum memverifikasi tanda tangan JWS.
JWS dapat memiliki payload terlampir, seperti dalam bentuk:
header.payload.signature
Atau, JWS dapat menghilangkan payload, yang disebut payload terpisah, dan berbentuk:
header..signature
Kebijakan DecodeJWS berfungsi dengan kedua bentuk tersebut 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 ringkasan format JWS.
Kebijakan ini adalah Kebijakan yang dapat diperluas dan penggunaan kebijakan ini mungkin memiliki implikasi biaya atau penggunaan, bergantung pada lisensi Apigee Anda. Untuk mengetahui informasi tentang jenis kebijakan dan implikasi penggunaannya, lihat Jenis kebijakan.
Video
Tonton video singkat untuk mempelajari cara mendekode JWT. Meskipun video ini khusus untuk JWT, banyak konsepnya sama untuk JWS.
Contoh: Mendekode JWS
Kebijakan yang ditampilkan di bawah mendekode JWS yang ditemukan dalam variabel alur var.JWS. Variabel ini harus ada dan berisi JWS yang layak (dapat didekode). Kebijakan dapat memperoleh JWS dari variabel alur 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 menetapkan variabel alur bernama:
jws.policy-name.header.header-name
Jika JWS memiliki payload terlampir, maka JWS akan menetapkan variabel alur jws.policy-name.header.payload
ke payload. Untuk payload yang terlepas, payload
kosong.
Lihat Variabel alur untuk mengetahui daftar lengkap variabel yang ditetapkan oleh kebijakan ini.
Referensi elemen untuk Decode JWS
Referensi kebijakan menjelaskan elemen dan atribut kebijakan Decode JWS.
Atribut yang diterapkan ke elemen tingkat teratas
<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 Apigee menerapkan batasan tambahan, seperti menghapus karakter yang bukan alfanumerik secara otomatis.
Secara opsional, gunakan elemen |
T/A | Wajib |
continueOnError |
Disetel ke false untuk menampilkan error saat kebijakan gagal. Hal ini adalah perilaku yang diharapkan untuk sebagian besar kebijakan.
Setel ke |
false | Opsional |
diaktifkan |
Tetapkan ke true untuk menerapkan kebijakan.
Setel ke |
true | Opsional |
asinkron | Atribut ini tidak digunakan lagi. | false | Tidak digunakan lagi |
<DisplayName>
<DisplayName>Policy Display Name</DisplayName>
Gunakan selain atribut nama untuk memberi label kebijakan di editor proxy UI pengelolaan dengan nama bahasa alami yang berbeda.
Default | Jika Anda menghapus elemen ini, nilai atribut nama kebijakan akan digunakan. |
Kehadiran | Opsional |
Jenis | String |
<Source>
<Source>JWS-variable</Source>
Jika ada, menentukan variabel alur tempat kebijakan mengharapkan untuk menemukan JWS yang akan didekode.
Default | request.header.authorization (Lihat catatan di atas untuk mengetahui informasi penting
tentang default). |
Kehadiran | Opsional |
Jenis | String |
Nilai yang valid | Nama variabel alur 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. |
Referensi error
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 . |
|
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>