VerificationAPIKey की नीति

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

क्या

'एपीआई पासकोड की पुष्टि करें' नीति की मदद से, रनटाइम के दौरान एपीआई पासकोड की पुष्टि की जा सकती है. इससे, सिर्फ़ ऐसे ऐप्लिकेशन आपके एपीआई ऐक्सेस कर पाएंगे जिनके पास पुष्टि किए गए एपीआई पासकोड हैं. इस नीति से यह पक्का होता है कि एपीआई पासकोड मान्य हों, उन्हें रद्द न किया गया हो, और आपके एपीआई प्रॉडक्ट से जुड़े खास संसाधनों को इस्तेमाल करने की अनुमति मिली हो.

सैंपल

<VerifyAPIKey name="APIKeyVerifier">
    <APIKey ref="request.queryparam.apikey" />
</VerifyAPIKey>

इस उदाहरण में, नीति को request.queryparam.apikey नाम के फ़्लो वैरिएबल में एपीआई पासकोड मिलना चाहिए. वैरिएबल request.queryparam.{name} एक स्टैंडर्ड Edge फ़्लो वैरिएबल है. इसे क्लाइंट अनुरोध में पास की गई क्वेरी पैरामीटर की वैल्यू से पॉप्युलेट किया जाता है.

यहां दिया गया curl कमांड, क्वेरी पैरामीटर में एपीआई पासकोड पास करता है:

curl http://myorg-test.apigee.net/mocktarget?apikey=IEYRtW2cb7A5Gs54A1wKElECBL65GVls
<VerifyAPIKey name="APIKeyVerifier">
    <APIKey ref="request.header.x-apikey" />
</VerifyAPIKey>

इस उदाहरण में, नीति को request.header.x-apikey नाम के फ़्लो वैरिएबल में एपीआई पासकोड मिलना चाहिए. वैरिएबल request.header.{name} एक स्टैंडर्ड Edge फ़्लो वैरिएबल है. इसे क्लाइंट अनुरोध में पास किए गए हेडर की वैल्यू से पॉप्युलेट किया जाता है.

यहां दिए गए cURL में, हेडर में एपीआई पासकोड पास करने का तरीका बताया गया है:

curl "http://myorg-test.apigee.net/mocktarget" -H "x-apikey:IEYRtW2cb7A5Gs54A1wKElECBL65GVls"
<VerifyAPIKey name="APIKeyVerifier">
    <APIKey ref="requestAPIKey.key"/>
</VerifyAPIKey>

नीति में, उस वैरिएबल का रेफ़रंस दिया जा सकता है जिसमें कुंजी शामिल हो. इस उदाहरण में दी गई नीति, requestAPIKey.key नाम के वैरिएबल से एपीआई पासकोड निकालती है.

उस वैरिएबल को पॉप्युलेट करने का तरीका आपके हिसाब से तय किया जा सकता है. उदाहरण के लिए, myKey नाम के क्वेरी पैरामीटर से requestAPIKey.key को पॉप्युलेट करने के लिए, वैरिएबल निकालने की नीति का इस्तेमाल किया जा सकता है. इसके लिए, यहां दिया गया तरीका अपनाएं:

<ExtractVariables async="false" continueOnError="false" enabled="true" name="SetAPIKeyVar">
    <Source>request</Source>
    <QueryParam name="myKey">
        <Pattern ignoreCase="true">{key}</Pattern>
    </QueryParam>
    <VariablePrefix>requestAPIKey</VariablePrefix>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</ExtractVariables>
<AssignMessage async="false" continueOnError="false" enabled="true" name="accessverifyvars">
    <AssignVariable>
        <Name>devFirstName</Name>
        <Ref>verifyapikey.verify-api-key.developer.firstName</Ref>
        <Value>ErrorOnCopy</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>devLastName</Name>
        <Ref>verifyapikey.verify-api-key.developer.lastName</Ref>
        <Value>ErrorOnCopy</Value>
    </AssignVariable>
    <AssignVariable>
        <Name>devEmail</Name>
        <Ref>verifyapikey.verify-api-key.developer.email</Ref>
        <Value>ErrorOnCopy</Value>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

मान्य एपीआई पासकोड के लिए, एपीआई पासकोड की पुष्टि करने की नीति को लागू करते समय, Edge अपने-आप फ़्लो वैरिएबल का एक सेट भर देता है. इन वैरिएबल का इस्तेमाल, ऐप्लिकेशन का नाम, ऐप्लिकेशन आईडी, और ऐप्लिकेशन को रजिस्टर करने वाले डेवलपर या कंपनी की जानकारी जैसी जानकारी को ऐक्सेस करने के लिए किया जा सकता है. ऊपर दिए गए उदाहरण में, 'एपीआई पासकोड की पुष्टि करें' सुविधा के लागू होने के बाद, डेवलपर का नाम, सरनेम, और ईमेल पता ऐक्सेस करने के लिए, 'मैसेज असाइन करें' नीति का इस्तेमाल किया गया है.

