DecodeJWT नीति

यह Apigee Edge के दस्तावेज़ हैं.
पर जाएं Apigee X दस्तावेज़.
info

क्या

यह नीति, JWT पर मौजूद हस्ताक्षर की पुष्टि किए बिना, JWT को डिकोड करती है. यह नीति, VerifyJWT नीति के साथ इस्तेमाल करने पर सबसे ज़्यादा काम की होती है. ऐसा तब होता है, जब JWT के हस्ताक्षर की पुष्टि करने से पहले, JWT में मौजूद दावे की वैल्यू पता करनी हो.

JWT पर हस्ताक्षर करने के लिए, जिस एल्गोरिदम का इस्तेमाल किया गया है उससे कोई फ़र्क़ नहीं पड़ता. JWT डिकोड करने की नीति, हर मामले में काम करती है. ज़्यादा जानकारी के लिए, JWS और JWT नीतियों की खास जानकारी देखें.

वीडियो

JWT को डिकोड करने का तरीका जानने के लिए, यह छोटा वीडियो देखें.

उदाहरण: JWT डिकोड करना

यहां दिखाई गई नीति, फ़्लो वैरिएबल var.jwt में मौजूद JWT को डिकोड करती है. यह वैरिएबल मौजूद होना चाहिए और इसमें डिकोड किया जा सकने वाला JWT होना चाहिए. यह नीति, किसी भी फ़्लो वैरिएबल से JWT हासिल कर सकती है.

<DecodeJWT name="JWT-Decode-HS256">
    <DisplayName>JWT Verify HS256</DisplayName>
    <Source>var.jwt</Source>
</DecodeJWT>

यह नीति, अपना आउटपुट कॉन्टेक्स्ट वैरिएबल में लिखती है, ताकि एपीआई प्रॉक्सी में मौजूद अगली नीतियां या शर्तें उन वैल्यू की जांच कर सकें. इस नीति से सेट किए गए वैरिएबल की सूची देखने के लिए, फ़्लो वैरिएबल देखें.

JWT डिकोड करने के लिए, एलिमेंट का रेफ़रंस

नीति के रेफ़रंस में, JWT डिकोड करने की नीति के एलिमेंट और एट्रिब्यूट के बारे में बताया गया है.

सबसे ऊपर के एलिमेंट पर लागू होने वाले एट्रिब्यूट

<DecodeJWT name="JWT" continueOnError="false" enabled="true" async="false">

ये एट्रिब्यूट, सभी नीति के पैरंट एलिमेंट में मौजूद होते हैं.

एट्रिब्यूट ब्यौरा डिफ़ॉल्ट मौजूद होना
name नीति का इंटरनल नाम. नाम में इन वर्णों का इस्तेमाल किया जा सकता है: A-Z0-9._\-$ %. हालांकि, Edge के मैनेजमेंट यूज़र इंटरफ़ेस (यूआई) में कुछ और पाबंदियां लागू होती हैं. जैसे, अल्फ़ान्यूमेरिक वर्णों के अलावा अन्य वर्णों को अपने-आप हटाना.

मैनेजमेंट यूज़र इंटरफ़ेस (यूआई) के प्रॉक्सी एडिटर में, नीति को किसी दूसरे नाम से लेबल करने के लिए, <displayname></displayname> एलिमेंट का इस्तेमाल किया जा सकता है.

लागू नहीं ज़रूरी है
continueOnError किसी नीति के काम न करने पर गड़बड़ी दिखाने के लिए, इसे false पर सेट करें. ज़्यादातर नीतियों के लिए, यह सामान्य व्यवहार है.

किसी नीति के काम न करने पर भी, फ़्लो के एक्ज़ीक्यूशन को जारी रखने के लिए, इसे true पर सेट करें.

गलत वैकल्पिक
enabled नीति को लागू करने के लिए, इसे true पर सेट करें.

नीति को "बंद" करने के लिए, इसे false पर सेट करें. अगर नीति किसी फ़्लो से जुड़ी रहती है, तब भी उसे लागू नहीं किया जाएगा.

सही वैकल्पिक
async इस एट्रिब्यूट को बंद कर दिया गया है. गलत बहिष्कृत

<DisplayName>

<DisplayName>Policy Display Name</DisplayName>

मैनेजमेंट यूज़र इंटरफ़ेस (यूआई) के प्रॉक्सी एडिटर में, नीति को किसी दूसरे नाम से लेबल करने के लिए, name एट्रिब्यूट के अलावा इसका इस्तेमाल किया जा सकता है.

डिफ़ॉल्ट अगर इस एलिमेंट को शामिल नहीं किया जाता है, तो नीति के name एट्रिब्यूट की वैल्यू का इस्तेमाल किया जाता है.
मौजूद होना वैकल्पिक
समस्या स्ट्रिंग

<Source>

<Source>jwt-variable</Source>

अगर यह एलिमेंट मौजूद है, तो यह उस फ़्लो वैरिएबल के बारे में बताता है जिसमें नीति, डिकोड करने के लिए JWT ढूंढती है

डिफ़ॉल्ट request.header.authorization (डिफ़ॉल्ट के बारे में अहम जानकारी के लिए, ऊपर दिया गया नोट देखें).
मौजूद होना वैकल्पिक
समस्या स्ट्रिंग
मान्य वैल्यू Edge के फ़्लो वैरिएबल का नाम

Flow variables

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

jwt.{policy_name}.{variable_name}

