OAuth की मदद से खाता लिंक करना

OAuth लिंकिंग टाइप, दो इंडस्ट्री स्टैंडर्ड वाले OAuth 2.0 फ़्लो के साथ काम करता है. इनमें इंप्लिसिट और ऑथराइज़ेशन कोड फ़्लो शामिल है.

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

ऑथराइज़ेशन कोड फ़्लो में, आपको दो एंडपॉइंट की ज़रूरत होगी:

  • ऑथराइज़ेशन एंडपॉइंट, जो उन उपयोगकर्ताओं के साइन-इन यूज़र इंटरफ़ेस (यूआई) को दिखाने के लिए ज़िम्मेदार है जिन्होंने पहले से साइन इन नहीं किया है. साथ ही, उपयोगकर्ता को कुछ समय तक इस्तेमाल किए जाने वाले ऑथराइज़ेशन कोड के तौर पर ऐक्सेस का अनुरोध करने के लिए सहमति लेनी होती है.
  • टोकन एक्सचेंज एंडपॉइंट, दो तरह के एक्सचेंज के लिए ज़िम्मेदार है:
    1. लंबे समय तक चलने वाले रीफ़्रेश टोकन और कुछ समय तक चलने वाले ऐक्सेस टोकन के लिए ऑथराइज़ेशन कोड बदलता है. यह एक्सचेंज तब होता है, जब उपयोगकर्ता, खाता जोड़ने के फ़्लो से गुज़रता है.
    2. वह कम समय तक चलने वाले ऐक्सेस टोकन के लिए, लंबे समय तक चलने वाले रीफ़्रेश टोकन की अदला-बदली करता है. यह ऐसा तब होता है, जब Google को नए ऐक्सेस टोकन की ज़रूरत होती है, क्योंकि उसकी समयसीमा खत्म हो चुकी होती है.

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

OAuth खाता जोड़ने की प्रोसेस को लागू करना

प्रोजेक्ट कॉन्फ़िगर करें

OAuth लिंकिंग का इस्तेमाल करने के लिए, अपने प्रोजेक्ट को कॉन्फ़िगर करने के लिए, यह तरीका अपनाएं:

  1. Actions Console खोलें और वह प्रोजेक्ट चुनें जिसका आपको इस्तेमाल करना है.
  2. डेवलप करें टैब पर क्लिक करें और खाता लिंक करना चुनें.
  3. खाता लिंक करना के बगल में मौजूद स्विच को चालू करें.
  4. खाता बनाना सेक्शन में, नहीं, मुझे सिर्फ़ अपनी वेबसाइट पर खाता बनाने की अनुमति देनी है चुनें.

  5. लिंक करने का टाइप में, OAuth और Implicit चुनें.

  6. क्लाइंट की जानकारी में:

    • Google से आने वाले अनुरोधों की पहचान करने के लिए, Google Actions से जारी किए गए Client-ID के लिए कोई वैल्यू असाइन करें.
    • अपने ऑथराइज़ेशन और टोकन एक्सचेंज एंडपॉइंट के यूआरएल डालें.
  1. सेव करें पर क्लिक करें.

अपना OAuth सर्वर लागू करना

To support the OAuth 2.0 implicit flow, your service makes an authorization endpoint available by HTTPS. This endpoint is responsible for authenticating and obtaining consent from users for data access. The authorization endpoint presents a sign-in UI to your users that aren't already signed in and records consent to the requested access.

When your Action needs to call one of your service's authorized APIs, Google uses this endpoint to get permission from your users to call these APIs on their behalf.

A typical OAuth 2.0 implicit flow session initiated by Google has the following flow:

  1. Google opens your authorization endpoint in the user's browser. The user signs in if not signed in already, and grants Google permission to access their data with your API if they haven't already granted permission.
  2. Your service creates an access token and returns it to Google by redirecting the user's browser back to Google with the access token attached to the request.
  3. Google calls your service's APIs, and attaches the access token with each request. Your service verifies that the access token grants Google authorization to access the API and then completes the API call.

Handle authorization requests

When your Action needs to perform account linking via an OAuth 2.0 implicit flow, Google sends the user to your authorization endpoint with a request that includes the following parameters:

Authorization endpoint parameters
client_id The client ID you assigned to Google.
redirect_uri The URL to which you send the response to this request.
state A bookkeeping value that is passed back to Google unchanged in the redirect URI.
response_type The type of value to return in the response. For the OAuth 2.0 implicit flow, the response type is always token.

For example, if your authorization endpoint is available at https://myservice.example.com/auth, a request might look like:

GET https://myservice.example.com/auth?client_id=GOOGLE_CLIENT_ID&redirect_uri=REDIRECT_URI&state=STATE_STRING&response_type=token

For your authorization endpoint to handle sign-in requests, do the following steps:

  1. Verify the client_id and redirect_uri values to prevent granting access to unintended or misconfigured client apps:

    • Confirm that the client_id matches the client ID you assigned to Google.
    • Confirm that the URL specified by the redirect_uri parameter has the following form:
      https://oauth-redirect.googleusercontent.com/r/YOUR_PROJECT_ID
      YOUR_PROJECT_ID is the ID found on the Project settings page of the Actions Console.
  2. Check if the user is signed in to your service. If the user isn't signed in, complete your service's sign-in or sign-up flow.

  3. Generate an access token that Google will use to access your API. The access token can be any string value, but it must uniquely represent the user and the client the token is for and must not be guessable.

  4. Send an HTTP response that redirects the user's browser to the URL specified by the redirect_uri parameter. Include all of the following parameters in the URL fragment:

    • access_token: the access token you just generated
    • token_type: the string bearer
    • state: the unmodified state value from the original request The following is an example of the resulting URL:
      https://oauth-redirect.googleusercontent.com/r/YOUR_PROJECT_ID#access_token=ACCESS_TOKEN&token_type=bearer&state=STATE_STRING