इन सभी वैरिएबल के आगे यह प्रीफ़िक्स होता है:

verifyapikey.{policy_name}

इस उदाहरण में, एपीआई पासकोड की पुष्टि करने की नीति का नाम "verify-api-key" है. इसलिए, वैरिएबल verifyapikey.verify-api-key.developer.firstName. को ऐक्सेस करके, अनुरोध करने वाले डेवलपर के नाम का रेफ़रंस दिया जाता है


एपीआई पासकोड की पुष्टि करने की नीति के बारे में जानकारी

जब कोई डेवलपर Edge पर ऐप्लिकेशन रजिस्टर करता है, तो Edge अपने-आप एक उपभोक्ता कुंजी और गुप्त कुंजी का जोड़ा जनरेट करता है. Edge के यूज़र इंटरफ़ेस (यूआई) में, ऐप्लिकेशन के उपभोक्ता पासकोड और सीक्रेट पासकोड को देखा जा सकता है. इसके अलावा, इन्हें Edge एपीआई से भी ऐक्सेस किया जा सकता है.

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

एपीआई कुंजियों का इस्तेमाल, पुष्टि करने वाले टोकन के तौर पर किया जा सकता है. इसके अलावा, इनका इस्तेमाल OAuth ऐक्सेस टोकन पाने के लिए भी किया जा सकता है. OAuth में, एपीआई पासकोड को "क्लाइंट आईडी" कहा जाता है. इन दोनों नामों का इस्तेमाल एक-दूसरे की जगह पर किया जा सकता है. ज़्यादा जानकारी के लिए, OAuth होम देखें.

एपीआई पासकोड की पुष्टि करने की नीति लागू करते समय, Edge फ़्लो वैरिएबल का एक सेट अपने-आप भर देता है. ज़्यादा जानकारी के लिए, नीचे फ़्लो के वैरिएबल देखें.

एलिमेंट का रेफ़रंस

इस नीति के लिए, इन एलिमेंट और एट्रिब्यूट को कॉन्फ़िगर किया जा सकता है:

<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="Verify-API-Key-1">
    <DisplayName>Custom label used in UI</DisplayName>
    <APIKey ref="variable_containing_api_key"/>
</VerifyAPIKey>

<VerifyAPIKey> एट्रिब्यूट

यहां दिए गए उदाहरण में, <VerifyAPIKey> टैग के एट्रिब्यूट दिखाए गए हैं:

<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="Verify-API-Key-1">

The following table describes attributes that are common to all policy parent elements:

Attribute Description Default Presence
name

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

N/A Required
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails.

false Optional
enabled

Set to true to enforce the policy.

Set to false to turn off the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional
async

This attribute is deprecated.

false Deprecated

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-language name.

<DisplayName>Policy Display Name</DisplayName>
Default

N/A

If you omit this element, the value of the policy's name attribute is used.

Presence Optional
Type String

<APIKey> एलिमेंट

यह एलिमेंट, उस फ़्लो वैरिएबल की जानकारी देता है जिसमें एपीआई पासकोड शामिल होता है. आम तौर पर, क्लाइंट एपीआई कुंजी को क्वेरी पैरामीटर, एचटीटीपी हेडर या फ़ॉर्म पैरामीटर में भेजता है. उदाहरण के लिए, अगर कुंजी को x-apikey नाम वाले हेडर में भेजा जाता है, तो कुंजी वैरिएबल में मिलेगी: request.header.x-apikey

डिफ़ॉल्ट NA
मौजूदगी ज़रूरी है
टाइप स्ट्रिंग

विशेषताएं

नीचे दी गई टेबल में, <APIKey> एलिमेंट के एट्रिब्यूट के बारे में बताया गया है

एट्रिब्यूट ब्यौरा डिफ़ॉल्ट मौजूदगी
ref

उस वैरिएबल का रेफ़रंस जिसमें एपीआई पासकोड शामिल है. हर नीति के लिए, सिर्फ़ एक जगह की जानकारी दी जा सकती है.

लागू नहीं ज़रूरी है

उदाहरण

इन उदाहरणों में, पासकोड को पैरामीटर और x-apikey नाम के हेडर में पास किया गया है.

