ภาพรวม
การลิงก์ Google Sign-In แบบอิงตาม OAuth จะเพิ่ม Google Sign-In นอกเหนือจากการลิงก์ OAuth บริการนี้จะมอบประสบการณ์การลิงก์ที่ราบรื่นสําหรับผู้ใช้ Google และยังช่วยให้ผู้ใช้สร้างบัญชี ซึ่งช่วยให้ผู้ใช้สร้างบัญชีใหม่ในบริการของคุณได้โดยใช้บัญชี Google
หากต้องการลิงก์บัญชีกับ OAuth และ Google Sign-In ให้ทําตามขั้นตอนทั่วไปดังนี้
- ขั้นแรกให้ขอให้ผู้ใช้ให้สิทธิ์การเข้าถึงโปรไฟล์ Google ของตน
- ใช้ข้อมูลในโปรไฟล์เพื่อตรวจสอบว่ามีบัญชีผู้ใช้หรือไม่
- สําหรับผู้ใช้ที่มีอยู่ ให้ลิงก์บัญชี
- หากไม่พบรายการที่ตรงกันสําหรับผู้ใช้ Google ในระบบการตรวจสอบสิทธิ์ของคุณ ให้ตรวจสอบโทเค็นรหัสที่ได้รับจาก Google จากนั้นคุณจะสร้างผู้ใช้ตามข้อมูลโปรไฟล์ที่อยู่ในโทเค็นรหัสได้