Google's OAuth 2.0 redirect handler will receive the access token and confirm that the state value hasn't changed. After Google has obtained an access token for your service, Google will attach the token to subsequent calls to your Action as part of the AppRequest.

पुष्टि करने के लिए, वॉइस यूज़र इंटरफ़ेस डिज़ाइन करें

यह पता करना कि उपयोगकर्ता की पुष्टि हो चुकी है या नहीं और खाता लिंक करने की प्रक्रिया शुरू करें

  1. Actions कंसोल में अपना Actions Builder प्रोजेक्ट खोलें.
  2. अपनी सेट की गई कार्रवाई में खाता लिंक करने की प्रोसेस शुरू करने के लिए, एक नया सीन बनाएं:
    1. सीन पर क्लिक करें.
    2. नया सीन जोड़ने के लिए, जोड़ें (+) आइकॉन पर क्लिक करें.
  3. नए सीन में, शर्तों के लिए, जोड़ें आइकॉन पर क्लिक करें.
  4. एक शर्त जोड़ें जो यह जांच करती है कि बातचीत से जुड़ा उपयोगकर्ता, पुष्टि किया गया उपयोगकर्ता है या नहीं. अगर जांच पूरी नहीं हो पाती, तो आपकी सेट की गई कार्रवाई, बातचीत के दौरान खाता लिंक नहीं कर पाएगी. साथ ही, इसे ऐसे फ़ंक्शन का ऐक्सेस देना होगा जिसके लिए खाता लिंक करने की ज़रूरत नहीं होती.
    1. शर्त वाले Enter new expression फ़ील्ड में, यह लॉजिक डालें: user.verificationStatus != "VERIFIED"
    2. ट्रांज़िशन में, ऐसा सीन चुनें जिसमें खाता लिंक करने की ज़रूरत न हो या कोई ऐसा सीन चुनें जो सिर्फ़ मेहमान के लिए उपलब्ध सुविधा के लिए शुरुआती पॉइंट हो.

  1. शर्तों के लिए, ' जोड़ें' आइकॉन पर क्लिक करें.
  2. अगर उपयोगकर्ता की पहचान से जुड़ी जानकारी नहीं है, तो खाता लिंक करने के फ़्लो को ट्रिगर करने के लिए कोई शर्त जोड़ें.
    1. शर्त वाले Enter new expression फ़ील्ड में, यह लॉजिक डालें: user.verificationStatus == "VERIFIED"
    2. ट्रांज़िशन में जाकर, खाता लिंक करना सिस्टम सीन चुनें.
    3. सेव करें पर क्लिक करें.

सेव करने के बाद, आपके प्रोजेक्ट में खाता लिंक करने वाला <SceneName>_AccountLinking नाम का एक नया सीन जोड़ा जाता है.

खाता लिंक करने के सीन को पसंद के मुताबिक बनाना

  1. सीन में जाकर, खाता लिंक करने वाले सिस्टम का सीन चुनें.
  2. सूचना भेजें पर क्लिक करें. इसके बाद, एक छोटा वाक्य जोड़कर उपयोगकर्ता को बताएं कि कार्रवाई को उनकी पहचान का ऐक्सेस क्यों चाहिए. उदाहरण के लिए, "आपकी प्राथमिकताएं सेव करने के लिए".
  3. सेव करें पर क्लिक करें.

  1. शर्तें सेक्शन में, अगर उपयोगकर्ता खाता लिंक करने की प्रोसेस पूरी कर लेता है पर क्लिक करें.
  2. अगर उपयोगकर्ता अपने खाते को लिंक करने की सहमति देता है, तो फ़्लो को कॉन्फ़िगर करना. उदाहरण के लिए, ज़रूरी किसी भी कारोबारी लॉजिक को प्रोसेस करने और मूल सीन पर वापस जाने के लिए वेबहुक को कॉल करें.
  3. सेव करें पर क्लिक करें.

  1. शर्तें सेक्शन में, अगर उपयोगकर्ता खाता जोड़ने की प्रोसेस को रद्द करता है या उसे खारिज करता है, तो उस पर क्लिक करें.
  2. अगर उपयोगकर्ता अपने खाते को लिंक करने के लिए सहमत नहीं है, तो फ़्लो कॉन्फ़िगर करें. उदाहरण के लिए, स्वीकार करने वाला मैसेज भेजें और उन सीन पर रीडायरेक्ट करें जिनमें ऐसी सुविधाएं दी गई हों जिनके लिए खाता लिंक करने की ज़रूरत न हो.
  3. सेव करें पर क्लिक करें.

  1. शर्तें सेक्शन में, अगर सिस्टम या नेटवर्क की गड़बड़ी होती है पर क्लिक करें.
  2. कॉन्फ़िगर करें कि अगर सिस्टम या नेटवर्क की गड़बड़ियों की वजह से खाता लिंक करने का फ़्लो पूरा नहीं हो पा रहा है, तो फ़्लो कैसे आगे बढ़ना चाहिए. उदाहरण के लिए, स्वीकार करने वाला मैसेज भेजें और उन सीन पर रीडायरेक्ट करें जिनमें ऐसी सुविधाएं दी गई हों जिनके लिए खाता लिंक करने की ज़रूरत न हो.
  3. सेव करें पर क्लिक करें.

डेटा ऐक्सेस करने के अनुरोधों को मैनेज करना

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