شما در حال مشاهده اسناد Apigee Edge هستید.
به مستندات Apigee X بروید . اطلاعات

چی
هدر JWS را بدون تایید امضای JWS رمزگشایی می کند و هر هدر را روی یک متغیر جریان می نویسد. این خطمشی زمانی بیشترین کاربرد را دارد که در هماهنگی با خطمشی VerifyJWS استفاده میشود، زمانی که مقدار یک هدر از داخل JWS باید قبل از تأیید امضای JWS شناخته شود.
یک JWS میتواند یک محموله متصل داشته باشد، مانند شکل:
header.payload.signature
یا، JWS میتواند محمولهای را که به آن پیبار جدا شده میگویند، حذف کند و به شکل زیر باشد:
header..signature
خط مشی DecodeJWS با هر دو شکل کار می کند زیرا فقط قسمت هدر JWS را رمزگشایی می کند. خط مشی DecodeJWS نیز بدون توجه به الگوریتمی که برای امضای JWS استفاده شده است، کار می کند.
برای معرفی دقیق و مروری بر فرمت یک JWS به نمای کلی سیاست های JWS و JWT مراجعه کنید.
ویدئو
برای یادگیری نحوه رمزگشایی JWT یک ویدیوی کوتاه را تماشا کنید. در حالی که این ویدیو مختص یک JWT است، بسیاری از مفاهیم برای JWS یکسان است.
نمونه: رمزگشایی یک JWS
خط مشی نشان داده شده در زیر یک JWS موجود در متغیر جریان var.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 دارای یک payload متصل باشد، jws. policy-name .header.payload
متغیر جریان jws. policy-name .header.payload
به payload. برای یک محموله جدا، payload
خالی است. برای فهرست کاملی از متغیرهای تنظیم شده توسط این خط مشی ، متغیرهای جریان را ببینید.
مرجع عنصر برای رمزگشایی JWS
مرجع خط مشی عناصر و ویژگی های خط مشی Decode JWS را توصیف می کند.
ویژگی هایی که برای عنصر سطح بالا اعمال می شود
<DecodeJWS name="JWS" continueOnError="false" enabled="true" async="false">
ویژگی های زیر برای همه عناصر اصلی خط مشی مشترک است.
صفت | توضیحات | پیش فرض | حضور |
---|---|---|---|
نام | نام داخلی سیاست. نویسه هایی که می توانید در نام استفاده کنید محدود به: A-Z0-9._\-$ % . با این حال، رابط کاربری مدیریت Edge محدودیتهای بیشتری را اعمال میکند، مانند حذف خودکار کاراکترهایی که حروف عددی نیستند. به صورت اختیاری، از عنصر | N/A | مورد نیاز |
continueOnError | برای بازگرداندن خطا در صورت شکست خط مشی، روی false تنظیم کنید. این رفتار مورد انتظار برای اکثر سیاست ها است. روی | نادرست | اختیاری |
فعال شد | برای اجرای خط مشی روی true تنظیم کنید. برای "خاموش کردن" خط مشی، روی | درست است | اختیاری |
ناهمگام | این ویژگی منسوخ شده است. | نادرست | منسوخ شده است |
<DisplayName>
<DisplayName>Policy Display Name</DisplayName>
علاوه بر ویژگی نام، برای برچسبگذاری خطمشی در ویرایشگر پروکسی رابط کاربری مدیریت با نامی متفاوت و به زبان طبیعی، از آن استفاده کنید.
پیش فرض | اگر این عنصر را حذف کنید، از مقدار ویژگی نام خط مشی استفاده می شود. |
حضور | اختیاری |
تایپ کنید | رشته |
<منبع>
<Source>JWS-variable</Source>
در صورت وجود، متغیر جریانی را مشخص می کند که در آن خط مشی انتظار دارد JWS را برای رمزگشایی پیدا کند.
پیش فرض | request.header.authorization (برای اطلاعات مهم در مورد پیش فرض به یادداشت بالا مراجعه کنید). |
حضور | اختیاری |
تایپ کنید | رشته |
مقادیر معتبر | نام متغیر جریان لبه |
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. |
مرجع خطا
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. |
|
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>