क्वेरी पैरामीटर के तौर पर:

<VerifyAPIKey name="APIKeyVerifier">
    <APIKey ref="request.queryparam.x-apikey"/>
</VerifyAPIKey>

एचटीटीपी हेडर के तौर पर:

<VerifyAPIKey name="APIKeyVerifier">
    <APIKey ref="request.header.x-apikey"/>
</VerifyAPIKey>

एचटीटीपी फ़ॉर्म पैरामीटर के तौर पर:

<VerifyAPIKey name="APIKeyVerifier">
    <APIKey ref="request.formparam.x-apikey"/>
</VerifyAPIKey>

स्कीमा

फ़्लो वैरिएबल

जब किसी मान्य एपीआई पासकोड पर, एपीआई पासकोड की पुष्टि करने की नीति लागू की जाती है, तो Edge फ़्लो के वैरिएबल का एक सेट भरता है. ये वैरिएबल, फ़्लो में बाद में लागू की जाने वाली नीतियों या कोड के लिए उपलब्ध होते हैं. साथ ही, इनका इस्तेमाल अक्सर एपीआई पासकोड के एट्रिब्यूट के आधार पर कस्टम प्रोसेसिंग करने के लिए किया जाता है. जैसे, ऐप्लिकेशन का नाम, पासकोड को अनुमति देने के लिए इस्तेमाल किया गया एपीआई प्रॉडक्ट या एपीआई पासकोड के कस्टम एट्रिब्यूट.

नीति, कई तरह के फ़्लो वैरिएबल को पॉप्युलेट करती है. इनमें ये शामिल हैं:

  • सामान्य
  • ऐप्लिकेशन
  • डेवलपर
  • कंपनी
  • Analytics

हर तरह के फ़्लो वैरिएबल का प्रीफ़िक्स अलग होता है. सभी वैरिएबल स्केलर होते हैं. हालांकि, उन वैरिएबल को छोड़कर जिन्हें खास तौर पर ऐरे के तौर पर दिखाया गया है.

सामान्य फ़्लो वैरिएबल

यहां दी गई टेबल में, एपीआई पासकोड की पुष्टि करने की नीति से पॉप्युलेट होने वाले सामान्य फ़्लो वैरिएबल की सूची दी गई है. इन सभी वैरिएबल के आगे यह प्रीफ़िक्स होता है:

verifyapikey.{policy_name}

उदाहरण के लिए: verifyapikey.{policy_name}.client_id

उपलब्ध वैरिएबल में ये शामिल हैं:

वैरिएबल ब्यौरा
client_id अनुरोध करने वाले ऐप्लिकेशन से मिली उपयोगकर्ता कुंजी (जिसे एपीआई पासकोड या ऐप्लिकेशन पासकोड भी कहा जाता है).
client_secret उपभोक्ता कुंजी से जुड़ा उपभोक्ता पासवर्ड.
redirection_uris अनुरोध में मौजूद कोई भी रीडायरेक्ट यूआरआई.
developer.app.id

अनुरोध करने वाले डेवलपर ऐप्लिकेशन का आईडी.

developer.app.name अनुरोध करने वाले डेवलपर ऐप्लिकेशन का नाम.
developer.id

अनुरोध करने वाले ऐप्लिकेशन के मालिक के तौर पर रजिस्टर किए गए डेवलपर का आईडी.

developer.{custom_attrib_name} ऐप्लिकेशन की मुख्य प्रोफ़ाइल से मिले कस्टम एट्रिब्यूट
DisplayName नीति के <DisplayName> एट्रिब्यूट की वैल्यू.
failed एपीआई पासकोड की पुष्टि न होने पर, इसे "सही" पर सेट करें.
{custom_app_attrib}

ऐप्लिकेशन प्रोफ़ाइल से मिला कोई भी कस्टम एट्रिब्यूट. कस्टम एट्रिब्यूट का नाम बताएं.

apiproduct.name* अनुरोध की पुष्टि करने के लिए इस्तेमाल किए गए एपीआई प्रॉडक्ट का नाम.
apiproduct.{custom_attrib_name}* एपीआई प्रॉडक्ट प्रोफ़ाइल से मिला कोई कस्टम एट्रिब्यूट.
apiproduct.developer.quota.limit* एपीआई प्रॉडक्ट पर सेट की गई कोटा सीमा, अगर कोई हो.
apiproduct.developer.quota.interval* अगर एपीआई प्रॉडक्ट पर कोटा इंटरवल सेट किया गया है, तो वह.
apiproduct.developer.quota.timeunit* अगर एपीआई प्रॉडक्ट पर कोटा की समयावधि सेट की गई है, तो वह समयावधि.
* अगर एपीआई प्रॉडक्ट को मान्य एनवायरमेंट, प्रॉक्सी, और संसाधनों (proxy.pathsuffix से मिले) के साथ कॉन्फ़िगर किया गया है, तो एपीआई प्रॉडक्ट वैरिएबल अपने-आप पॉप्युलेट हो जाते हैं. एपीआई प्रॉडक्ट सेट अप करने के निर्देशों के लिए, एपीआई पब्लिश करने के लिए Edge मैनेजमेंट एपीआई का इस्तेमाल करना लेख पढ़ें.

