OAuth এর সাথে Google অ্যাকাউন্ট লিঙ্ক করা

অ্যাকাউন্টগুলি ইন্ডাস্ট্রি স্ট্যান্ডার্ড OAuth 2.0 অন্তর্নিহিত এবং অনুমোদন কোড ফ্লো ব্যবহার করে লিঙ্ক করা হয়। আপনার পরিষেবা অবশ্যই OAuth 2.0 অনুগত অনুমোদন এবং টোকেন বিনিময় শেষ পয়েন্ট সমর্থন করবে৷

অন্তর্নিহিত প্রবাহে, Google ব্যবহারকারীর ব্রাউজারে আপনার অনুমোদনের শেষ পয়েন্ট খোলে। সফল সাইন ইন করার পরে, আপনি Google-এ একটি দীর্ঘস্থায়ী অ্যাক্সেস টোকেন ফেরত দেন। এই অ্যাক্সেস টোকেনটি এখন Google থেকে পাঠানো প্রতিটি অনুরোধে অন্তর্ভুক্ত করা হয়েছে।

অনুমোদন কোড প্রবাহে, আপনার দুটি শেষ পয়েন্ট প্রয়োজন:

  • অনুমোদন এন্ডপয়েন্ট, যা আপনার ব্যবহারকারীদের সাইন-ইন UI উপস্থাপন করে যারা ইতিমধ্যে সাইন ইন করেনি। অনুমোদনের শেষ পয়েন্টটি অনুরোধ করা অ্যাক্সেসে ব্যবহারকারীদের সম্মতি রেকর্ড করার জন্য একটি স্বল্প-কালীন অনুমোদন কোডও তৈরি করে।

  • টোকেন এক্সচেঞ্জ এন্ডপয়েন্ট, যা দুই ধরনের এক্সচেঞ্জের জন্য দায়ী:

    1. একটি দীর্ঘস্থায়ী রিফ্রেশ টোকেন এবং একটি স্বল্পকালীন অ্যাক্সেস টোকেনের জন্য একটি অনুমোদন কোড বিনিময় করে৷ এই বিনিময়টি ঘটে যখন ব্যবহারকারী অ্যাকাউন্ট লিঙ্কিং প্রবাহের মধ্য দিয়ে যায়।
    2. একটি স্বল্পকালীন অ্যাক্সেস টোকেনের জন্য দীর্ঘস্থায়ী রিফ্রেশ টোকেন বিনিময় করে। Google এর একটি নতুন অ্যাক্সেস টোকেনের প্রয়োজন হলে এই বিনিময়টি ঘটে কারণ এটির মেয়াদ শেষ হয়ে গেছে।

একটি OAuth 2.0 ফ্লো বেছে নিন

যদিও অন্তর্নিহিত প্রবাহ প্রয়োগ করা সহজ, Google সুপারিশ করে যে অন্তর্নিহিত প্রবাহ দ্বারা জারি করা অ্যাক্সেস টোকেন কখনই মেয়াদ শেষ হবে না। এর কারণ হল একটি টোকেন অন্তর্নিহিত প্রবাহের সাথে মেয়াদ শেষ হওয়ার পরে ব্যবহারকারীকে তাদের অ্যাকাউন্ট আবার লিঙ্ক করতে বাধ্য করা হয়। নিরাপত্তার কারণে আপনার টোকেনের মেয়াদ শেষ হওয়ার প্রয়োজন হলে, আমরা দৃঢ়ভাবে সুপারিশ করছি যে আপনি পরিবর্তে অনুমোদন কোড প্রবাহ ব্যবহার করুন।

ডিজাইন নির্দেশিকা

এই বিভাগে আপনি OAuth লিঙ্কিং ফ্লোগুলির জন্য হোস্ট করা ব্যবহারকারী স্ক্রিনের জন্য ডিজাইনের প্রয়োজনীয়তা এবং সুপারিশগুলি বর্ণনা করে৷ Google-এর অ্যাপ দ্বারা এটিকে কল করার পরে, আপনার প্ল্যাটফর্মটি Google পৃষ্ঠায় একটি সাইন ইন এবং ব্যবহারকারীকে অ্যাকাউন্ট লিঙ্ক করার সম্মতি স্ক্রীন প্রদর্শন করে। অ্যাকাউন্ট লিঙ্ক করতে তাদের সম্মতি দেওয়ার পরে ব্যবহারকারীকে Google-এর অ্যাপে ফেরত পাঠানো হয়।