รูปที่ 1 การลิงก์บัญชีในโทรศัพท์ของผู้ใช้ด้วยการลิงก์ที่มีประสิทธิภาพมากขึ้น
ข้อกําหนดสําหรับการลิงก์ที่มีประสิทธิภาพ
- ใช้การลิงก์ OAuth ในเว็บพื้นฐาน บริการของคุณต้องรองรับปลายทางการให้สิทธิ์ของ OAuth 2.0 และโทเค็นการแลกเปลี่ยน
- ปลายทาง token Exchange ต้องรองรับการยืนยัน JSON Web Token (JWT) และใช้ Intent ของ
check
,create
และget
ใช้งานเซิร์ฟเวอร์ OAuth
ปลายทาง token Exchange ต้องรองรับ Intent ของ check
, create
และ get
ขั้นตอนด้านล่างนี้แสดงขั้นตอนที่ต้องดําเนินการผ่านการลิงก์บัญชีและระบุเวลาที่มีเจตนาที่แตกต่างกัน
- ผู้ใช้มีบัญชีในระบบการตรวจสอบสิทธิ์หรือไม่ (ผู้ใช้ตัดสินใจเลือกโดยเลือก "ใช่" หรือ "ไม่")
- ใช่ : ผู้ใช้จะใช้อีเมลที่เชื่อมโยงกับบัญชี Google เพื่อลงชื่อเข้าใช้แพลตฟอร์มของคุณหรือไม่ (ผู้ใช้ตัดสินใจเลือกโดยเลือก "ใช่" หรือ "ไม่")
- ใช่ : ผู้ใช้มีบัญชีที่ตรงกันในระบบการตรวจสอบสิทธิ์หรือไม่ (ระบบจะเรียกใช้
check intent
เพื่อยืนยัน)- ใช่ : มีการเรียก
get intent
และลิงก์บัญชีหากรับ Intent สําเร็จ - ไม่ : สร้างบัญชีใหม่ใช่ไหม (ผู้ใช้ตัดสินใจเลือกโดยเลือก "ใช่" หรือ "ไม่")
- ใช่ : มีการเรียก
create intent
และลิงก์บัญชีหากสร้าง Intent คืนสําเร็จ - ไม่ : ระบบจะเรียกใช้ขั้นตอน OAuth ในเว็บ ระบบจะนําผู้ใช้ไปยังเบราว์เซอร์ของตน และผู้ใช้จะได้รับตัวเลือกให้ลิงก์กับอีเมลอื่น
- ใช่ : มีการเรียก
- ใช่ : มีการเรียก
- ไม่ : ระบบจะเรียกใช้ขั้นตอน OAuth ในเว็บ ระบบจะนําผู้ใช้ไปยังเบราว์เซอร์ของตน และผู้ใช้จะได้รับตัวเลือกให้ลิงก์กับอีเมลอื่น
- ใช่ : ผู้ใช้มีบัญชีที่ตรงกันในระบบการตรวจสอบสิทธิ์หรือไม่ (ระบบจะเรียกใช้
- ไม่ : ผู้ใช้มีบัญชีที่ตรงกันในระบบการตรวจสอบสิทธิ์หรือไม่ (ระบบจะเรียกใช้
check intent
เพื่อยืนยัน)- ใช่ : มีการเรียก
get intent
และลิงก์บัญชีหากรับ Intent สําเร็จ - ไม่ : ระบบจะเรียกใช้
create intent
และระบบจะลิงก์บัญชีหากสร้าง Intent คืนสําเร็จ
- ใช่ : มีการเรียก
- ใช่ : ผู้ใช้จะใช้อีเมลที่เชื่อมโยงกับบัญชี Google เพื่อลงชื่อเข้าใช้แพลตฟอร์มของคุณหรือไม่ (ผู้ใช้ตัดสินใจเลือกโดยเลือก "ใช่" หรือ "ไม่")
Check for an existing user account (check intent)
After the user gives consent to access their Google profile, Google sends a request that contains a signed assertion of the Google user's identity. The assertion contains information that includes the user's Google Account ID, name, and email address. The token exchange endpoint configured for your project handles that request.
If the corresponding Google account is already present in your authentication
system, your token exchange endpoint responds with account_found=true
. If the
Google account doesn't match an existing user, your token exchange endpoint
returns an HTTP 404 Not Found error with account_found=false
.
The request has the following form:
POST /token HTTP/1.1 Host: oauth2.example.com Content-Type: application/x-www-form-urlencoded grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&intent=check&assertion=JWT&scope=SCOPES
Your token exchange endpoint must be able to handle the following parameters:
Token endpoint parameters | |
---|---|
intent |
For these requests, the value of this parameter is
check . |
grant_type |
The type of token being exchanged. For these requests, this
parameter has the value urn:ietf:params:oauth:grant-type:jwt-bearer . |
assertion |
A JSON Web Token (JWT) that provides a signed assertion of the Google user's identity. The JWT contains information that includes the user's Google Account ID, name, and email address. |
To respond to the check
intent requests, your token exchange endpoint must perform the following steps:
- Validate and decode the JWT assertion.
- Check if the Google account is already present in your authentication system.
ตรวจสอบและถอดรหัสการยืนยัน JWT
คุณสามารถตรวจสอบและถอดรหัสการยืนยัน JWT ได้โดยใช้ ไลบรารีการถอดรหัส JWT สำหรับภาษาของคุณ ใช้คีย์สาธารณะของ Google ซึ่งมีให้ในรูปแบบ JWK หรือ PEM เพื่อตรวจสอบลายเซ็นของโทเค็น
เมื่อถอดรหัสการยืนยัน JWT จะมีลักษณะดังตัวอย่างต่อไปนี้:
{ "sub": "1234567890", // The unique ID of the user's Google Account "iss": "https://accounts.google.com", // The assertion's issuer "aud": "123-abc.apps.googleusercontent.com", // Your server's client ID "iat": 233366400, // Unix timestamp of the assertion's creation time "exp": 233370000, // Unix timestamp of the assertion's expiration time "name": "Jan Jansen", "given_name": "Jan", "family_name": "Jansen", "email": "jan@gmail.com", // If present, the user's email address "email_verified": true, // true, if Google has verified the email address "hd": "example.com", // If present, the host domain of the user's GSuite email address // If present, a URL to user's profile picture "picture": "https://lh3.googleusercontent.com/a-/AOh14GjlTnZKHAeb94A-FmEbwZv7uJD986VOF1mJGb2YYQ", "locale": "en_US" // User's locale, from browser or phone settings }
นอกจากนี้ในการตรวจสอบลายเซ็นของโทเค็นการตรวจสอบว่า บริษัท ผู้ออกหลักทรัพย์ยืนยันของ ( iss
ฟิลด์) เป็น https://accounts.google.com
ว่าผู้ชม ( aud
ฟิลด์) เป็นรหัสลูกค้าที่ได้รับมอบหมายของคุณและที่โทเค็นยังไม่หมดอายุ ( exp
ฟิลด์).
การใช้ช่อง email
email_verified
และ hd
เพื่อตรวจสอบว่า Google โฮสต์และเชื่อถือได้สำหรับที่อยู่อีเมล ในกรณีที่ Google มีสิทธิ์ในขณะนี้ผู้ใช้ทราบว่าเป็นเจ้าของบัญชีที่ถูกต้องและคุณสามารถข้ามรหัสผ่านหรือวิธีการท้าทายอื่น ๆ ได้ มิฉะนั้นสามารถใช้วิธีการเหล่านี้เพื่อยืนยันบัญชีก่อนการเชื่อมโยง
กรณีที่ Google เชื่อถือได้:
-
email
มีคำต่อท้าย@gmail.com
นี่คือบัญชี Gmail -
email_verified
เป็นจริงและตั้งค่าhd
แล้วนี่คือบัญชี G Suite
ผู้ใช้สามารถลงทะเบียนบัญชี Google ได้โดยไม่ต้องใช้ Gmail หรือ G Suite เมื่อ email
ไม่มีคำต่อท้าย @gmail.com
และ hd
ไม่มี Google ไม่ได้รับอนุญาตและขอแนะนำให้ใช้รหัสผ่านหรือวิธีการท้าทายอื่น ๆ ในการยืนยันผู้ใช้ email_verfied
อาจเป็นจริงได้เช่นกันเนื่องจาก Google ได้ยืนยันผู้ใช้ในตอนแรกเมื่อสร้างบัญชี Google อย่างไรก็ตามความเป็นเจ้าของบัญชีอีเมลของบุคคลที่สามอาจมีการเปลี่ยนแปลง
Check if the Google account is already present in your authentication system
Check whether either of the following conditions are true:
- The Google Account ID, found in the assertion's
sub
field, is in your user database. - The email address in the assertion matches a user in your user database.
If either condition is true, the user has already signed up. In that case, return a response like the following:
HTTP/1.1 200 Success Content-Type: application/json;charset=UTF-8 { "account_found":"true", }
If neither the Google Account ID nor the email address specified in the
assertion matches a user in your database, the user hasn't signed up yet. In
this case, your token exchange endpoint needs to reply with a HTTP 404 error
that specifies "account_found": "false"
, as in the following example:
HTTP/1.1 404 Not found Content-Type: application/json;charset=UTF-8 { "account_found":"false", }
จัดการการเชื่อมโยงอัตโนมัติ (รับความตั้งใจ)
หลังจากที่ผู้ใช้ให้ความยินยอมในการเข้าถึงโปรไฟล์ Google ของตนแล้ว Google จะส่งคำขอที่มีการยืนยันตัวตนของผู้ใช้ Google ที่ลงนามแล้ว การยืนยันมีข้อมูลที่ประกอบด้วยรหัสบัญชี Google ชื่อและที่อยู่อีเมลของผู้ใช้ จุดสิ้นสุดการแลกเปลี่ยนโทเค็นที่กำหนดค่าไว้สำหรับโปรเจ็กต์ของคุณจัดการกับคำขอนั้น
หากมีบัญชี Google ที่เกี่ยวข้องในระบบการตรวจสอบสิทธิ์ของคุณแล้ว ปลายทางการแลกเปลี่ยนโทเค็นของคุณจะส่งคืนโทเค็นให้กับผู้ใช้ หากบัญชี Google ที่ไม่ตรงกับผู้ใช้ที่มีอยู่ปลายทางแลกเปลี่ยนโทเค็นของคุณส่งกลับ linking_error
ข้อผิดพลาดและไม่จำเป็น login_hint
คำขอมีรูปแบบดังต่อไปนี้:
POST /token HTTP/1.1 Host: oauth2.example.com Content-Type: application/x-www-form-urlencoded grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&intent=get&assertion=JWT&scope=SCOPES
จุดสิ้นสุดการแลกเปลี่ยนโทเค็นของคุณต้องสามารถจัดการพารามิเตอร์ต่อไปนี้:
พารามิเตอร์ปลายทางของโทเค็น | |
---|---|
intent | สำหรับการร้องขอเหล่านี้ค่าของพารามิเตอร์นี้คือ get |
grant_type | ประเภทของโทเค็นที่แลกเปลี่ยน สำหรับการร้องขอเหล่านี้พารามิเตอร์นี้มีค่า urn:ietf:params:oauth:grant-type:jwt-bearer |
assertion | JSON Web Token (JWT) ที่ให้การยืนยันตัวตนของผู้ใช้ Google ที่มีการลงชื่อ JWT ประกอบด้วยข้อมูลที่มี ID บัญชี Google ชื่อและที่อยู่อีเมลของผู้ใช้ |
scope | ตัวเลือก: ขอบเขตใด ๆ ที่คุณได้กำหนดค่า Google เพื่อการร้องขอจากผู้ใช้ |
เพื่อตอบสนองต่อ get
การร้องขอเจตนาปลายทางแลกเปลี่ยนโทเค็นของคุณจะต้องดำเนินการขั้นตอนต่อไปนี้:
- ตรวจสอบและถอดรหัสการยืนยัน JWT
- ตรวจสอบว่าบัญชี Google มีอยู่แล้วในระบบการตรวจสอบของคุณ
ตรวจสอบและถอดรหัสการยืนยัน JWT
คุณสามารถตรวจสอบและถอดรหัสการยืนยัน JWT ได้โดยใช้ ไลบรารีการถอดรหัส JWT สำหรับภาษาของคุณ ใช้คีย์สาธารณะของ Google ซึ่งมีให้ในรูปแบบ JWK หรือ PEM เพื่อตรวจสอบลายเซ็นของโทเค็น
เมื่อถอดรหัสการยืนยัน JWT จะมีลักษณะดังตัวอย่างต่อไปนี้:
{ "sub": "1234567890", // The unique ID of the user's Google Account "iss": "https://accounts.google.com", // The assertion's issuer "aud": "123-abc.apps.googleusercontent.com", // Your server's client ID "iat": 233366400, // Unix timestamp of the assertion's creation time "exp": 233370000, // Unix timestamp of the assertion's expiration time "name": "Jan Jansen", "given_name": "Jan", "family_name": "Jansen", "email": "jan@gmail.com", // If present, the user's email address "email_verified": true, // true, if Google has verified the email address "hd": "example.com", // If present, the host domain of the user's GSuite email address // If present, a URL to user's profile picture "picture": "https://lh3.googleusercontent.com/a-/AOh14GjlTnZKHAeb94A-FmEbwZv7uJD986VOF1mJGb2YYQ", "locale": "en_US" // User's locale, from browser or phone settings }
นอกจากนี้ในการตรวจสอบลายเซ็นของโทเค็นการตรวจสอบว่า บริษัท ผู้ออกหลักทรัพย์ยืนยันของ ( iss
ฟิลด์) เป็น https://accounts.google.com
ว่าผู้ชม ( aud
ฟิลด์) เป็นรหัสลูกค้าที่ได้รับมอบหมายของคุณและที่โทเค็นยังไม่หมดอายุ ( exp
ฟิลด์).
การใช้ช่อง email
email_verified
และ hd
เพื่อตรวจสอบว่า Google โฮสต์และเชื่อถือได้สำหรับที่อยู่อีเมล ในกรณีที่ Google มีสิทธิ์ในขณะนี้ผู้ใช้ทราบว่าเป็นเจ้าของบัญชีที่ถูกต้องและคุณสามารถข้ามรหัสผ่านหรือวิธีการท้าทายอื่น ๆ ได้ มิฉะนั้นสามารถใช้วิธีการเหล่านี้เพื่อยืนยันบัญชีก่อนการเชื่อมโยง
กรณีที่ Google เชื่อถือได้:
-
email
มีคำต่อท้าย@gmail.com
นี่คือบัญชี Gmail -
email_verified
เป็นจริงและตั้งค่าhd
แล้วนี่คือบัญชี G Suite
ผู้ใช้สามารถลงทะเบียนบัญชี Google ได้โดยไม่ต้องใช้ Gmail หรือ G Suite เมื่อ email
ไม่มีคำต่อท้าย @gmail.com
และ hd
ไม่มี Google ไม่ได้รับอนุญาตและขอแนะนำให้ใช้รหัสผ่านหรือวิธีการท้าทายอื่น ๆ ในการยืนยันผู้ใช้ email_verfied
อาจเป็นจริงได้เช่นกันเนื่องจาก Google ได้ยืนยันผู้ใช้ในตอนแรกเมื่อสร้างบัญชี Google อย่างไรก็ตามความเป็นเจ้าของบัญชีอีเมลของบุคคลที่สามอาจมีการเปลี่ยนแปลง
ตรวจสอบว่าบัญชี Google มีอยู่แล้วในระบบการตรวจสอบของคุณ
ตรวจสอบว่าเงื่อนไขใด ๆ ต่อไปนี้เป็นจริง:
- หมายเลขบัญชี Google ที่พบในการยืนยันของ
sub
ข้อมูลที่อยู่ในฐานข้อมูลผู้ใช้ของคุณ - ที่อยู่อีเมลในการยืนยันตรงกับผู้ใช้ในฐานข้อมูลผู้ใช้ของคุณ
หากบัญชีพบสำหรับผู้ใช้ในการเข้าถึงโทเค็นออกและส่งกลับค่าในวัตถุ JSON ในร่างกายของการตอบสนองของคุณ HTTPS เช่นในตัวอย่างต่อไปนี้:
{ "token_type": "Bearer", "access_token": "ACCESS_TOKEN", "expires_in": SECONDS_TO_EXPIRATION }
ในบางกรณี การเชื่อมโยงบัญชีโดยใช้โทเค็น ID อาจล้มเหลวสำหรับผู้ใช้ ถ้ามันไม่ว่าจะด้วยเหตุผลใด ๆ ปลายทางแลกเปลี่ยนโทเค็นของคุณต้องตอบด้วย HTTP 401 ข้อผิดพลาดที่ระบุ error=linking_error
เช่นการแสดงตัวอย่างต่อไปนี้:
HTTP/1.1 401 Unauthorized Content-Type: application/json;charset=UTF-8 { "error":"linking_error", "login_hint":"foo@bar.com" }
เมื่อ Google ได้รับการตอบสนองข้อผิดพลาด 401 กับ linking_error
Google จะส่งผู้ใช้ไปยังปลายทางอนุมัติของคุณกับ login_hint
เป็นพารามิเตอร์ ผู้ใช้ทำการลิงก์บัญชีให้เสร็จสิ้นโดยใช้ขั้นตอนการเชื่อมโยง OAuth ในเบราว์เซอร์
Handle account creation via Google Sign-In (create intent)
When a user needs to create an account on your service, Google makes a request
to your token exchange endpoint that specifies intent=create
.
The request has the following form:
POST /token HTTP/1.1 Host: oauth2.example.com Content-Type: application/x-www-form-urlencoded response_type=token&grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&scope=SCOPES&intent=create&assertion=JWT
Your token exchange endpoint must able to handle the following parameters:
Token endpoint parameters | |
---|---|
intent |
For these requests, the value of this parameter is create . |
grant_type |
The type of token being exchanged. For these requests, this
parameter has the value urn:ietf:params:oauth:grant-type:jwt-bearer . |
assertion |
A JSON Web Token (JWT) that provides a signed assertion of the Google user's identity. The JWT contains information that includes the user's Google Account ID, name, and email address. |
The JWT within the assertion
parameter contains the user's Google Account ID,
name, and email address, which you can use to create a new account on your
service.
To respond to the create
intent requests, your token exchange endpoint must perform the following steps:
- Validate and decode the JWT assertion.
- Validate user information and create new account.
ตรวจสอบและถอดรหัสการยืนยัน JWT
คุณสามารถตรวจสอบและถอดรหัสการยืนยัน JWT ได้โดยใช้ ไลบรารีการถอดรหัส JWT สำหรับภาษาของคุณ ใช้คีย์สาธารณะของ Google ซึ่งมีให้ในรูปแบบ JWK หรือ PEM เพื่อตรวจสอบลายเซ็นของโทเค็น
เมื่อถอดรหัสการยืนยัน JWT จะมีลักษณะดังตัวอย่างต่อไปนี้:
{ "sub": "1234567890", // The unique ID of the user's Google Account "iss": "https://accounts.google.com", // The assertion's issuer "aud": "123-abc.apps.googleusercontent.com", // Your server's client ID "iat": 233366400, // Unix timestamp of the assertion's creation time "exp": 233370000, // Unix timestamp of the assertion's expiration time "name": "Jan Jansen", "given_name": "Jan", "family_name": "Jansen", "email": "jan@gmail.com", // If present, the user's email address "email_verified": true, // true, if Google has verified the email address "hd": "example.com", // If present, the host domain of the user's GSuite email address // If present, a URL to user's profile picture "picture": "https://lh3.googleusercontent.com/a-/AOh14GjlTnZKHAeb94A-FmEbwZv7uJD986VOF1mJGb2YYQ", "locale": "en_US" // User's locale, from browser or phone settings }
นอกจากนี้ในการตรวจสอบลายเซ็นของโทเค็นการตรวจสอบว่า บริษัท ผู้ออกหลักทรัพย์ยืนยันของ ( iss
ฟิลด์) เป็น https://accounts.google.com
ว่าผู้ชม ( aud
ฟิลด์) เป็นรหัสลูกค้าที่ได้รับมอบหมายของคุณและที่โทเค็นยังไม่หมดอายุ ( exp
ฟิลด์).
การใช้ช่อง email
email_verified
และ hd
เพื่อตรวจสอบว่า Google โฮสต์และเชื่อถือได้สำหรับที่อยู่อีเมล ในกรณีที่ Google มีสิทธิ์ในขณะนี้ผู้ใช้ทราบว่าเป็นเจ้าของบัญชีที่ถูกต้องและคุณสามารถข้ามรหัสผ่านหรือวิธีการท้าทายอื่น ๆ ได้ มิฉะนั้นสามารถใช้วิธีการเหล่านี้เพื่อยืนยันบัญชีก่อนการเชื่อมโยง
กรณีที่ Google เชื่อถือได้:
-
email
มีคำต่อท้าย@gmail.com
นี่คือบัญชี Gmail -
email_verified
เป็นจริงและตั้งค่าhd
แล้วนี่คือบัญชี G Suite
ผู้ใช้สามารถลงทะเบียนบัญชี Google ได้โดยไม่ต้องใช้ Gmail หรือ G Suite เมื่อ email
ไม่มีคำต่อท้าย @gmail.com
และ hd
ไม่มี Google ไม่ได้รับอนุญาตและขอแนะนำให้ใช้รหัสผ่านหรือวิธีการท้าทายอื่น ๆ ในการยืนยันผู้ใช้ email_verfied
อาจเป็นจริงได้เช่นกันเนื่องจาก Google ได้ยืนยันผู้ใช้ในตอนแรกเมื่อสร้างบัญชี Google อย่างไรก็ตามความเป็นเจ้าของบัญชีอีเมลของบุคคลที่สามอาจมีการเปลี่ยนแปลง
Validate user information and create new account
Check whether either of the following conditions are true:
- The Google Account ID, found in the assertion's
sub
field, is in your user database. - The email address in the assertion matches a user in your user database.
If either condition is true, prompt the user to link their existing account
with their Google Account. To do so, respond to the request with an HTTP 401 error
that specifies error=linking_error
and gives the user's email address as the
login_hint
. The following is a sample response:
HTTP/1.1 401 Unauthorized Content-Type: application/json;charset=UTF-8 { "error":"linking_error", "login_hint":"foo@bar.com" }
When Google receives a 401 error response with linking_error
, Google sends
the user to your authorization endpoint with login_hint
as a parameter. The
user completes account linking using the OAuth linking flow in their browser.
If neither condition is true, create a new user account with the information provided in the JWT. New accounts don't typically have a password set. It's recommended that you add Google Sign-In to other platforms to enable users to log in with Google across the surfaces of your application. Alternatively, you can email the user a link that starts your password recovery flow to allow the user to set a password to sign in on other platforms.
When the creation is completed, issue an access token and return the values in a JSON object in the body of your HTTPS response, like in the following example:
{ "token_type": "Bearer", "access_token": "ACCESS_TOKEN", "expires_in": SECONDS_TO_EXPIRATION }
รับรหัสไคลเอ็นต์ของ Google API
คุณจะต้องระบุรหัสไคลเอ็นต์ของ Google API ในระหว่างขั้นตอนการลงทะเบียนการลิงก์บัญชี
หากต้องการรับรหัสไคลเอ็นต์ API โดยใช้โปรเจ็กต์ที่คุณสร้างขณะทําตามขั้นตอนการลิงก์ OAuth โดยทําตามขั้นตอนต่อไปนี้
- เปิดหน้าข้อมูลเข้าสู่ระบบของคอนโซล Google API
สร้างหรือเลือกโปรเจ็กต์ Google APIs
หากโปรเจ็กต์ไม่มีรหัสไคลเอ็นต์สําหรับประเภทเว็บแอปพลิเคชัน ให้คลิกสร้างข้อมูลเข้าสู่ระบบ > รหัสไคลเอ็นต์ OAuth เพื่อสร้าง อย่าลืมใส่โดเมนของเว็บไซต์ในช่องต้นทางของ JavaScript ที่ได้รับอนุญาต เมื่อทําการทดสอบหรือการพัฒนาในเครื่อง คุณต้องเพิ่มทั้ง
http://localhost
และhttp://localhost:<port_number>
ในช่อง ต้นทางของ JavaScript ที่ได้รับอนุญาต
กําลังตรวจสอบการติดตั้งใช้งาน
You can validate your implementation by using the OAuth 2.0 Playground tool.
In the tool, do the following steps:
- Click Configuration to open the OAuth 2.0 Configuration window.
- In the OAuth flow field, select Client-side.
- In the OAuth Endpoints field, select Custom.
- Specify your OAuth 2.0 endpoint and the client ID you assigned to Google in the corresponding fields.
- 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.
- 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:
- Click the Sign-in with Google button.
- Choose the account you'd like to link.
- Enter the service ID.
- Optionally enter one or more scopes that you will request access for.
- Click Start Demo.
- When prompted, confirm that you may consent and deny the linking request.
- Confirm that you are redirected to your platform.