ऐप्लिकेशन फ़्लो के वैरिएबल

ऐप्लिकेशन की जानकारी वाले इन फ़्लो वैरिएबल को नीति से पॉप्युलेट किया जाता है. इन सभी वैरिएबल के आगे यह प्रीफ़िक्स होता है:

verifyapikey.{policy_name}.app.

उदाहरण के लिए:

verifyapikey.{policy_name}.app.name

उपलब्ध वैरिएबल में ये शामिल हैं:

वैरिएबल ब्यौरा
name ऐप्लिकेशन का नाम.
id ऐप्लिकेशन का आईडी.
accessType Apigee इसका इस्तेमाल नहीं करता.
callbackUrl ऐप्लिकेशन का कॉलबैक यूआरएल. आम तौर पर, इसका इस्तेमाल सिर्फ़ OAuth के लिए किया जाता है.
DisplayName ऐप्लिकेशन का डिसप्ले नेम.
status ऐप्लिकेशन का स्टेटस, जैसे कि 'मंज़ूरी दी गई' या 'रद्द कर दिया गया'.
apiproducts ऐप्लिकेशन से जुड़े एपीआई प्रॉडक्ट की सूची वाला कलेक्शन.
appFamily ऐप्लिकेशन या "डिफ़ॉल्ट" वाली कोई भी ऐप्लिकेशन फ़ैमिली.
appParentStatus ऐप्लिकेशन के पैरंट का स्टेटस, जैसे कि 'चालू है' या 'बंद है'
appType ऐप्लिकेशन का टाइप, "कंपनी" या "डेवलपर".
appParentId पैरंट ऐप्लिकेशन का आईडी.
created_at ऐप्लिकेशन बनाने की तारीख/समय का टाइमस्टैंप.
created_by ऐप्लिकेशन बनाने वाले डेवलपर का ईमेल पता.
last_modified_at ऐप्लिकेशन को आखिरी बार अपडेट किए जाने की तारीख/समय का टाइमस्टैंप.
last_modified_by उस डेवलपर का ईमेल पता जिसने ऐप्लिकेशन को आखिरी बार अपडेट किया था.
{app_custom_attributes} कोई भी कस्टम ऐप्लिकेशन एट्रिब्यूट. कस्टम एट्रिब्यूट का नाम बताएं.

डेवलपर फ़्लो वैरिएबल

डेवलपर की जानकारी वाले इन फ़्लो वैरिएबल को नीति से पॉप्युलेट किया जाता है. इन सभी वैरिएबल के आगे ये प्रीफ़िक्स होते हैं:

verifyapikey.{policy_name}.developer

उदाहरण के लिए:

verifyapikey.{policy_name}.developer.id

उपलब्ध वैरिएबल में ये शामिल हैं:

वैरिएबल ब्यौरा
id {org_name}@@@{developer_id} दिखाता है
userName डेवलपर का उपयोगकर्ता नाम.
firstName डेवलपर का नाम.
lastName डेवलपर का उपनाम.
email डेवलपर का ईमेल पता.
status डेवलपर का स्टेटस, जैसे कि चालू, बंद या login_lock.
apps डेवलपर से जुड़े ऐप्लिकेशन की सूची.
created_at डेवलपर खाता बनाने की तारीख/समय का टाइमस्टैंप.
created_by उस उपयोगकर्ता का ईमेल पता जिसने डेवलपर खाता बनाया है.
last_modified_at डेवलपर में आखिरी बार बदलाव करने की तारीख/टाइमस्टैंप.
last_modified_by डेवलपर की जानकारी में बदलाव करने वाले उपयोगकर्ता का ईमेल पता.
{developer_custom_attributes} कोई भी कस्टम डेवलपर एट्रिब्यूट. कस्टम एट्रिब्यूट का नाम बताएं.
Company डेवलपर से जुड़ी कंपनी का नाम, अगर कोई है.

कंपनी फ़्लो वैरिएबल

