> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# JWT उत्पन्न करें

> सिंगल साइन ऑन के साथ उपयोग के लिए एक JSON Web Token (JWT) उत्पन्न करें।

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

<PlansAvailable plans={["business"]} maxPackRequired={false} />

सिंगल साइन ऑन के साथ उपयोग के लिए एक JSON Web Token (JWT) उत्पन्न करें।

अधिक विवरण के लिए [Generate JWT Overview](/apis/profiles/generate-jwt-overview) देखें।

<Note>
  JWT URL **5 मिनट** के लिए वैध है। 5 मिनट के बाद आपको एक नया JWT URL उत्पन्न करना होगा।
  [अतिरिक्त विकल्पों](/apis/profiles/generate-jwt-overview#jwt-expires-in) के लिए Max Pack `expiresIn` देखें।
</Note>

## हेडर पैरामीटर

<HeaderAPI noProfileKey />

<ParamField header="X-Twitter-OAuth1-Api-Key" type="string">
  X Developer Portal से आपकी X API Key (Consumer Key)। `twitterApiKey` बॉडी पैरामीटर का विकल्प। प्रदान किए जाने पर, उत्पन्न JWT URL OAuth लिंकिंग के लिए आपके X Developer App का उपयोग करेगा।
</ParamField>

<ParamField header="X-Twitter-OAuth1-Api-Secret" type="string">
  X Developer Portal से आपकी X API Secret (Consumer Secret)। `twitterApiSecret` बॉडी पैरामीटर का विकल्प। `X-Twitter-OAuth1-Api-Key` प्रदान किए जाने पर आवश्यक।
</ParamField>

<Info>
  **अनुशंसित:** सभी अन्य Ayrshare API एंडपॉइंट्स के साथ संगति के लिए अपनी X क्रेडेंशियल्स को हेडर (`X-Twitter-OAuth1-Api-Key` और `X-Twitter-OAuth1-Api-Secret`) के माध्यम से पास करें। `twitterApiKey` और `twitterApiSecret` बॉडी पैरामीटर पिछड़े संगतता के लिए अभी भी समर्थित हैं।
</Info>

## बॉडी पैरामीटर

<ParamField body="domain" type="string" required>
  ऐप का डोमेन। कृपया ऑनबोर्डिंग के दौरान दिए गए सटीक डोमेन का उपयोग करें।
</ParamField>

<ParamField body="privateKey" type="string" required>
  एन्क्रिप्शन के लिए उपयोग की जाने वाली Private Key।
</ParamField>

<ParamField body="profileKey" type="string" required>
  User Profile Key। इस फ़ील्ड में API Key का उपयोग नहीं किया जा सकता।
</ParamField>

<ParamField body="logout" type="boolean" default={false}>
  वर्तमान सत्र को स्वचालित रूप से लॉगआउट करें। प्रदर्शन को प्रभावित करने के कारण उत्पादन में उपयोग नहीं करने की अनुशंसा की जाती है।

  अधिक जानकारी के लिए [Automatic Logout of a Profile Session](/multiple-users/api-integration-business#automatic-logout-of-a-profile-session) देखें।
</ParamField>

<ParamField body="redirect" type="string">
  "Done" बटन या लोगो छवि पर क्लिक करने पर रीडायरेक्ट करने के लिए एक URL निर्दिष्ट करें। लौटाए गए JWT url में URL स्वचालित रूप से शॉर्टन कर दिया जाएगा। रीडायरेक्ट URL में क्वेरी पैरामीटर `origin=true` जोड़कर [origin opener window को रीडायरेक्ट](/multiple-users/api-integration-business#opening-and-closing-the-social-linking-url) करें।
</ParamField>

<ParamField body="allowedSocial" type="array">
  लिंकिंग पेज में प्रदर्शित करने के लिए सोशल नेटवर्क निर्दिष्ट करें। यह [Social Networks](/multiple-users/manage-user-profiles#set-social-networks-access) पेज में कॉन्फ़िगर किए गए सोशल नेटवर्कों को ओवरराइड कर देगा।

  ```json Only display Facebook, X/Twitter, LinkedIn, and TikTok theme={"system"}
  {
    "allowedSocial": ["facebook", "twitter", "linkedin", "tiktok"]
  }
  ```
</ParamField>

<ParamField body="instagramLinkMethod" type="string">
  इस URL के लिए सोशल लिंकिंग पेज पर उपयोगकर्ता Instagram बटन पर क्लिक करने पर कौन सा Instagram लिंकिंग फ़्लो उपयोग किया जाता है, इसे ओवरराइड करें। वैध मान:

  * `instagram`: सीधा Instagram Login, कोई Facebook पेज आवश्यक नहीं।
  * `facebook`: कनेक्टेड Facebook पेज के माध्यम से Instagram लिंक करें।

  ```json Force direct Instagram Login for this linking session theme={"system"}
  {
    "instagramLinkMethod": "instagram"
  }
  ```

  छोड़ दिए जाने पर, लिंकिंग पेज आपकी खाता-व्यापी [Instagram Login](/multiple-users/manage-user-profiles#instagram-login) सेटिंग का उपयोग करता है।

  अधिक जानकारी के लिए [Instagram Link Method](/apis/profiles/generate-jwt-overview#instagram-link-method) देखें।
</ParamField>

<ParamField body="verify" type="boolean" default={false}>
  सत्यापित करें कि उत्पन्न टोकन मान्य है। केवल गैर-उत्पादन वातावरण में उपयोग करने की अनुशंसा की जाती है।

  अधिक जानकारी के लिए [Opening and Closing the Social Linking URL](/multiple-users/api-integration-business#opening-and-closing-the-social-linking-url) देखें।
</ParamField>

<ParamField body="base64" type="boolean" default={false}>
  यदि प्राइवेट की base64 एन्कोडेड है, तो `true` पर सेट करें।

  private.key फ़ाइल को base64 में एन्कोड करें और सिंगल लाइन String को `privateKey` फ़ील्ड में पास करें।

  उदा. Linux में: `cat private.key | base64`
</ParamField>

<ParamField body="expiresIn" type="number" default={5}>
  मिनटों में टोकन की लंबी अवधि सेट करें। सीमा: 1 मिनट से 2880 मिनट तक।

  अधिक जानकारी के लिए [JWT Expires In](/apis/profiles/generate-jwt-overview#jwt-expires-in) देखें।
</ParamField>

<ParamField body="email" type="object" default={5}>
  उपयोगकर्ताओं के लिए उनके सोशल लिंकेज पेज तक सीधे पहुँच के लिए एक लिंक के साथ Connect Accounts ईमेल भेजें।

  अधिक जानकारी के लिए [Connect Accounts Email](/apis/profiles/generate-jwt-overview#connect-accounts-email) देखें।
</ParamField>

<Info>
  जब आप अपनी X API क्रेडेंशियल्स शामिल करते हैं, तो उत्पन्न JWT URL आपके अपने X Developer App का उपयोग करके OAuth लिंकिंग शुरू करेगा। आपके अंतिम उपयोगकर्ता X सहमति स्क्रीन पर आपके ऐप का नाम देखेंगे।
</Info>

<Warning>
  **आवश्यक:** इस सुविधा का उपयोग करने से पहले, आपको इन कॉलबैक URL को अपनी X Developer App सेटिंग्स में (Authentication settings > Callback URI / Redirect URL के अंतर्गत) जोड़ना होगा:

  * `https://profile.ayrshare.com/social-accounts`
  * `https://app.ayrshare.com/social-accounts`

  इनके बिना, OAuth फ़्लो `403 Callback URL not approved` त्रुटि के साथ विफल हो जाएगा।
</Warning>

<RequestExample>
  ```javascript cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: application/json' \
  -H "X-Twitter-OAuth1-Api-Key: YOUR_CONSUMER_KEY" \
  -H "X-Twitter-OAuth1-Api-Secret: YOUR_CONSUMER_SECRET" \
  -d '{"domain": "ACME", "privateKey": "-----BEGIN RSA PRIVATE KEY...", "profileKey": "PROFILE_KEY"}' \
  -X POST https://api.ayrshare.com/api/profiles/generateJWT
  ```

  ```javascript JavaScript theme={"system"}
  const fs = require('fs');
  const API_KEY = "API_KEY";
  const PROFILE_KEY = "PROFILE_KEY";

  // Read in local private.key files - also can read from a DB
  const privateKey = fs.readFileSync('private.key', 'utf8');

  fetch("https://api.ayrshare.com/api/profiles/generateJWT", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`,
          "X-Twitter-OAuth1-Api-Key": "YOUR_CONSUMER_KEY",
          "X-Twitter-OAuth1-Api-Secret": "YOUR_CONSUMER_SECRET"
        },
        body: JSON.stringify({
          domain: "ACME",          // required
          privateKey,              // required
          profileKey: PROFILE_KEY, // required
        }),
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  # Read in local private.key files - also can read from a DB
  with open('.private.key') as f:
      profileKey = f.read()

  payload = {'domain': 'ACME',
          'privateKey': profileKey,
          'profileKey': 'PROFILE_KEY' }
  headers = {'Content-Type': 'application/json',
          'Authorization': 'Bearer API_KEY',
          'X-Twitter-OAuth1-Api-Key': 'YOUR_CONSUMER_KEY',
          'X-Twitter-OAuth1-Api-Secret': 'YOUR_CONSUMER_SECRET'}

  r = requests.post('https://api.ayrshare.com/api/profiles/generateJWT',
      json=payload,
      headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  <?php
  require 'vendor/autoload.php';    // Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html

  $client = new GuzzleHttp\Client();
  $res = $client->request(
      'POST',
      'https://api.ayrshare.com/api/post',
      [
          'headers' => [
              'Content-Type'  => 'application/json',
              'Authorization' => 'Bearer API_KEY'
          ],
          'json' => [
              'domain' => 'ACME',
              'privateKey' => '-----BEGIN RSA PRIVATE KEY...', // required
              'profileKey' => 'PROFILE_KEY', // requires
          ]
      ]
  );

  echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;
  using System.IO;
  using Newtonsoft.Json;

  namespace GenerateJWTRequest_csharp
  {
    class GenerateJWT
    {
        static async Task Main(string[] args)
        {
            string API_KEY = "API_KEY";
            string url = "https://api.ayrshare.com/api/profiles/generateJWT";

            try
            {
                string privateKey = await File.ReadAllTextAsync("./private.key");

                var sendData = new
                {
                    domain = "domain",
                    privateKey = privateKey,
                    profileKey = "PROFILE_KEY"
                };

                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

                    string jsonData = JsonConvert.SerializeObject(sendData);
                    var content = new StringContent(jsonData, Encoding.UTF8, "application/json");

                    HttpResponseMessage response = await client.PostAsync(url, content);
                    response.EnsureSuccessStatusCode();

                    string responseBody = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(responseBody);
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine($"Private key file not found: {e.Message}");
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine($"HTTP request error: {e.Message}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Unexpected error: {e.Message}");
            }
        }
    }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200: सफलता theme={"system"}
  {
      "status": "success",
      "title": "User Profile Title",
      "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlLZXkiOiJBSjNQR1cxLThIWk04UjQtR0NXVFZKVy1ZRTE1M1BFIiwicHJvZmlsZUtleSI6IjhKNDY4UFktSjM5TVlXRC1IWEpLVlIyLVBRMjBQUlMiLCJpYXQiOjE2MTQyMjYwNDksImV4cCI6MTYxNDIyNjM0OSwiYXVkIjoiaHR0cHM6Ly9hcHAuYXlyc2hhcmUuY29tIiwiaXNzIjoiYm9uZGJyYW5kbG95YWx0eS5jb20iLCJzdWIiOiJzdXBwb3J0QGF5cnNoYXJlLmNvbSJ9.Se387OyhJIdaDkFkvAe0Dwo3pQrHBwdg2bbjqKYn7BZuVDxPboJmTsd7rra8N-Z6b9_fJOtwlRFGBLW1CvgLGU4RSisTVqjqhAkb3KNhpA7cZ673IJbRX-ST7tYadKKzmd9GNrZW9rhxHOlgMJ9uOboc4dcaDbNmzb_yCrfLY-E"
      "url": "https://profile.ayrshare.com?domain=PROVIDED_DOMAIN&jwt=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcGlLZXkiOiJBSjNQR1cxLThIWk04UjQtR0NXVFZKVy1ZRTE1M1BFIiwicHJvZmlsZUtleSI6IjhKNDY4UFktSjM5TVlXRC1IWEpLVlIyLVBRMjBQUlMiLCJpYXQiOjE2MTQyMjYwNDksImV4cCI6MTYxNDIyNjM0OSwiYXVkIjoiaHR0cHM6Ly9hcHAuYXlyc2hhcmUuY29tIiwiaXNzIjoiYm9uZGJyYW5kbG95YWx0eS5jb20iLCJzdWIiOiJzdXBwb3J0QGF5cnNoYXJlLmNvbSJ9.Se387OyhJIdaDkFkvAe0Dwo3pQrHBwdg2bbjqKYn7BZuVDxPboJmTsd7rra8N-Z6b9_fJOtwlRFGBLW1CvgLGU4RSisTVqjqhAkb3KNhpA7cZ673IJbRX-ST7tYadKKzmd9GNrZW9rhxHOlgMJ9uOboc4dcaDbNmzb_yCrfLY-E",
      "emailSent": true,    
      "expiresIn": "30m"    
  }
  ```

  ```json 400: प्राइवेट की गलत ढंग से प्रारूपित theme={"system"}
  {
    "action": "JWT",
    "status": "error",
    "code": 189,
    "message": "Error generating JWT. Check the sent parameters, such as the privateKey has no extra tabs, spaces, or newlines. Error: error:0909006C:PEM routines:get_name:no start line"
  }
  ```

  ```json 400: आंशिक Twitter API कुंजियाँ theme={"system"}
  {
    "action": "JWT",
    "status": "error",
    "code": 188,
    "message": "Both twitterApiKey and twitterApiSecret are required. You provided only one."
  }
  ```

  ```json 400: डुप्लिकेट X/Twitter क्रेडेंशियल्स theme={"system"}
  {
      "action": "JWT",
      "status": "error",
      "code": 434,
      "message": "X/Twitter API credentials were provided in both the request headers and the request body. Please use the headers only. See https://www.ayrshare.com/docs/apis/profiles/generate-jwt"
  }
  ```
</ResponseExample>