For example, if the policy name is jwt-parse-token , then the policy will store the subject specified in the JWT to the context variable named jwt.jwt-parse-token.decoded.claim.sub. (For backward compatibility, it will also be available in jwt.jwt-parse-token.claim.subject)

Variable name Description
claim.audience The JWT audience claim. This value may be a string, or an array of strings.
claim.expiry The expiration date/time, expressed in milliseconds since epoch.
claim.issuedat The Date the token was issued, expressed in milliseconds since epoch.
claim.issuer The JWT issuer claim.
claim.notbefore If the JWT includes a nbf claim, this variable will contain the value, expressed in milliseconds since epoch.
claim.subject The JWT subject claim.
claim.name The value of the named claim (standard or additional) in the payload. One of these will be set for every claim in the payload.
decoded.claim.name The JSON-parsable value of the named claim (standard or additional) in the payload. One variable is set for every claim in the payload. For example, you can use decoded.claim.iat to retrieve the issued-at time of the JWT, expressed in seconds since epoch. While you can also use the claim.name flow variables, this is the recommended variable to use to access a claim.
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.
expiry_formatted The expiration date/time, formatted as a human-readable string. Example: 2017-09-28T21:30:45.000+0000
header.algorithm The signing algorithm used on the JWT. For example, RS256, HS384, and so on. See (Algorithm) Header Parameter for more.
header.kid The Key ID, if added when the JWT was generated. See also "Using a JSON Web Key Set (JWKS)" at JWT policies overview to verify a JWT. See (Key ID) Header Parameter for more.
header.type Will be set to JWT.
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 JWT.
header-json The header in JSON format.
is_expired true or false
payload-claim-names An array of claims supported by the JWT.
payload-json
The payload in JSON format.
seconds_remaining The number of seconds before the token will expire. If the token is expired, this number will be negative.
time_remaining_formatted The time remaining before the token will expire, formatted as a human-readable string. Example: 00:59:59.926
valid In the case of VerifyJWT, 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 DecodeJWT, this variable is not set.

गड़बड़ी का रेफ़रंस

यह सेक्शन गड़बड़ी के कोड और दिखाए गए गड़बड़ी के मैसेज के बारे में बताता है. साथ ही, इस नीति के ट्रिगर होने पर Edge की मदद से सेट की गई गड़बड़ी के वैरिएबल के बारे में बताता है. यह जानकारी जानना ज़रूरी है कि क्या गड़बड़ियों को ठीक करने के लिए, गड़बड़ी से जुड़े नियम बनाए जा रहे हैं. ज़्यादा जानने के लिए, नीति से जुड़ी गड़बड़ियों के बारे में आपके लिए ज़रूरी जानकारी और गड़बड़ियों को ठीक करने के तरीके देखें.

रनटाइम से जुड़ी गड़बड़ियां

नीति के लागू होने पर ये गड़बड़ियां हो सकती हैं.

गड़बड़ी का कोड एचटीटीपी कोड स्थिति वजह समाधान
steps.jwt.FailedToDecode 401 ऐसा तब होता है, जब नीति, JWT को डिकोड नहीं कर पाती. JWT गलत हो सकता है, अमान्य हो सकता है या इसे डिकोड नहीं किया जा सकता.
steps.jwt.FailedToResolveVariable 401 ऐसा तब होता है, जब नीति के <Source> एलिमेंट में बताया गया फ़्लो वैरिएबल मौजूद न हो.
steps.jwt.InvalidToken 401 ऐसा तब होता है, जब नीति के <Source> एलिमेंट में दिया गया फ़्लो वैरिएबल दायरे से बाहर हो या उसे हल नहीं किया जा सकता हो.

डिप्लॉयमेंट से जुड़ी गड़बड़ियां

ये गड़बड़ियां तब हो सकती हैं, जब इस नीति वाले किसी प्रॉक्सी को डिप्लॉय किया जाता है.

गड़बड़ी का नाम वजह समाधान
InvalidEmptyElement ऐसा तब होता है, जब डिकोड किए जाने वाले JWT वाले फ़्लो वैरिएबल को नीति के <Source> एलिमेंट में न बताया गया हो.

गड़बड़ी के वैरिएबल

रनटाइम की गड़बड़ी होने पर ये वैरिएबल सेट किए जाते हैं. ज़्यादा जानकारी के लिए, आपके लिए ज़रूरी जानकारी देखें नीति से जुड़ी गड़बड़ियों के बारे में जानकारी.

वैरिएबल कहां उदाहरण
fault.name="fault_name" fault_name गड़बड़ी का नाम है, जैसा कि ऊपर रनटाइम में गड़बड़ियां टेबल में बताया गया है. गड़बड़ी का नाम, गड़बड़ी के कोड का आखिरी हिस्सा होता है. fault.name Matches "TokenExpired"
JWT.failed कोई गड़बड़ी होने पर, JWT की सभी नीतियां एक ही वैरिएबल सेट करती हैं. JWT.failed = true

गड़बड़ी के रिस्पॉन्स का उदाहरण

JWT नीति फ़ॉल्ट कोड

गड़बड़ी ठीक करने के लिए, सबसे सही तरीका यह है कि गड़बड़ी के errorcode वाले हिस्से को छिपाया जाए जवाब. faultstring में मौजूद टेक्स्ट पर पूरी तरह भरोसा न करें, क्योंकि इससे बदलाव हो सकता है.

गड़बड़ी के नियम का उदाहरण

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