Halaman ini berlaku untuk Apigee dan Apigee hybrid.
Lihat dokumentasi
Apigee Edge.
Kebijakan DecodeJWS mendekode header JWS tanpa memverifikasi tanda tangan pada JWS, dan menulis setiap header ke flow variable. 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 Extensible policy 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.
Contoh: Mendekode JWS
Kebijakan yang ditampilkan di bawah mendekode JWS yang ditemukan dalam flow variable var.JWS. Variabel ini harus ada dan berisi JWS yang dapat digunakan (dapat didekode). Kebijakan ini dapat memperoleh JWS dari flow variable 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 flow variable jws.policy-name.header.payload
ke payload. Untuk payload yang terpisah, 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 bersifat 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 otomatis menghapus karakter yang bukan alfanumerik.
Secara opsional, gunakan elemen |
T/A | Wajib |
| continueOnError |
Setel ke false untuk menampilkan error saat kebijakan gagal. Hal ini adalah perilaku yang diharapkan untuk sebagian besar kebijakan.
Setel ke |
false | Opsional |
| diaktifkan |
Setel 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 menghilangkan elemen ini, nilai atribut nama kebijakan akan digunakan. |
| Kehadiran | Opsional |
| Jenis | String |
<Source>
<Source>JWS-variable</Source>
Jika ada, menentukan flow variable tempat kebijakan diharapkan menemukan JWS untuk didekode.
| Default | request.header.authorization (Lihat catatan di atas untuk mengetahui informasi penting
tentang setelan 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. |
Variabel error
Variabel ini ditetapkan saat error runtime terjadi. Untuk mengetahui informasi selengkapnya, lihat Yang perlu Anda ketahui tentang error kebijakan.
| Variabel | Dari mana | Contoh |
|---|---|---|
fault.name="fault_name" |
fault_name adalah nama error, seperti yang tercantum dalam tabel Runtime errors di atas. Nama error adalah bagian terakhir dari kode error. | fault.name Matches "TokenExpired" |
JWS.failed |
Semua kebijakan JWS menetapkan variabel yang sama jika terjadi kegagalan. | jws.JWS-Policy.failed = true |
Contoh respons error
Untuk penanganan error, praktik terbaiknya adalah menjebak bagian errorcode dari respons error. Jangan mengandalkan teks di faultstring, karena teks tersebut dapat berubah.
Contoh aturan error
<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>