कंपनी की जानकारी वाले इन फ़्लो वैरिएबल को नीति से पॉप्युलेट किया जाता है. इन सभी वैरिएबल के आगे ये प्रीफ़िक्स होते हैं:

verifyapikey.{policy_name}.company

उदाहरण के लिए:

verifyapikey.{policy_name}.company.name

उपलब्ध वैरिएबल में ये शामिल हैं:

वैरिएबल ब्यौरा
name कंपनी का नाम.
displayName कंपनी का डिसप्ले नेम.
id

कंपनी का आईडी.

apps कंपनी के ऐप्लिकेशन की सूची वाला कलेक्शन.
appOwnerStatus
ऐप्लिकेशन के मालिक का स्टेटस, जैसे कि चालू, बंद या login_lock.
created_at कंपनी बनाने की तारीख/टाइमस्टैंप.
created_by कंपनी बनाने वाले उपयोगकर्ता का ईमेल पता.
last_modified_at कंपनी में आखिरी बार बदलाव किए जाने की तारीख/टाइमस्टैंप.
last_modified_by कंपनी में आखिरी बार बदलाव करने वाले उपयोगकर्ता का ईमेल पता.
{company_custom_attributes} कंपनी का कोई कस्टम एट्रिब्यूट. कस्टम एट्रिब्यूट का नाम बताएं.

Analytics वैरिएबल

मान्य एपीआई पासकोड के लिए, एपीआई पासकोड की पुष्टि करने की नीति लागू होने पर, Analytics में ये वैरिएबल अपने-आप पॉप्युलेट हो जाते हैं. ये वैरिएबल, सिर्फ़ एपीआई पासकोड की पुष्टि करने की नीति और OAuth की नीतियों से अपने-आप पॉप्युलेट होते हैं.

वैरिएबल और वैल्यू का इस्तेमाल, Analytics रिपोर्ट बनाने के लिए डाइमेंशन के तौर पर किया जा सकता है. इससे, डेवलपर और ऐप्लिकेशन के इस्तेमाल के पैटर्न के बारे में जानकारी मिलती है.

  • apiproduct.name
  • developer.app.name
  • client_id
  • developer.id

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

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 Cause
keymanagement.service.CompanyStatusNotActive 401 The Company associated with the Developer App that has the API key you are using has an inactive status. When a Company's status is set to inactive, you cannot access the developers or apps associated with that Company. An org admin can change a Company's status using the management API. See Set the Status of a Company.
keymanagement.service.DeveloperStatusNotActive 401

The developer who created the Developer App that has the API key you are using has an inactive status. When an App Developer's status is set to inactive, any Developer Apps created by that developer are deactivated. An admin user with appropriate permissions (such as Organization Administrator) can change a developer's status in the following ways:

keymanagement.service.invalid_client-app_not_approved 401 The Developer App associated with the API key is revoked. A revoked app cannot access any API products and cannot invoke any API managed by Apigee Edge. An org admin can change the status of a Developer App using the management API. See Approve or Revoke Developer App.
oauth.v2.FailedToResolveAPIKey 401 The policy expects to find the API key in a variable that is specified in the policy's <APIKey> element. This error arises when the expected variable does not exist (it cannot be resolved).
oauth.v2.InvalidApiKey 401 An API key was received by Edge, but it is invalid. When Edge looks up the key in its database, it must exactly match the on that was sent in the request. If the API worked previously, make sure the key was not regenerated. If the key was regenerated, you will see this error if you try to use the old key. For details, see Register apps and manage API keys.
oauth.v2.InvalidApiKeyForGivenResource 401 An API key was received by Edge, and it is valid; however, it does not match an approved key in the Developer App associated with your API proxy through a Product.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause
SpecifyValueOrRefApiKey The <APIKey> element does not have a value or key specified.

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 "FailedToResolveAPIKey"
oauthV2.policy_name.failed policy_name is the user-specified name of the policy that threw the fault. oauthV2.VK-VerifyAPIKey.failed = true

Example error responses

{  
   "fault":{  
      "faultstring":"Invalid ApiKey",
      "detail":{  
         "errorcode":"oauth.v2.InvalidApiKey"
      }
   }
}
{  
   "fault":{  
      "detail":{  
         "errorcode":"keymanagement.service.DeveloperStatusNotActive"
      },
      "faultstring":"Developer Status is not Active"
   }
}

Example fault rule

<FaultRule name="FailedToResolveAPIKey">
    <Step>
        <Name>AM-FailedToResolveAPIKey</Name>
    </Step>
    <Condition>(fault.name Matches "FailedToResolveAPIKey") </Condition>
</FaultRule>

मिलते-जुलते विषय