এই চিত্রটি একটি ব্যবহারকারীর জন্য তাদের Google অ্যাকাউন্টকে আপনার প্রমাণীকরণ সিস্টেমের সাথে লিঙ্ক করার পদক্ষেপগুলি দেখায়৷ প্রথম স্ক্রিনশটটি আপনার প্ল্যাটফর্ম থেকে ব্যবহারকারীর সূচনা লিঙ্ক দেখায়। দ্বিতীয় চিত্রটি ব্যবহারকারীর Google-এ সাইন-ইন দেখায়, যখন তৃতীয়টি আপনার অ্যাপের সাথে তাদের Google অ্যাকাউন্ট লিঙ্ক করার জন্য ব্যবহারকারীর সম্মতি এবং নিশ্চিতকরণ দেখায়। চূড়ান্ত স্ক্রিনশট Google অ্যাপে একটি সফলভাবে লিঙ্ক করা ব্যবহারকারীর অ্যাকাউন্ট দেখায়।
চিত্র 1. অ্যাকাউন্ট লিঙ্ককারী ব্যবহারকারী Google-এ সাইন ইন করুন এবং সম্মতি স্ক্রীন।

প্রয়োজনীয়তা

  1. আপনাকে অবশ্যই যোগাযোগ করতে হবে যে ব্যবহারকারীর অ্যাকাউন্টটি Google-এর সাথে লিঙ্ক করা হবে, Google Home বা Google Assistant-এর মতো নির্দিষ্ট Google পণ্যের সাথে নয়

সুপারিশ

আমরা আপনাকে নিম্নলিখিতগুলি করার পরামর্শ দিই:

  1. Google এর গোপনীয়তা নীতি প্রদর্শন করুন। সম্মতি স্ক্রিনে Google-এর গোপনীয়তা নীতির একটি লিঙ্ক অন্তর্ভুক্ত করুন।

  2. ডেটা শেয়ার করতে হবে। ব্যবহারকারীকে তাদের Google-এর কোন ডেটা প্রয়োজন এবং কেন তা জানাতে স্পষ্ট এবং সংক্ষিপ্ত ভাষা ব্যবহার করুন৷

  3. কল-টু-অ্যাকশন পরিষ্কার করুন। আপনার সম্মতি স্ক্রিনে একটি স্পষ্ট কল-টু-অ্যাকশন বলুন, যেমন "সম্মতি দিন এবং লিঙ্ক করুন।" এর কারণ হল ব্যবহারকারীদের বুঝতে হবে তাদের অ্যাকাউন্ট লিঙ্ক করার জন্য Google-এর সাথে কী ডেটা শেয়ার করতে হবে।

  4. বাতিল করার ক্ষমতা। ব্যবহারকারীরা লিঙ্ক না করা বেছে নিলে তাদের ফিরে যেতে বা বাতিল করার একটি উপায় প্রদান করুন।

  5. সাইন-ইন প্রক্রিয়া পরিষ্কার করুন। নিশ্চিত করুন যে ব্যবহারকারীদের তাদের Google অ্যাকাউন্টে সাইন ইন করার জন্য পরিষ্কার পদ্ধতি আছে, যেমন তাদের ব্যবহারকারীর নাম এবং পাসওয়ার্ডের জন্য ক্ষেত্র বা Google দিয়ে সাইন ইন করুন

  6. লিঙ্কমুক্ত করার ক্ষমতা। ব্যবহারকারীদের আনলিঙ্ক করার জন্য একটি প্রক্রিয়া অফার করুন, যেমন আপনার প্ল্যাটফর্মে তাদের অ্যাকাউন্ট সেটিংসের URL। বিকল্পভাবে, আপনি Google অ্যাকাউন্টে একটি লিঙ্ক অন্তর্ভুক্ত করতে পারেন যেখানে ব্যবহারকারীরা তাদের লিঙ্ক করা অ্যাকাউন্ট পরিচালনা করতে পারে।

  7. ব্যবহারকারীর অ্যাকাউন্ট পরিবর্তন করার ক্ষমতা। ব্যবহারকারীদের তাদের অ্যাকাউন্ট(গুলি) পরিবর্তন করার জন্য একটি পদ্ধতির পরামর্শ দিন। এটি বিশেষত উপকারী যদি ব্যবহারকারীদের একাধিক অ্যাকাউন্ট থাকে।

    • যদি কোনো ব্যবহারকারীকে অ্যাকাউন্ট পাল্টানোর জন্য সম্মতি স্ক্রীন বন্ধ করতে হয়, Google-এ একটি পুনরুদ্ধারযোগ্য ত্রুটি পাঠান যাতে ব্যবহারকারী OAuth লিঙ্কিং এবং অন্তর্নিহিত প্রবাহের মাধ্যমে পছন্দসই অ্যাকাউন্টে সাইন ইন করতে পারেন।
  8. আপনার লোগো অন্তর্ভুক্ত করুন. সম্মতি স্ক্রিনে আপনার কোম্পানির লোগো দেখান। আপনার লোগো স্থাপন করতে আপনার শৈলী নির্দেশিকা ব্যবহার করুন. আপনি যদি Google-এর লোগোও প্রদর্শন করতে চান, লোগো এবং ট্রেডমার্ক দেখুন।

Create the project

To create your project to use account linking:

  1. Go to the Google API Console.
  2. প্রকল্প তৈরি করুন ক্লিক করুন
  3. একটি নাম লিখুন বা উত্পন্ন পরামর্শ গ্রহণ করুন।
  4. নিশ্চিত করুন বা কোনও অবশিষ্ট ক্ষেত্র সম্পাদনা করুন।
  5. তৈরি ক্লিক করুন

