OAuth 2.0 इंप्लिसिट फ़्लो के लिए, आपकी सेवा, एचटीटीपीएस के ज़रिए ऑथराइज़ेशन एंडपॉइंट उपलब्ध कराती है. यह एंडपॉइंट, डेटा ऐक्सेस करने के लिए, उपयोगकर्ताओं की पुष्टि करने और उनकी सहमति पाने के लिए ज़िम्मेदार होता है. ऑथराइज़ेशन एंडपॉइंट, आपके उन उपयोगकर्ताओं को साइन-इन यूज़र इंटरफ़ेस (यूआई) दिखाता है जिन्होंने पहले से साइन इन नहीं किया है. साथ ही, यह अनुरोध किए गए ऐक्सेस के लिए सहमति रिकॉर्ड करता है.
जब किसी Google ऐप्लिकेशन को आपकी सेवा के ऑथराइज़ किए गए किसी एपीआई को कॉल करना होता है, तो Google इस एंडपॉइंट का इस्तेमाल करके, आपके उपयोगकर्ताओं से इन एपीआई को उनकी ओर से कॉल करने की अनुमति लेता है.
Google खाता लिंक करना: OAuth इंप्लिसिट फ़्लो
इस क्रम के डायग्राम में, उपयोगकर्ता, Google, और आपकी सेवा के एंडपॉइंट के बीच होने वाले इंटरैक्शन के बारे में बताया गया है.
भूमिकाएं और ज़िम्मेदारियां
इस टेबल में, Google खाता लिंक करने (जीएएल) के OAuth इंप्लिसिट फ़्लो में शामिल लोगों की भूमिकाओं और ज़िम्मेदारियों के बारे में बताया गया है. ध्यान दें कि जीएएल में, Google, OAuth क्लाइंट के तौर पर काम करता है. वहीं, आपकी सेवा, पहचान/सेवा देने वाली कंपनी के तौर पर काम करती है.
| Actor / Component | GAL Role | Responsibilities |
|---|---|---|
| Google App / Server | OAuth Client | यह फ़्लो शुरू करता है, ब्राउज़र रीडायरेक्ट का इस्तेमाल करके ऐक्सेस टोकन हासिल करता है, और आपकी सेवा के एपीआई को ऐक्सेस करने के लिए इसे सुरक्षित तरीके से सेव करता है. |
| Your Authorization Endpoint | Authorization Server | यह आपके उपयोगकर्ताओं की पुष्टि करता है, उनकी सहमति लेता है, और Google को सीधे तौर पर, लंबे समय तक इस्तेमाल किए जा सकने वाले ऐक्सेस टोकन जारी करता है. |
| Google Redirect URI | Callback Endpoint | यह यूआरएल फ़्रैगमेंट में
access_token और state वैल्यू के साथ, आपके ऑथराइज़ेशन सर्वर से उपयोगकर्ता रीडायरेक्ट हासिल करता है. |
Google की ओर से शुरू किए गए, OAuth 2.0 इंप्लिसिट फ़्लो के सामान्य सेशन में यह फ़्लो होता है:
- Google, उपयोगकर्ता के ब्राउज़र में आपका ऑथराइज़ेशन एंडपॉइंट खोलता है. अगर उपयोगकर्ता ने पहले से साइन इन नहीं किया है, तो वह साइन इन करता है. साथ ही, अगर उसने पहले से अनुमति नहीं दी है, तो वह Google को आपके एपीआई की मदद से अपना डेटा ऐक्सेस करने की अनुमति देता है.
- आपकी सेवा, एक ऐक्सेस टोकन बनाती है और इसे Google को वापस भेजती है. ऐसा करने के लिए, उपयोगकर्ता के ब्राउज़र को Google पर वापस रीडायरेक्ट करें. साथ ही, अनुरोध में ऐक्सेस टोकन जोड़ें.
- Google, आपकी सेवा के एपीआई को कॉल करता है और हर अनुरोध के साथ ऐक्सेस टोकन जोड़ता है. आपकी सेवा पुष्टि करती है कि ऐक्सेस टोकन से Google को एपीआई ऐक्सेस करने की अनुमति मिली है. इसके बाद, एपीआई कॉल पूरा किया जाता है.
लागू करने की रेसिपी
इंप्लिसिट फ़्लो लागू करने के लिए, यह तरीका अपनाएं.
पहला चरण: ऑथराइज़ेशन के अनुरोधों को मैनेज करना
जब Google, खाता लिंक करने की प्रोसेस शुरू करता है, तो वह उपयोगकर्ता को आपके ऑथराइज़ेशन एंडपॉइंट पर रीडायरेक्ट करता है. प्रोटोकॉल के कॉन्ट्रैक्ट और पैरामीटर की ज़रूरी शर्तों के बारे में ज़्यादा जानने के लिए, ऑथराइज़ेशन एंडपॉइंट देखें.
अनुरोध को मैनेज करने के लिए, यह तरीका अपनाएं:
अनुरोध की पुष्टि करना:
- पुष्टि करें कि
client_id, Google को असाइन किए गए क्लाइंट आईडी से मैच करता हो. - पुष्टि करें कि
redirect_uriGoogle के रीडायरेक्ट करने वाले यूआरएल से मैच करता हो:none https://oauth-redirect.googleusercontent.com/r/YOUR_PROJECT_ID https://oauth-redirect-sandbox.googleusercontent.com/r/YOUR_PROJECT_ID - पुष्टि करें कि
response_type,tokenहो.
- पुष्टि करें कि
उपयोगकर्ता की पुष्टि करना:
- देखें कि उपयोगकर्ता ने आपकी सेवा में साइन इन किया है या नहीं.
- अगर उपयोगकर्ता ने साइन इन नहीं किया है, तो उससे साइन-इन या साइन-अप फ़्लो पूरा करने के लिए कहें.
ऐक्सेस टोकन जनरेट करना:
- उपयोगकर्ता और क्लाइंट से जुड़ा एक यूनीक ऐक्सेस टोकन बनाएं. ऐसा टोकन बनाएं जिसका अनुमान न लगाया जा सके.
Google पर वापस रीडायरेक्ट करना:
- ब्राउज़र को
redirect_uriमें दिए गए यूआरएल पर रीडायरेक्ट करें. - यूआरएल फ़्रैगमेंट (हैश) में ये पैरामीटर जोड़ें:
access_token: वह ऐक्सेस टोकन जो आपने जनरेट किया है.token_type: यहbearerहोना चाहिए.state: Google से मिली, बिना बदलाव वाली स्टेट वैल्यू.
- ब्राउज़र को
Handle userinfo requests
The userinfo endpoint is an OAuth 2.0 protected resource that return claims about the linked user. Implementing and hosting the userinfo endpoint is optional, except for the following use cases:
- Linked Account Sign-In with Google One Tap.
- Frictionless subscription on AndroidTV.
After the access token has been successfully retrieved from your token endpoint, Google sends a request to your userinfo endpoint to retrieve basic profile information about the linked user.
| userinfo endpoint request headers | |
|---|---|
Authorization header |
The access token of type Bearer. |
For example, if your userinfo endpoint is available at
https://myservice.example.com/userinfo, a request might look like the following:
GET /userinfo HTTP/1.1 Host: myservice.example.com Authorization: Bearer ACCESS_TOKEN
For your userinfo endpoint to handle requests, do the following steps:
- Extract access token from the Authorization header and return information for the user associated with the access token.
- If the access token is invalid, return an HTTP 401 Unauthorized error with using the
WWW-AuthenticateResponse Header. Below is an example of a userinfo error response: If a 401 Unauthorized, or any other unsuccessful error response is returned during the linking process, the error will be non-recoverable, the retrieved token will be discarded and the user will have to initiate the linking process again.HTTP/1.1 401 Unauthorized WWW-Authenticate: error="invalid_token", error_description="The Access Token expired"
If the access token is valid, return and HTTP 200 response with the following JSON object in the body of the HTTPS response:
If your userinfo endpoint returns an HTTP 200 success response, the retrieved token and claims are registered against the user's Google account.{ "sub": "USER_UUID", "email": "EMAIL_ADDRESS", "given_name": "FIRST_NAME", "family_name": "LAST_NAME", "name": "FULL_NAME", "picture": "PROFILE_PICTURE", }userinfo endpoint response subA unique ID that identifies the user in your system. emailEmail address of the user. given_nameOptional: First name of the user. family_nameOptional: Last name of the user. nameOptional: Full name of the user. pictureOptional: Profile picture of the user.