আপনার প্রকল্পের আইডি দেখতে:

  1. Go to the Google API Console.
  2. অবতরণ পৃষ্ঠায় সারণীতে আপনার প্রকল্পটি সন্ধান করুন। প্রকল্প আইডি আইডি কলামে প্রদর্শিত হবে।

The Google Account Linking process includes a consent screen which tells users the application requesting access to their data, what kind of data they are asking for and the terms that apply. You will need to configure your OAuth consent screen before generating a Google API client ID.

  1. Open the OAuth consent screen page of the Google APIs console.
  2. If prompted, select the project you just created.
  3. On the "OAuth consent screen" page, fill out the form and click the “Save” button.

    Application name: The name of the application asking for consent. The name should accurately reflect your application and be consistent with the application name users see elsewhere. The application name will be shown on the Account Linking consent screen.

    Application logo: An image on the consent screen that will help users recognize your app. The logo is shown on Account linking consent screen and on account settings

    Support email: For users to contact you with questions about their consent.

    Scopes for Google APIs: Scopes allow your application to access your user's private Google data. For the Google Account Linking use case, default scope (email, profile, openid) is sufficient, you don’t need to add any sensitive scopes. It is generally a best practice to request scopes incrementally, at the time access is required, rather than up front. Learn more.

    Authorized domains: To protect you and your users, Google only allows applications that authenticate using OAuth to use Authorized Domains. Your applications' links must be hosted on Authorized Domains. Learn more.

    Application Homepage link: Home page for your application. Must be hosted on an Authorized Domain.

    Application Privacy Policy link: Shown on Google Account Linking consent screen. Must be hosted on an Authorized Domain.

    Application Terms of Service link (Optional): Must be hosted on an Authorized Domain.

    Figure 1. Google Account Linking Consent Screen for a fictitious Application, Tunery

  4. Check "Verification Status", if your application needs verification then click the "Submit For Verification" button to submit your application for verification. Refer to OAuth verification requirements for details.

আপনার OAuth সার্ভার বাস্তবায়ন করুন

To support the OAuth 2.0 implicit flow, your service makes an authorization endpoint available by HTTPS. This endpoint is responsible for authentication 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 a Google application 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. To do so, redirect 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 a Google application 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.
user_locale The Google Account language setting in RFC5646 format used to localize your content in the user's preferred language.

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

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

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
      https://oauth-redirect-sandbox.googleusercontent.com/r/YOUR_PROJECT_ID
      
  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 for Google to 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 receives the access token and confirms that the state value hasn't changed. After Google has obtained an access token for your service, Google attaches the token to subsequent calls to your service APIs.

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:

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:

  1. Extract access token from the Authorization header and return information for the user associated with the access token.
  2. If the access token is invalid, return an HTTP 401 Unauthorized error with using the WWW-Authenticate Response Header. Below is an example of a userinfo error response:
    HTTP/1.1 401 Unauthorized
    WWW-Authenticate: error="invalid_token",
    error_description="The Access Token expired"
    
    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.
  3. If the access token is valid, return and HTTP 200 response with the following JSON object in the body of the HTTPS response:

    {
    "sub": "USER_UUID",
    "email": "EMAIL_ADDRESS",
    "given_name": "FIRST_NAME",
    "family_name": "LAST_NAME",
    "name": "FULL_NAME",
    "picture": "PROFILE_PICTURE",
    }
    
    If your userinfo endpoint returns an HTTP 200 success response, the retrieved token and claims are registered against the user's Google account.

    userinfo endpoint response
    sub A unique ID that identifies the user in your system.
    email Email address of the user.
    given_name Optional: First name of the user.
    family_name Optional: Last name of the user.
    name Optional: Full name of the user.
    picture Optional: Profile picture of the user.

আপনার বাস্তবায়ন যাচাই করা হচ্ছে

You can validate your implementation by using the OAuth 2.0 Playground tool.

In the tool, do the following steps:

  1. Click Configuration to open the OAuth 2.0 Configuration window.
  2. In the OAuth flow field, select Client-side.
  3. In the OAuth Endpoints field, select Custom.
  4. Specify your OAuth 2.0 endpoint and the client ID you assigned to Google in the corresponding fields.
  5. In the Step 1 section, don't select any Google scopes. Instead, leave this field blank or type a scope valid for your server (or an arbitrary string if you don't use OAuth scopes). When you're done, click Authorize APIs.
  6. In the Step 2 and Step 3 sections, go through the OAuth 2.0 flow and verify that each step works as intended.

You can validate your implementation by using the Google Account Linking Demo tool.

In the tool, do the following steps:

  1. Click the Sign-in with Google button.
  2. Choose the account you'd like to link.
  3. Enter the service ID.
  4. Optionally enter one or more scopes that you will request access for.
  5. Click Start Demo.
  6. When prompted, confirm that you may consent and deny the linking request.
  7. Confirm that you are redirected to your platform.