1. บทนำ
ในโมเดลการยืนยันตัวตนแบบ client-server ดั้งเดิม client จะขอใช้ทรัพยากรที่จำกัดการเข้าถึง (protected resource) บน server โดยยืนยันตัวตนกับ server ด้วย credentials ของ resource owner เมื่อต้องการให้แอปพลิเคชันของบุคคลที่สามเข้าถึงทรัพยากรที่จำกัดการเข้าถึงเหล่านี้ resource owner ก็ต้องแบ่งปัน credentials ของตนให้บุคคลที่สาม ซึ่งสร้างปัญหาและข้อจำกัดหลายอย่าง:
-
แอปพลิเคชันของบุคคลที่สามต้องเก็บ credentials ของ resource owner ไว้ใช้ภายหลัง ซึ่งโดยทั่วไปคือรหัสผ่านที่เก็บเป็นข้อความธรรมดา (clear-text)
-
Server ต้องรองรับการยืนยันตัวตนด้วยรหัสผ่าน แม้รหัสผ่านจะมีจุดอ่อนด้านความปลอดภัยอยู่ในตัว
-
แอปพลิเคชันของบุคคลที่สามได้สิทธิ์เข้าถึง protected resource ของ resource owner กว้างเกินไป ทำให้ resource owner ไม่มีทางจำกัดระยะเวลา หรือจำกัดการเข้าถึงให้เหลือเพียงทรัพยากรบางส่วนได้
-
resource owner ไม่สามารถเพิกถอนสิทธิ์ของบุคคลที่สามรายใดรายหนึ่งได้ โดยไม่เพิกถอนสิทธิ์ของบุคคลที่สามทุกราย และต้องทำด้วยการเปลี่ยนรหัสผ่านของบุคคลที่สามนั้น
-
ถ้าแอปพลิเคชันของบุคคลที่สามรายใดถูกบุกรุก รหัสผ่านของ end-user และข้อมูลทั้งหมดที่รหัสผ่านนั้นปกป้องอยู่ก็ถูกบุกรุกไปด้วย
OAuth แก้ปัญหาเหล่านี้ด้วยการเพิ่ม authorization layer และแยกบทบาทของ client ออกจากบทบาทของ resource owner ใน OAuth, client จะขอเข้าถึงทรัพยากรที่ resource owner ควบคุมและ resource server เป็นผู้โฮสต์ และจะได้รับชุด credentials ที่ต่างจากของ resource owner
แทนที่จะใช้ credentials ของ resource owner เพื่อเข้าถึง protected resource client จะขอ access token ซึ่งเป็น string ที่ระบุ scope, อายุการใช้งาน และคุณสมบัติอื่นของการเข้าถึง authorization server จะออก access token ให้ client ของบุคคลที่สามด้วยความเห็นชอบของ resource owner จากนั้น client ใช้ access token นี้เข้าถึง protected resource ที่ resource server โฮสต์อยู่
ตัวอย่างเช่น end-user (resource owner) สามารถอนุญาตให้บริการสั่งพิมพ์ (client) เข้าถึงรูปถ่ายที่เป็น protected resource ของเธอซึ่งเก็บอยู่ในบริการแชร์รูป (resource server) โดยไม่ต้องบอกชื่อผู้ใช้และรหัสผ่านของเธอให้บริการสั่งพิมพ์ แต่เธอจะยืนยันตัวตนโดยตรงกับ server ที่บริการแชร์รูปไว้วางใจ (authorization server) ซึ่งจะออก credentials เฉพาะสำหรับการมอบสิทธิ์ครั้งนี้ (access token) ให้บริการสั่งพิมพ์
ข้อกำหนดนี้ออกแบบมาเพื่อใช้กับ HTTP ([RFC2616]) การใช้ OAuth บนโปรโตคอลอื่นที่ไม่ใช่ HTTP อยู่นอกขอบเขตของข้อกำหนดนี้
โปรโตคอล OAuth 1.0 ([RFC5849]) ซึ่งเผยแพร่เป็นเอกสารเพื่อเป็นข้อมูล (informational) เกิดจากความพยายามเฉพาะกิจของชุมชนขนาดเล็ก ข้อกำหนดฉบับ Standards Track นี้ต่อยอดจากประสบการณ์การใช้งาน OAuth 1.0 รวมถึง use case เพิ่มเติมและข้อกำหนดด้านการขยายระบบที่รวบรวมจากชุมชน IETF วงกว้าง OAuth 2.0 ไม่รองรับ OAuth 1.0 แบบย้อนหลัง (backward compatible) สองเวอร์ชันอยู่ร่วมกันบนเครือข่ายได้ และผู้พัฒนาอาจเลือกรองรับทั้งสองเวอร์ชัน อย่างไรก็ตาม ข้อกำหนดนี้ตั้งใจให้ระบบใหม่รองรับ OAuth 2.0 ตามที่ระบุในเอกสารนี้ และใช้ OAuth 1.0 เพียงเพื่อรองรับระบบที่ใช้งานอยู่เดิม OAuth 2.0 มีรายละเอียดการ implement ร่วมกับ OAuth 1.0 น้อยมาก ผู้พัฒนาที่คุ้นเคยกับ OAuth 1.0 จึงควรอ่านเอกสารนี้โดยไม่ต้องคาดเดาเกี่ยวกับโครงสร้างและรายละเอียดของมัน
1.1. บทบาท
OAuth กำหนดบทบาทไว้สี่บทบาท:
-
resource owner: เอนทิตีที่สามารถให้สิทธิ์เข้าถึง protected resource ได้ ถ้า resource owner เป็นบุคคล จะเรียกว่า end-user
-
resource server: server ที่โฮสต์ protected resource และรับ protected resource request ที่ใช้ access token แล้วตอบกลับได้
-
client: แอปพลิเคชันที่ส่ง protected resource request ในนามของ resource owner และด้วยการอนุญาตของ resource owner คำว่า "client" ไม่ได้บ่งบอกลักษณะการ implement ใด ๆ (เช่น แอปพลิเคชันจะรันบน server, เดสก์ท็อป หรืออุปกรณ์อื่นก็ได้)
-
authorization server: server ที่ออก access token ให้ client หลังจากยืนยันตัวตนของ resource owner และได้รับการอนุญาตสำเร็จแล้ว
การโต้ตอบระหว่าง authorization server กับ resource server อยู่นอกขอบเขตของข้อกำหนดนี้ authorization server อาจเป็น server เดียวกับ resource server หรือแยกเป็นอีกหน่วยหนึ่งก็ได้ authorization server เพียงตัวเดียวอาจออก access token ที่ resource server หลายตัวยอมรับ
1.2. ลำดับการทำงานของโปรโตคอล
sequenceDiagram
participant C as Client
participant RO as Resource Owner
participant AS as Authorization Server
participant RS as Resource Server
C->>RO: (A) Authorization Request
RO-->>C: (B) Authorization Grant
C->>AS: (C) Authorization Grant
AS-->>C: (D) Access Token
C->>RS: (E) Access Token
RS-->>C: (F) Protected Resource
Figure 1: ลำดับการทำงานของโปรโตคอลแบบนามธรรม
flow แบบนามธรรมของ OAuth 2.0 ใน Figure 1 แสดงการโต้ตอบระหว่างบทบาททั้งสี่ และมีขั้นตอนดังนี้:
-
(A) client ขออนุญาตจาก resource owner authorization request อาจส่งตรงไปยัง resource owner (ตามที่แสดงในรูป) หรือจะดีกว่าถ้าส่งอ้อมผ่าน authorization server ที่ทำหน้าที่เป็นตัวกลาง
-
(B) client ได้รับ authorization grant ซึ่งเป็น credential ที่แสดงการอนุญาตของ resource owner โดยอยู่ในรูปแบบของ grant type หนึ่งในสี่แบบที่ข้อกำหนดนี้กำหนด หรือของ extension grant type grant type ของ authorization grant ขึ้นอยู่กับวิธีที่ client ใช้ขอการอนุญาต และชนิดที่ authorization server รองรับ
-
(C) client ขอ access token โดยยืนยันตัวตนกับ authorization server และแสดง authorization grant
-
(D) authorization server ยืนยันตัวตนของ client และตรวจสอบ authorization grant ถ้าถูกต้องจึงออก access token
-
(E) client ขอ protected resource จาก resource server และยืนยันตัวตนด้วยการแสดง access token
-
(F) resource server ตรวจสอบ access token ถ้าถูกต้องจึงให้บริการ request นั้น
วิธีที่ควรใช้ให้ client ได้รับ authorization grant จาก resource owner (ขั้นตอน (A) และ (B)) คือใช้ authorization server เป็นตัวกลาง ดังที่แสดงใน Figure 3 ใน Section 4.1.
1.3. Authorization Grant
authorization grant คือ credential ที่แสดงการอนุญาตของ resource owner (ให้เข้าถึง protected resource ของตน) ซึ่ง client ใช้เพื่อขอ access token ข้อกำหนดนี้กำหนด grant type ไว้สี่แบบ ได้แก่ authorization code, implicit, resource owner password credentials และ client credentials รวมถึงกลไกขยายสำหรับกำหนดชนิดเพิ่มเติม
1.3.1. Authorization Code
authorization code ได้มาโดยใช้ authorization server เป็นตัวกลางระหว่าง client กับ resource owner client ไม่ได้ขอการอนุญาตจาก resource owner โดยตรง แต่ส่ง resource owner ไปยัง authorization server (ผ่าน user-agent ตามที่นิยามใน [RFC2616]) แล้ว authorization server จะส่ง resource owner กลับมาที่ client พร้อม authorization code
ก่อนส่ง resource owner กลับไปที่ client พร้อม authorization code authorization server จะยืนยันตัวตนของ resource owner และขอการอนุญาต เนื่องจาก resource owner ยืนยันตัวตนกับ authorization server เท่านั้น credentials ของ resource owner จึงไม่เคยถูกแชร์ให้ client
authorization code มีข้อดีด้านความปลอดภัยที่สำคัญหลายอย่าง เช่น สามารถยืนยันตัวตนของ client ได้ และส่ง access token ตรงไปยัง client โดยไม่ผ่าน user-agent ของ resource owner ซึ่งอาจทำให้ access token ถูกเปิดเผยแก่ผู้อื่น รวมถึง resource owner เอง
1.3.2. Implicit
implicit grant คือ authorization code flow แบบย่อที่ปรับให้เหมาะกับ client ที่เขียนอยู่ใน browser ด้วยภาษาสคริปต์ เช่น JavaScript ใน implicit flow client จะได้รับ access token โดยตรง (เป็นผลจากการที่ resource owner อนุญาต) แทนที่จะได้รับ authorization code grant type นี้เรียกว่า implicit เพราะไม่มีการออก credentials ตัวกลาง (เช่น authorization code) เพื่อนำไปแลก access token ภายหลัง
เมื่อออก access token ใน implicit grant flow authorization server ไม่ได้ยืนยันตัวตนของ client ในบางกรณี อาจตรวจสอบตัวตนของ client ได้จาก redirection URI ที่ใช้ส่ง access token ให้ client access token อาจถูกเปิดเผยแก่ resource owner หรือแอปพลิเคชันอื่นที่เข้าถึง user-agent ของ resource owner ได้
implicit grant ช่วยให้ client บางประเภท (เช่น client ที่ implement เป็นแอปพลิเคชันใน browser) ตอบสนองได้เร็วและมีประสิทธิภาพขึ้น เพราะลดจำนวน round trip ที่ต้องใช้เพื่อขอ access token อย่างไรก็ตาม ควรชั่งน้ำหนักความสะดวกนี้กับผลด้านความปลอดภัยของ implicit grant เช่นที่อธิบายใน Sections 10.3 และ 10.16 โดยเฉพาะเมื่อมี authorization code grant type ให้เลือกใช้
1.3.3. Resource Owner Password Credentials
resource owner password credentials (ได้แก่ ชื่อผู้ใช้และรหัสผ่าน) ใช้เป็น authorization grant โดยตรงเพื่อขอ access token ได้ ควรใช้ credentials นี้เฉพาะเมื่อ resource owner กับ client ไว้วางใจกันในระดับสูง (เช่น client เป็นส่วนหนึ่งของระบบปฏิบัติการของอุปกรณ์ หรือเป็นแอปพลิเคชันที่มีสิทธิ์สูง) และเมื่อไม่มี authorization grant type อื่นให้ใช้ (เช่น authorization code)
แม้ grant type นี้ต้องให้ client เข้าถึง credentials ของ resource owner โดยตรง แต่ credentials เหล่านั้นถูกใช้เพียง request เดียวแล้วแลกเป็น access token grant type นี้ทำให้ client ไม่ต้องเก็บ credentials ของ resource owner ไว้ใช้ภายหลัง เพราะสามารถแลก credentials เป็น access token หรือ refresh token ที่มีอายุยาวได้
1.3.4. Client Credentials
client credentials (หรือ client authentication รูปแบบอื่น) ใช้เป็น authorization grant ได้เมื่อ scope ของการอนุญาตจำกัดอยู่ที่ protected resource ซึ่งอยู่ในความควบคุมของ client เอง หรือ protected resource ที่ตกลงไว้กับ authorization server ล่วงหน้า โดยทั่วไป client credentials ถูกใช้เป็น authorization grant เมื่อ client ทำงานในนามของตนเอง (client เป็น resource owner ด้วย) หรือขอเข้าถึง protected resource ตามการอนุญาตที่ตกลงไว้กับ authorization server ล่วงหน้า
1.4. Access Token
access token คือ credentials ที่ใช้เข้าถึง protected resource โดยเป็น string ที่แทนการอนุญาตซึ่งออกให้ client ตัว string นี้มักเป็นแบบ opaque สำหรับ client (client อ่านความหมายภายในไม่ได้) token แทน scope และระยะเวลาการเข้าถึงที่เฉพาะเจาะจง ซึ่ง resource owner เป็นผู้ให้ และ resource server กับ authorization server เป็นผู้บังคับใช้
token อาจเป็นตัวระบุที่ใช้ดึงข้อมูลการอนุญาต หรืออาจบรรจุข้อมูลการอนุญาตไว้ในตัวเองในรูปแบบที่ตรวจสอบได้ (เช่น token string ที่ประกอบด้วยข้อมูลบางส่วนกับ signature) client อาจต้องใช้ credentials สำหรับการยืนยันตัวตนเพิ่มเติมจึงจะใช้ token ได้ ซึ่งอยู่นอกขอบเขตของข้อกำหนดนี้
access token ทำหน้าที่เป็นชั้น abstraction ที่แทนรูปแบบการอนุญาตต่าง ๆ (เช่น ชื่อผู้ใช้และรหัสผ่าน) ด้วย token เดียวที่ resource server เข้าใจ abstraction นี้ทำให้ออก access token ที่มีข้อจำกัดมากกว่า authorization grant ที่ใช้ขอมันได้ และทำให้ resource server ไม่ต้องเข้าใจวิธียืนยันตัวตนที่หลากหลาย
access token อาจมีรูปแบบ โครงสร้าง และวิธีใช้งาน (เช่น คุณสมบัติด้านการเข้ารหัส) ต่างกันไปตามข้อกำหนดด้านความปลอดภัยของ resource server คุณสมบัติของ access token และวิธีเข้าถึง protected resource อยู่นอกขอบเขตของข้อกำหนดนี้ และกำหนดไว้ในข้อกำหนดประกอบอื่น เช่น [RFC6750]
1.5. Refresh Token
refresh token คือ credentials ที่ใช้ขอ access token authorization server ออก refresh token ให้ client เพื่อใช้ขอ access token ใหม่เมื่อ access token ปัจจุบันใช้ไม่ได้หรือหมดอายุ หรือใช้ขอ access token เพิ่มที่มี scope เท่าเดิมหรือแคบกว่า (access token อาจมีอายุสั้นกว่าและมีสิทธิ์น้อยกว่าที่ resource owner อนุญาตไว้) การออก refresh token เป็นทางเลือกที่ authorization server ตัดสินใจเอง ถ้า authorization server ออก refresh token ก็จะรวมมาตอนออก access token (คือขั้นตอน (D) ใน Figure 1)
refresh token คือ string ที่แทนการอนุญาตที่ resource owner ให้แก่ client ตัว string นี้มักเป็นแบบ opaque สำหรับ client token นี้เป็นตัวระบุที่ใช้ดึงข้อมูลการอนุญาต refresh token ต่างจาก access token ตรงที่ออกแบบให้ใช้กับ authorization server เท่านั้น และไม่เคยถูกส่งไปยัง resource server
sequenceDiagram
participant C as Client
participant RS as Resource Server
participant AS as Authorization Server
C->>AS: (A) Authorization Grant
AS-->>C: (B) Access Token & Refresh Token
C->>RS: (C) Access Token
RS-->>C: (D) Protected Resource
C->>RS: (E) Access Token
RS-->>C: (F) Invalid Token Error
C->>AS: (G) Refresh Token
AS-->>C: (H) Access Token & Optional Refresh Token
Figure 2: การ refresh access token ที่หมดอายุแล้ว
flow ใน Figure 2 มีขั้นตอนดังนี้:
-
(A) client ขอ access token โดยยืนยันตัวตนกับ authorization server และแสดง authorization grant
-
(B) authorization server ยืนยันตัวตนของ client และตรวจสอบ authorization grant ถ้าถูกต้องจึงออก access token และ refresh token
-
(C) client ส่ง protected resource request ไปยัง resource server โดยแสดง access token
-
(D) resource server ตรวจสอบ access token ถ้าถูกต้องจึงให้บริการ request นั้น
-
(E) ขั้นตอน (C) และ (D) ทำซ้ำไปจนกว่า access token จะหมดอายุ ถ้า client รู้ว่า access token หมดอายุแล้ว จะข้ามไปขั้นตอน (G) ถ้าไม่รู้ ก็จะส่ง protected resource request อีกครั้ง
-
(F) เนื่องจาก access token ใช้ไม่ได้แล้ว resource server จึงตอบกลับเป็น invalid token error
-
(G) client ขอ access token ใหม่โดยยืนยันตัวตนกับ authorization server และแสดง refresh token ข้อกำหนดเรื่อง client authentication ขึ้นอยู่กับประเภทของ client และนโยบายของ authorization server
-
(H) authorization server ยืนยันตัวตนของ client และตรวจสอบ refresh token ถ้าถูกต้องจึงออก access token ใหม่ (และอาจออก refresh token ใหม่ด้วย)
ขั้นตอน (C), (D), (E) และ (F) อยู่นอกขอบเขตของข้อกำหนดนี้ ตามที่อธิบายไว้ใน Section 7
1.6. เวอร์ชันของ TLS
ทุกครั้งที่ข้อกำหนดนี้ใช้ Transport Layer Security (TLS) เวอร์ชัน (หรือหลายเวอร์ชัน) ของ TLS ที่เหมาะสมจะเปลี่ยนไปตามกาลเวลา โดยขึ้นอยู่กับการใช้งานจริงอย่างแพร่หลายและช่องโหว่ด้านความปลอดภัยที่ทราบ ณ เวลาที่เขียนเอกสารนี้ TLS เวอร์ชัน 1.2 [RFC5246] เป็นเวอร์ชันล่าสุด แต่มีผู้ใช้งานน้อยมากและอาจยังนำไป implement ได้ไม่สะดวก ส่วน TLS เวอร์ชัน 1.0 [RFC2246] เป็นเวอร์ชันที่ใช้แพร่หลายที่สุดและจะทำงานร่วมกับระบบอื่นได้กว้างที่สุด
implementation MAY รองรับกลไกความปลอดภัยของ transport layer อื่นเพิ่มเติมได้ ถ้าตรงตามข้อกำหนดด้านความปลอดภัยของตน
1.7. HTTP Redirection
ข้อกำหนดนี้ใช้ HTTP redirection อย่างมาก คือ client หรือ authorization server ส่ง user-agent ของ resource owner ไปยังปลายทางอื่น แม้ตัวอย่างในข้อกำหนดนี้จะใช้ HTTP status code 302 แต่จะใช้วิธีอื่นใดที่ทำได้ผ่าน user-agent เพื่อ redirect ก็ได้ และถือเป็นรายละเอียดของการ implement
1.8. ความสามารถในการทำงานร่วมกัน
OAuth 2.0 เป็น authorization framework ที่ครบเครื่องและมีคุณสมบัติด้านความปลอดภัยที่นิยามไว้ชัดเจน แต่เมื่อมันเป็น framework ที่ครบเครื่อง ขยายได้มาก และมีส่วนประกอบที่เป็นทางเลือกจำนวนมาก ข้อกำหนดนี้เพียงลำพังจึงมีแนวโน้มทำให้เกิด implementation จำนวนมากที่ทำงานร่วมกันไม่ได้
นอกจากนี้ ข้อกำหนดนี้ปล่อยให้ส่วนประกอบที่จำเป็นบางส่วนไม่ได้กำหนดไว้ทั้งหมดหรือบางส่วน (เช่น client registration, ความสามารถของ authorization server, endpoint discovery) หากไม่มีส่วนประกอบเหล่านี้ ต้องตั้งค่า client ด้วยมือและเฉพาะเจาะจงกับ authorization server และ resource server ตัวใดตัวหนึ่ง จึงจะทำงานร่วมกันได้
framework นี้ออกแบบมาโดยคาดหวังอย่างชัดเจนว่างานในอนาคตจะกำหนด profile และส่วนขยายที่เจาะจง ซึ่งจำเป็นต่อการทำงานร่วมกันได้เต็มที่ในระดับเว็บ
1.9. ข้อตกลงด้านสัญลักษณ์
คำหลัก "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY" และ "OPTIONAL" ในข้อกำหนดนี้ให้ตีความตามที่อธิบายไว้ใน [RFC2119]
ข้อกำหนดนี้ใช้สัญกรณ์ Augmented Backus-Naur Form (ABNF) ของ [RFC5234] และนำกฎ URI-reference มาจาก "Uniform Resource Identifier (URI): Generic Syntax" [RFC3986]
คำศัพท์ด้านความปลอดภัยบางคำให้เข้าใจตามความหมายที่นิยามไว้ใน [RFC4949] คำเหล่านี้ได้แก่ แต่ไม่จำกัดเพียง "attack", "authentication", "authorization", "certificate", "confidentiality", "credential", "encryption", "identity", "sign", "signature", "trust", "validate" และ "verify"
เว้นแต่จะระบุไว้เป็นอย่างอื่น ชื่อและค่าของ parameter ทั้งหมดของโปรโตคอลนี้แยกตัวพิมพ์ใหญ่และตัวพิมพ์เล็ก (case sensitive)
2. การลงทะเบียน client
ก่อนเริ่มโปรโตคอล client จะลงทะเบียนกับ authorization server วิธีที่ client ใช้ลงทะเบียนกับ authorization server อยู่นอกขอบเขตของข้อกำหนดนี้ แต่โดยทั่วไปต้องให้ end-user โต้ตอบกับแบบฟอร์มลงทะเบียน HTML
การลงทะเบียน client ไม่จำเป็นต้องให้ client และ authorization server โต้ตอบกันโดยตรง ถ้า authorization server รองรับ การลงทะเบียนสามารถอาศัยวิธีอื่นในการสร้างความไว้วางใจและรับคุณสมบัติของ client ที่จำเป็น (เช่น redirection URI, ประเภทของ client) ตัวอย่างเช่น ลงทะเบียนโดยใช้ assertion ที่ client ออกเองหรือที่บุคคลที่สามออกให้ หรือให้ authorization server ทำ client discovery ผ่านช่องทางที่เชื่อถือได้
เมื่อลงทะเบียน client ผู้พัฒนา client SHALL:
-
ระบุประเภทของ client ตามที่อธิบายไว้ใน Section 2.1,
-
ให้ client redirection URI ตามที่อธิบายไว้ใน Section 3.1.2 และ
-
ใส่ข้อมูลอื่นที่ authorization server ต้องการ (เช่น ชื่อแอปพลิเคชัน, เว็บไซต์, คำอธิบาย, รูปโลโก้, การยอมรับข้อกำหนดทางกฎหมาย)
2.1. ประเภทของ client
OAuth กำหนดประเภทของ client ไว้สองประเภท โดยดูจากความสามารถในการยืนยันตัวตนกับ authorization server อย่างปลอดภัย (คือความสามารถในการเก็บ client credentials เป็นความลับ):
-
confidential: client ที่เก็บ credentials ของตนเป็นความลับได้ (เช่น client ที่ implement บน server ที่ปลอดภัยและจำกัดการเข้าถึง client credentials) หรือยืนยันตัวตนของ client อย่างปลอดภัยด้วยวิธีอื่นได้
-
public: client ที่เก็บ credentials ของตนเป็นความลับไม่ได้ (เช่น client ที่ทำงานบนอุปกรณ์ที่ resource owner ใช้ เช่น native application ที่ติดตั้งไว้ หรือแอปพลิเคชันที่ทำงานบน browser) และยืนยันตัวตนของ client อย่างปลอดภัยด้วยวิธีอื่นใดก็ไม่ได้
การจัดประเภทของ client ขึ้นอยู่กับว่า authorization server นิยามการยืนยันตัวตนที่ปลอดภัยไว้อย่างไร และยอมให้ client credentials รั่วไหลได้ในระดับใด authorization server SHOULD NOT สันนิษฐานเอาเองเกี่ยวกับประเภทของ client
client อาจ implement เป็นชุดของ component แบบกระจาย โดยแต่ละ component มีประเภทของ client และ security context ต่างกัน (เช่น client แบบกระจายที่มี component ฝั่ง server ซึ่งเป็น confidential และ component ฝั่ง browser ซึ่งเป็น public) ถ้า authorization server ไม่รองรับ client แบบนี้ หรือไม่มีแนวทางเรื่องการลงทะเบียน client SHOULD ลงทะเบียนแต่ละ component เป็น client แยกกัน
ข้อกำหนดนี้ออกแบบโดยอิงกับ client profile ต่อไปนี้:
-
web application: web application คือ confidential client ที่ทำงานบน web server resource owner เข้าถึง client ผ่านส่วนติดต่อผู้ใช้ HTML ที่แสดงใน user-agent บนอุปกรณ์ที่ resource owner ใช้ client credentials และ access token ใดที่ออกให้ client จะเก็บไว้บน web server และไม่เปิดเผยหรือเปิดให้ resource owner เข้าถึงได้
-
user-agent-based application: user-agent-based application คือ public client ที่โค้ดของ client ถูกดาวน์โหลดจาก web server แล้วทำงานภายใน user-agent (เช่น browser) บนอุปกรณ์ที่ resource owner ใช้ ข้อมูลของโปรโตคอลและ credentials เข้าถึงได้ง่าย (และมักมองเห็นได้) สำหรับ resource owner เนื่องจากแอปพลิเคชันเหล่านี้อยู่ภายใน user-agent จึงใช้ความสามารถของ user-agent ได้อย่างราบรื่นเมื่อขอการอนุญาต
-
native application: native application คือ public client ที่ติดตั้งและทำงานบนอุปกรณ์ที่ resource owner ใช้ ข้อมูลของโปรโตคอลและ credentials เข้าถึงได้สำหรับ resource owner โดยสมมติว่า credentials สำหรับ client authentication ใดที่ฝังอยู่ในแอปพลิเคชันสามารถถูกดึงออกไปได้ ในทางกลับกัน credentials ที่ออกให้แบบ dynamic เช่น access token หรือ refresh token ได้รับการปกป้องในระดับที่ยอมรับได้ อย่างน้อยที่สุด credentials เหล่านี้ได้รับการปกป้องจาก server ที่เป็นอันตรายซึ่งแอปพลิเคชันอาจติดต่อด้วย บนบางแพลตฟอร์ม credentials เหล่านี้อาจได้รับการปกป้องจากแอปพลิเคชันอื่นบนอุปกรณ์เดียวกันด้วย
2.2. Client Identifier
authorization server ออก client identifier ให้ client ที่ลงทะเบียนแล้ว ซึ่งเป็น string ที่ไม่ซ้ำกันและแทนข้อมูลการลงทะเบียนที่ client ให้ไว้ client identifier ไม่ใช่ความลับ มันถูกเปิดเผยให้ resource owner เห็น และ MUST NOT ใช้เพียงอย่างเดียวเพื่อ client authentication client identifier ไม่ซ้ำกันภายใน authorization server
ข้อกำหนดนี้ไม่ได้กำหนดขนาดของ string ที่เป็น client identifier client ไม่ควรสันนิษฐานเกี่ยวกับขนาดของ identifier authorization server SHOULD ระบุขนาดของ identifier ทุกตัวที่ออกไว้ในเอกสาร
2.3. Client Authentication
ถ้า client เป็นประเภท confidential, client กับ authorization server จะกำหนดวิธี client authentication ที่เหมาะกับข้อกำหนดด้านความปลอดภัยของ authorization server authorization server MAY ยอมรับ client authentication รูปแบบใดก็ได้ที่ตรงตามข้อกำหนดด้านความปลอดภัยของตน
confidential client มักได้รับ (หรือสร้างขึ้น) ชุด client credentials ที่ใช้ยืนยันตัวตนกับ authorization server (เช่น password, public/private key pair)
authorization server MAY กำหนดวิธี client authentication กับ public client ได้ อย่างไรก็ตาม authorization server MUST NOT พึ่งพา client authentication ของ public client เพื่อระบุตัวตนของ client
client MUST NOT ใช้วิธียืนยันตัวตนมากกว่าหนึ่งวิธีในแต่ละ request
2.3.1. Client Password
client ที่มี client password MAY ใช้ HTTP Basic authentication scheme ตามที่กำหนดใน [RFC2617] เพื่อยืนยันตัวตนกับ authorization server โดย client identifier จะถูก encode ด้วย algorithm "application/x-www-form-urlencoded" ตาม Appendix B แล้วใช้ค่าที่ encode เป็น username ส่วน client password ก็ encode ด้วย algorithm เดียวกันแล้วใช้เป็น password authorization server MUST รองรับ HTTP Basic authentication scheme สำหรับยืนยันตัวตนของ client ที่ได้รับ client password
ตัวอย่าง (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
Authorization: Basic czZCaGRSa3F0Mzo3RmpmcDBaQnIxS3REUmJuZlZkbUl3
หรืออีกทางหนึ่ง authorization server MAY รองรับการใส่ client credentials ไว้ใน request-body โดยใช้ parameter ต่อไปนี้:
-
client_id: REQUIRED client identifier ที่ออกให้ client ระหว่างขั้นตอนลงทะเบียนที่อธิบายไว้ใน Section 2.2
-
client_secret: REQUIRED client secret client MAY ละ parameter นี้ได้ ถ้า client secret เป็น string ว่าง
การใส่ client credentials ไว้ใน request-body ด้วย parameter สองตัวนี้ NOT RECOMMENDED และ SHOULD จำกัดไว้เฉพาะ client ที่ใช้ HTTP Basic authentication scheme (หรือ HTTP authentication scheme อื่นที่ใช้รหัสผ่าน) โดยตรงไม่ได้ parameter เหล่านี้ส่งได้เฉพาะใน request-body และ MUST NOT ใส่ใน request URI
ตัวอย่างเช่น request สำหรับ refresh access token (Section 6) โดยใช้ body parameter (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
POST /token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA
&client_id=s6BhdRkqt3&client_secret=7Fjfp0ZBr1KtDRbnfVdmIw
authorization server MUST บังคับให้ใช้ TLS ตามที่อธิบายใน Section 1.6 เมื่อรับ request ที่ใช้ password authentication
เนื่องจาก client authentication วิธีนี้ใช้ password, authorization server MUST ปกป้อง endpoint ทุกตัวที่ใช้วิธีนี้จาก brute force attack
2.3.2. วิธียืนยันตัวตนอื่น ๆ
authorization server MAY รองรับ HTTP authentication scheme ใดก็ได้ที่เหมาะกับข้อกำหนดด้านความปลอดภัยของตน เมื่อใช้วิธียืนยันตัวตนอื่น authorization server MUST กำหนดการจับคู่ระหว่าง client identifier (registration record) กับ authentication scheme
2.4. client ที่ไม่ได้ลงทะเบียน
ข้อกำหนดนี้ไม่ได้ห้ามการใช้ client ที่ไม่ได้ลงทะเบียน แต่การใช้ client แบบนี้อยู่นอกขอบเขตของข้อกำหนดนี้ และต้องมีการวิเคราะห์ด้านความปลอดภัยเพิ่มเติม รวมถึงทบทวนผลกระทบต่อการทำงานร่วมกัน
3. Endpoint ของโปรโตคอล
กระบวนการอนุญาตใช้ endpoint ของ authorization server สองตัว (HTTP resource):
-
Authorization endpoint - client ใช้เพื่อขอการอนุญาตจาก resource owner ผ่านการ redirect user-agent
-
Token endpoint - client ใช้เพื่อแลก authorization grant เป็น access token โดยทั่วไปจะมี client authentication ด้วย
และ endpoint ของ client อีกหนึ่งตัว:
- Redirection endpoint - authorization server ใช้เพื่อส่ง response ที่มี credentials สำหรับการอนุญาตกลับไปยัง client ผ่าน user-agent ของ resource owner
authorization grant type บางแบบไม่ได้ใช้ endpoint ทั้งสองตัว extension grant type MAY กำหนด endpoint เพิ่มเติมตามที่ต้องการ
3.1. Authorization Endpoint
authorization endpoint ใช้โต้ตอบกับ resource owner และขอ authorization grant authorization server MUST ตรวจสอบตัวตนของ resource owner ก่อน วิธีที่ authorization server ยืนยันตัวตนของ resource owner (เช่น login ด้วยชื่อผู้ใช้และรหัสผ่าน, session cookie) อยู่นอกขอบเขตของข้อกำหนดนี้
วิธีที่ client ทราบตำแหน่งของ authorization endpoint อยู่นอกขอบเขตของข้อกำหนดนี้ แต่โดยทั่วไปตำแหน่งนี้จะระบุไว้ในเอกสารของบริการ
endpoint URI MAY มี query component ในรูปแบบ "application/x-www-form-urlencoded" (ตาม Appendix B) ([RFC3986] Section 3.4) ซึ่ง MUST คงไว้เมื่อเพิ่ม query parameter อื่น endpoint URI MUST NOT มี fragment component
เนื่องจาก request ไปยัง authorization endpoint ทำให้เกิดการยืนยันตัวตนของผู้ใช้และการส่ง credentials แบบ clear-text (ใน HTTP response) authorization server MUST บังคับให้ใช้ TLS ตามที่อธิบายใน Section 1.6 เมื่อรับ request ที่ส่งไปยัง authorization endpoint
authorization server MUST รองรับ HTTP method "GET" [RFC2616] สำหรับ authorization endpoint และ MAY รองรับ method "POST" ด้วย
parameter ที่ส่งมาโดยไม่มีค่า MUST ถูกปฏิบัติเหมือนไม่ได้ส่งมาใน request authorization server MUST เพิกเฉยต่อ request parameter ที่ไม่รู้จัก request parameter และ response parameter MUST NOT ปรากฏซ้ำมากกว่าหนึ่งครั้ง
3.1.1. ค่า response type
authorization endpoint ใช้ใน flow ของ authorization code grant type และ implicit grant type client แจ้ง authorization server ว่าต้องการ grant type ใดด้วย parameter ต่อไปนี้:
- response_type: REQUIRED ค่า MUST เป็นอย่างใดอย่างหนึ่งของ "code" สำหรับขอ authorization code ตามที่อธิบายใน Section 4.1.1, "token" สำหรับขอ access token (implicit grant) ตามที่อธิบายใน Section 4.2.1 หรือค่า extension ที่ลงทะเบียนไว้ตามที่อธิบายใน Section 8.4
extension response type MAY มีรายการค่าที่คั่นด้วยช่องว่าง (%x20) ได้ โดยลำดับของค่าไม่มีผล (เช่น response type "a b" เหมือนกับ "b a") ความหมายของ response type แบบผสมเหล่านี้กำหนดไว้ในข้อกำหนดของแต่ละตัว
ถ้า authorization request ไม่มี parameter "response_type" หรือไม่เข้าใจ response type นั้น authorization server MUST ส่ง error response ตามที่อธิบายใน Section 4.1.2.1
3.1.2. Redirection Endpoint
หลังจากโต้ตอบกับ resource owner เสร็จ authorization server จะส่ง user-agent ของ resource owner กลับไปที่ client โดย redirect user-agent ไปยัง redirection endpoint ของ client ที่กำหนดไว้กับ authorization server ก่อนหน้า ไม่ว่าจะตอนลงทะเบียน client หรือตอนส่ง authorization request
redirection endpoint URI MUST เป็น absolute URI ตามที่กำหนดใน [RFC3986] Section 4.3 endpoint URI MAY มี query component ในรูปแบบ "application/x-www-form-urlencoded" (ตาม Appendix B) ([RFC3986] Section 3.4) ซึ่ง MUST คงไว้เมื่อเพิ่ม query parameter อื่น endpoint URI MUST NOT มี fragment component
3.1.2.1. ความลับของ request ที่ส่งไปยัง endpoint
redirection endpoint SHOULD บังคับให้ใช้ TLS ตามที่อธิบายใน Section 1.6 เมื่อ response type ที่ขอเป็น "code" หรือ "token" หรือเมื่อ redirection request จะทำให้ credentials ที่ละเอียดอ่อนถูกส่งผ่านเครือข่ายเปิด ข้อกำหนดนี้ไม่ได้บังคับให้ใช้ TLS เพราะ ณ เวลาที่เขียน การบังคับให้ client ต้อง deploy TLS เป็นอุปสรรคใหญ่สำหรับผู้พัฒนา client จำนวนมาก ถ้าใช้ TLS ไม่ได้ authorization server SHOULD เตือน resource owner เรื่อง endpoint ที่ไม่ปลอดภัยก่อน redirect (เช่น แสดงข้อความระหว่าง authorization request)
การไม่มีความปลอดภัยระดับ transport layer อาจกระทบความปลอดภัยของ client และ protected resource ที่ client ได้รับอนุญาตให้เข้าถึงอย่างรุนแรง ความปลอดภัยระดับ transport layer ยิ่งสำคัญมากเมื่อ client ใช้กระบวนการอนุญาตเป็นรูปแบบหนึ่งของการยืนยันตัวตน end-user แบบมอบหมาย (เช่น บริการ sign-in ของบุคคลที่สาม)
3.1.2.2. ข้อกำหนดด้านการลงทะเบียน
authorization server MUST บังคับให้ client ประเภทต่อไปนี้ลงทะเบียน redirection endpoint ของตน:
-
public client
-
confidential client ที่ใช้ implicit grant type
authorization server SHOULD บังคับให้ client ทุกตัวลงทะเบียน redirection endpoint ก่อนใช้ authorization endpoint
authorization server SHOULD บังคับให้ client ระบุ redirection URI แบบครบถ้วน (client MAY ใช้ request parameter "state" เพื่อปรับแต่งเป็นรายครั้งของ request) ถ้าบังคับให้ลงทะเบียน redirection URI แบบครบถ้วนไม่ได้ authorization server SHOULD บังคับให้ลงทะเบียน URI scheme, authority และ path (ทำให้ client เปลี่ยนได้แบบ dynamic เฉพาะ query component ของ redirection URI ตอนขอการอนุญาต)
authorization server MAY อนุญาตให้ client ลงทะเบียน redirection endpoint ได้หลายตัว
ถ้าไม่บังคับให้ลงทะเบียน redirection URI ผู้โจมตีอาจใช้ authorization endpoint เป็น open redirector ได้ ตามที่อธิบายใน Section 10.15
3.1.2.3. การกำหนดค่าแบบ dynamic
ถ้าลงทะเบียน redirection URI ไว้หลายตัว ถ้าลงทะเบียนไว้เพียงบางส่วนของ redirection URI หรือถ้าไม่ได้ลงทะเบียน redirection URI ไว้เลย client MUST ใส่ redirection URI มาใน authorization request โดยใช้ request parameter "redirect_uri"
เมื่อ authorization request มี redirection URI authorization server MUST เทียบค่าที่ได้รับกับ redirection URI (หรือ URI component) ที่ลงทะเบียนไว้อย่างน้อยหนึ่งตัวว่าตรงกัน ตามที่กำหนดใน [RFC3986] Section 6 ถ้ามีการลงทะเบียน redirection URI ไว้ ถ้าการลงทะเบียน client ระบุ redirection URI แบบเต็ม authorization server MUST เปรียบเทียบ URI ทั้งสองด้วยการเปรียบเทียบ string อย่างง่ายตามที่กำหนดใน [RFC3986] Section 6.2.1
3.1.2.4. endpoint ที่ใช้ไม่ได้
ถ้า authorization request ไม่ผ่านการตรวจสอบเพราะ redirection URI หายไป ไม่ถูกต้อง หรือไม่ตรงกัน authorization server SHOULD แจ้ง resource owner ว่าเกิดข้อผิดพลาด และ MUST NOT redirect user-agent ไปยัง redirection URI ที่ไม่ถูกต้องนั้นโดยอัตโนมัติ
3.1.2.5. เนื้อหาที่ endpoint
redirection request ที่ส่งไปยัง endpoint ของ client มักได้ response เป็นเอกสาร HTML ซึ่ง user-agent จะประมวลผล ถ้า response HTML ถูกส่งตรงเป็นผลของ redirection request สคริปต์ใดในเอกสาร HTML จะทำงานโดยเข้าถึง redirection URI และ credentials ที่อยู่ใน URI นั้นได้เต็มที่
client SHOULD NOT ใส่สคริปต์ของบุคคลที่สาม (เช่น analytics ของบุคคลที่สาม, social plug-in, ad network) ไว้ใน response ของ redirection endpoint แต่ SHOULD ดึง credentials ออกจาก URI แล้ว redirect user-agent อีกครั้งไปยัง endpoint อื่นโดยไม่เปิดเผย credentials (ใน URI หรือที่อื่น) ถ้าต้องใส่สคริปต์ของบุคคลที่สาม client MUST ทำให้แน่ใจว่าสคริปต์ของตนเอง (ที่ใช้ดึงและลบ credentials ออกจาก URI) จะทำงานก่อน
3.2. Token Endpoint
client ใช้ token endpoint เพื่อขอ access token โดยแสดง authorization grant หรือ refresh token ของตน token endpoint ใช้กับ authorization grant ทุกแบบ ยกเว้น implicit grant type (เพราะ access token ถูกออกให้โดยตรง)
วิธีที่ client ทราบตำแหน่งของ token endpoint อยู่นอกขอบเขตของข้อกำหนดนี้ แต่โดยทั่วไปตำแหน่งนี้จะระบุไว้ในเอกสารของบริการ
endpoint URI MAY มี query component ในรูปแบบ "application/x-www-form-urlencoded" (ตาม Appendix B) ([RFC3986] Section 3.4) ซึ่ง MUST คงไว้เมื่อเพิ่ม query parameter อื่น endpoint URI MUST NOT มี fragment component
เนื่องจาก request ไปยัง token endpoint ทำให้ credentials แบบ clear-text ถูกส่ง (ใน HTTP request และ response) authorization server MUST บังคับให้ใช้ TLS ตามที่อธิบายใน Section 1.6 เมื่อรับ request ที่ส่งไปยัง token endpoint
client MUST ใช้ HTTP method "POST" เมื่อส่ง access token request
parameter ที่ส่งมาโดยไม่มีค่า MUST ถูกปฏิบัติเหมือนไม่ได้ส่งมาใน request authorization server MUST เพิกเฉยต่อ request parameter ที่ไม่รู้จัก request parameter และ response parameter MUST NOT ปรากฏซ้ำมากกว่าหนึ่งครั้ง
3.2.1. Client Authentication
confidential client หรือ client อื่นที่ได้รับ client credentials MUST ยืนยันตัวตนกับ authorization server ตามที่อธิบายใน Section 2.3 เมื่อส่ง request ไปยัง token endpoint client authentication ใช้เพื่อ:
-
บังคับให้ refresh token และ authorization code ผูกกับ client ที่ได้รับ token หรือ code นั้น client authentication สำคัญมากเมื่อ authorization code ถูกส่งไปยัง redirection endpoint ผ่านช่องทางที่ไม่ปลอดภัย หรือเมื่อลงทะเบียน redirection URI ไม่ครบทั้งหมด
-
กู้สถานการณ์เมื่อ client ถูกบุกรุก ด้วยการปิดการใช้งาน client หรือเปลี่ยน credentials ของ client เพื่อไม่ให้ผู้โจมตีนำ refresh token ที่ขโมยไปใช้ในทางที่ผิด การเปลี่ยน client credentials ชุดเดียวทำได้เร็วกว่าการเพิกถอน refresh token ทั้งชุดมาก
-
ใช้แนวปฏิบัติที่ดีที่สุดด้านการจัดการ authentication ซึ่งต้องหมุนเวียน (rotate) credentials เป็นระยะ การ rotate refresh token ทั้งชุดทำได้ยาก ขณะที่การ rotate client credentials ชุดเดียวง่ายกว่ามาก
client MAY ใช้ request parameter "client_id" เพื่อระบุตัวตนของตนเมื่อส่ง request ไปยัง token endpoint ใน request "authorization_code" "grant_type" ที่ส่งไปยัง token endpoint client ที่ไม่ได้ยืนยันตัวตน MUST ส่ง "client_id" ของตน เพื่อป้องกันไม่ให้ตนเองรับ code ที่ออกไว้สำหรับ client ที่มี "client_id" อื่นโดยไม่ตั้งใจ วิธีนี้ปกป้อง client จากการสลับ authentication code (แต่ไม่ได้เพิ่มความปลอดภัยให้ protected resource)
3.3. Access Token Scope
authorization endpoint และ token endpoint ให้ client ระบุ scope ของ access request ได้ด้วย request parameter "scope" ส่วน authorization server ใช้ response parameter "scope" เพื่อแจ้ง client ว่า access token ที่ออกให้มี scope อะไร
ค่าของ parameter scope แสดงเป็นรายการ string ที่คั่นด้วยช่องว่างและแยกตัวพิมพ์ใหญ่เล็ก (case-sensitive) โดย authorization server เป็นผู้กำหนด string เหล่านี้ ถ้าค่ามี string หลายตัวที่คั่นด้วยช่องว่าง ลำดับของมันไม่มีผล และ string แต่ละตัวจะเพิ่มช่วงการเข้าถึงอีกหนึ่งช่วงให้ scope ที่ขอ
scope = scope-token *( SP scope-token )
scope-token = 1*( %x21 / %x23-5B / %x5D-7E )
authorization server MAY ละเว้น scope ที่ client ขอทั้งหมดหรือบางส่วนก็ได้ ตามนโยบายของ authorization server หรือคำสั่งของ resource owner ถ้า scope ของ access token ที่ออกให้ต่างจากที่ client ขอ authorization server MUST ใส่ response parameter "scope" เพื่อแจ้ง client ว่า scope ที่ให้จริงคืออะไร
ถ้า client ไม่ส่ง parameter scope มาตอนขอการอนุญาต authorization server MUST เลือกอย่างใดอย่างหนึ่ง คือประมวลผล request โดยใช้ค่า default ที่กำหนดไว้ล่วงหน้า หรือให้ request ล้มเหลวโดยระบุว่า scope ไม่ถูกต้อง authorization server SHOULD ระบุข้อกำหนดเรื่อง scope และค่า default (ถ้ามี) ไว้ในเอกสาร
4. การขอการอนุญาต
เพื่อขอ access token client ต้องได้รับการอนุญาตจาก resource owner ก่อน การอนุญาตแสดงอยู่ในรูปของ authorization grant ซึ่ง client ใช้ขอ access token OAuth กำหนด grant type ไว้สี่แบบ ได้แก่ authorization code, implicit, resource owner password credentials และ client credentials และมีกลไกขยายสำหรับกำหนด grant type เพิ่มเติม
4.1. Authorization Code Grant
authorization code grant type ใช้ขอทั้ง access token และ refresh token และออกแบบมาให้เหมาะกับ confidential client เนื่องจากเป็น flow ที่อาศัยการ redirect client จึงต้องโต้ตอบกับ user-agent ของ resource owner (โดยทั่วไปคือ browser) และรับ request ขาเข้า (ผ่านการ redirect) จาก authorization server ได้
sequenceDiagram
participant RO as Resource Owner
participant UA as User-Agent
participant C as Client
participant AS as Authorization Server
C->>UA: (A) Client Identifier & Redirection URI
UA->>AS: (A) Client Identifier & Redirection URI
UA->>RO: (B)
UA->>AS: (B) User authenticates
AS-->>UA: (C) Authorization Code
UA-->>C: (C) Authorization Code
C->>AS: (D) Authorization Code & Redirection URI
AS-->>C: (E) Access Token (w/ Optional Refresh Token)
หมายเหตุ: เส้นที่แสดงขั้นตอน (A), (B) และ (C) ถูกแบ่งเป็นสองส่วนเพราะผ่าน user-agent
Figure 3: flow ของ authorization code
flow ใน Figure 3 มีขั้นตอนดังนี้:
-
(A) client เริ่ม flow โดยส่ง user-agent ของ resource owner ไปยัง authorization endpoint client ใส่ client identifier, scope ที่ขอ, local state และ redirection URI ซึ่ง authorization server จะใช้ส่ง user-agent กลับมาเมื่อให้สิทธิ์ (หรือปฏิเสธ) แล้ว
-
(B) authorization server ยืนยันตัวตนของ resource owner (ผ่าน user-agent) และตรวจสอบว่า resource owner อนุญาตหรือปฏิเสธ access request ของ client
-
(C) ถ้า resource owner อนุญาต authorization server จะ redirect user-agent กลับไปที่ client โดยใช้ redirection URI ที่ระบุไว้ก่อนหน้า (ใน request หรือตอนลงทะเบียน client) redirection URI นั้นมี authorization code และ local state ใด ๆ ที่ client ส่งมาก่อนหน้านี้
-
(D) client ขอ access token จาก token endpoint ของ authorization server โดยส่ง authorization code ที่ได้รับในขั้นตอนก่อนหน้า ตอนส่ง request นี้ client ยืนยันตัวตนกับ authorization server และใส่ redirection URI ที่ใช้ขอ authorization code ไปด้วยเพื่อตรวจสอบ
-
(E) authorization server ยืนยันตัวตนของ client ตรวจสอบ authorization code และตรวจว่า redirection URI ที่ได้รับตรงกับ URI ที่ใช้ redirect client ในขั้นตอน (C) ถ้าถูกต้อง authorization server จะตอบกลับด้วย access token และอาจมี refresh token ด้วย
4.1.1. Authorization Request
client สร้าง request URI โดยเพิ่ม parameter ต่อไปนี้ลงใน query component ของ URI ของ authorization endpoint ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B:
-
response_type: REQUIRED ค่า MUST ตั้งเป็น "code"
-
client_id: REQUIRED client identifier ตามที่อธิบายใน Section 2.2
-
redirect_uri: OPTIONAL ตามที่อธิบายใน Section 3.1.2
-
scope: OPTIONAL scope ของ access request ตามที่อธิบายใน Section 3.3
-
state: RECOMMENDED ค่า opaque ที่ client ใช้เก็บ state ระหว่าง request กับ callback authorization server จะใส่ค่านี้กลับมาเมื่อ redirect user-agent กลับไปที่ client SHOULD ใช้ parameter นี้เพื่อป้องกัน cross-site request forgery ตามที่อธิบายใน Section 10.12
client ส่ง resource owner ไปยัง URI ที่สร้างขึ้นด้วย HTTP redirection response หรือด้วยวิธีอื่นที่ทำได้ผ่าน user-agent
ตัวอย่างเช่น client สั่งให้ user-agent ส่ง HTTP request ต่อไปนี้ผ่าน TLS (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz
&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
Host: server.example.com
authorization server ตรวจสอบ request เพื่อให้แน่ใจว่ามี parameter ที่จำเป็นครบและถูกต้อง ถ้า request ถูกต้อง authorization server จะยืนยันตัวตนของ resource owner และหาการตัดสินใจเรื่องการอนุญาต (โดยถาม resource owner หรือรับการอนุมัติด้วยวิธีอื่น)
เมื่อได้การตัดสินใจแล้ว authorization server จะส่ง user-agent ไปยัง redirection URI ของ client ที่ระบุมา ด้วย HTTP redirection response หรือด้วยวิธีอื่นที่ทำได้ผ่าน user-agent
4.1.2. Authorization Response
ถ้า resource owner อนุญาต access request authorization server จะออก authorization code และส่งให้ client โดยเพิ่ม parameter ต่อไปนี้ลงใน query component ของ redirection URI ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B:
-
code: REQUIRED authorization code ที่ authorization server สร้างขึ้น authorization code MUST หมดอายุภายในเวลาสั้น ๆ หลังออก เพื่อลดความเสี่ยงที่จะรั่วไหล อายุสูงสุดของ authorization code ที่ 10 นาทีนั้น RECOMMENDED client MUST NOT ใช้ authorization code เกินหนึ่งครั้ง ถ้ามีการใช้ authorization code เกินหนึ่งครั้ง authorization server MUST ปฏิเสธ request และ SHOULD เพิกถอน token ทั้งหมดที่เคยออกจาก authorization code นั้น (เมื่อทำได้) authorization code ผูกกับ client identifier และ redirection URI
-
state: REQUIRED ถ้า parameter "state" อยู่ใน authorization request ของ client ค่าเดิมทุกประการที่ได้รับจาก client
ตัวอย่างเช่น authorization server redirect user-agent โดยส่ง HTTP response ต่อไปนี้:
HTTP/1.1 302 Found
Location: https://client.example.com/cb?code=SplxlOBeZQQYbYS6WxSbIA
&state=xyz
client MUST เพิกเฉยต่อ response parameter ที่ไม่รู้จัก ข้อกำหนดนี้ไม่ได้กำหนดขนาดของ string ที่เป็น authorization code client ไม่ควรสันนิษฐานเกี่ยวกับขนาดของค่า code authorization server SHOULD ระบุขนาดของค่าทุกตัวที่ออกไว้ในเอกสาร
4.1.2.1. Response เมื่อเกิดข้อผิดพลาด
ถ้า request ล้มเหลวเพราะ redirection URI หายไป ไม่ถูกต้อง หรือไม่ตรงกัน หรือเพราะ client identifier หายไปหรือไม่ถูกต้อง authorization server SHOULD แจ้ง resource owner ว่าเกิดข้อผิดพลาด และ MUST NOT redirect user-agent ไปยัง redirection URI ที่ไม่ถูกต้องนั้นโดยอัตโนมัติ
ถ้า resource owner ปฏิเสธ access request หรือ request ล้มเหลวด้วยเหตุอื่นที่ไม่ใช่ redirection URI หายไปหรือไม่ถูกต้อง authorization server จะแจ้ง client โดยเพิ่ม parameter ต่อไปนี้ลงใน query component ของ redirection URI ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B:
-
error: REQUIRED error code แบบ ASCII [USASCII] เพียงค่าเดียวจากรายการต่อไปนี้:
invalid_request request ไม่มี parameter ที่จำเป็น มีค่า parameter ที่ไม่ถูกต้อง มี parameter ซ้ำมากกว่าหนึ่งครั้ง หรือมีรูปแบบผิดด้วยเหตุอื่น
unauthorized_client client ไม่ได้รับอนุญาตให้ขอ authorization code ด้วยวิธีนี้
access_denied resource owner หรือ authorization server ปฏิเสธ request
unsupported_response_type authorization server ไม่รองรับการขอ authorization code ด้วยวิธีนี้
invalid_scope scope ที่ขอไม่ถูกต้อง ไม่รู้จัก หรือมีรูปแบบผิด
server_error authorization server พบเงื่อนไขที่ไม่คาดคิดซึ่งทำให้ทำตาม request ไม่ได้ (ต้องมี error code นี้เพราะส่ง HTTP status code 500 Internal Server Error กลับไปที่ client ผ่าน HTTP redirect ไม่ได้)
temporarily_unavailable authorization server ไม่สามารถจัดการ request ได้ในขณะนี้ เพราะ server โอเวอร์โหลดชั่วคราวหรืออยู่ระหว่างการบำรุงรักษา (ต้องมี error code นี้เพราะส่ง HTTP status code 503 Service Unavailable กลับไปที่ client ผ่าน HTTP redirect ไม่ได้)
ค่าของ parameter "error" MUST NOT มีตัวอักษรนอกเซต %x20-21 / %x23-5B / %x5D-7E
-
error_description: OPTIONAL ข้อความ ASCII [USASCII] ที่คนอ่านได้ ให้ข้อมูลเพิ่มเติมเพื่อช่วยผู้พัฒนา client เข้าใจข้อผิดพลาดที่เกิดขึ้น ค่าของ parameter "error_description" MUST NOT มีตัวอักษรนอกเซต %x20-21 / %x23-5B / %x5D-7E
-
error_uri: OPTIONAL URI ที่ชี้ไปยังหน้าเว็บที่คนอ่านได้ซึ่งมีข้อมูลเกี่ยวกับข้อผิดพลาด ใช้ให้ข้อมูลเพิ่มเติมเกี่ยวกับข้อผิดพลาดแก่ผู้พัฒนา client ค่าของ parameter "error_uri" MUST เป็นไปตามไวยากรณ์ URI-reference จึง MUST NOT มีตัวอักษรนอกเซต %x21 / %x23-5B / %x5D-7E
-
state: REQUIRED ถ้า parameter "state" อยู่ใน authorization request ของ client ค่าเดิมทุกประการที่ได้รับจาก client
ตัวอย่างเช่น authorization server redirect user-agent โดยส่ง HTTP response ต่อไปนี้:
HTTP/1.1 302 Found
Location: https://client.example.com/cb?error=access_denied&state=xyz
4.1.3. Access Token Request
client ส่ง request ไปยัง token endpoint โดยส่ง parameter ต่อไปนี้ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B ด้วยการเข้ารหัสอักขระ UTF-8 ใน entity-body ของ HTTP request:
-
grant_type: REQUIRED ค่า MUST ตั้งเป็น "authorization_code"
-
code: REQUIRED authorization code ที่ได้รับจาก authorization server
-
redirect_uri: REQUIRED ถ้า parameter "redirect_uri" อยู่ใน authorization request ตามที่อธิบายใน Section 4.1.1 และค่าทั้งสอง MUST เหมือนกัน
-
client_id: REQUIRED ถ้า client ไม่ได้ยืนยันตัวตนกับ authorization server ตามที่อธิบายใน Section 3.2.1
ถ้า client เป็นประเภท confidential หรือ client ได้รับ client credentials (หรือถูกกำหนดข้อกำหนดด้านการยืนยันตัวตนอื่น) client MUST ยืนยันตัวตนกับ authorization server ตามที่อธิบายใน Section 3.2.1
ตัวอย่างเช่น client ส่ง HTTP request ต่อไปนี้ผ่าน TLS (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA
&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
authorization server MUST:
-
บังคับให้ confidential client หรือ client ใดที่ได้รับ client credentials (หรือมีข้อกำหนดด้านการยืนยันตัวตนอื่น) ต้องทำ client authentication,
-
ยืนยันตัวตนของ client ถ้ามี client authentication มาด้วย,
-
ตรวจสอบว่า authorization code ถูกออกให้ confidential client ที่ยืนยันตัวตนแล้ว หรือถ้า client เป็น public ให้ตรวจสอบว่า code ถูกออกให้ "client_id" ใน request,
-
ตรวจสอบว่า authorization code ใช้ได้ และ
-
ตรวจสอบว่ามี parameter "redirect_uri" ถ้า parameter "redirect_uri" อยู่ใน authorization request แรกตามที่อธิบายใน Section 4.1.1 และถ้ามี ให้ตรวจสอบว่าค่าทั้งสองเหมือนกัน
4.1.4. Access Token Response
ถ้า access token request ถูกต้องและได้รับอนุญาต authorization server จะออก access token และ refresh token (ถ้ามี) ตามที่อธิบายใน Section 5.1 ถ้า client authentication ของ request ล้มเหลวหรือไม่ถูกต้อง authorization server จะส่ง error response กลับตามที่อธิบายใน Section 5.2
ตัวอย่าง response ที่สำเร็จ:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter":"example_value"
}
4.2. Implicit Grant
implicit grant type ใช้ขอ access token (ไม่รองรับการออก refresh token) และออกแบบมาให้เหมาะกับ public client ที่ทราบว่าทำงานกับ redirection URI เฉพาะตัวหนึ่ง client เหล่านี้มักเขียนอยู่ใน browser ด้วยภาษาสคริปต์ เช่น JavaScript
เนื่องจากเป็น flow ที่อาศัยการ redirect client จึงต้องโต้ตอบกับ user-agent ของ resource owner (โดยทั่วไปคือ browser) และรับ request ขาเข้า (ผ่านการ redirect) จาก authorization server ได้
ต่างจาก authorization code grant type ที่ client ส่ง request แยกกันสำหรับขอการอนุญาตและขอ access token ใน implicit grant client ได้รับ access token เป็นผลของ authorization request เลย
implicit grant type ไม่รวม client authentication และอาศัยการมีอยู่ของ resource owner และการลงทะเบียนของ redirection URI เนื่องจาก access token ถูก encode ไว้ใน redirection URI จึงอาจถูกเปิดเผยต่อ resource owner และแอปพลิเคชันอื่น ๆ ที่อยู่ในอุปกรณ์เดียวกัน
sequenceDiagram
participant RO as Resource Owner
participant C as Client
participant UA as User-Agent
participant AS as Authorization Server
participant WH as Web-Hosted Client Resource
C->>UA: (A) Client Identifier & Redirection URI
UA->>AS: (A) Client Identifier & Redirection URI
UA->>RO: (B)
UA->>AS: (B) User authenticates
AS-->>UA: (C) Redirection URI with Access Token in Fragment
UA->>WH: (D) Redirection URI without Fragment
WH-->>UA: (E) Script
UA->>UA: (F)
UA-->>C: (G) Access Token
หมายเหตุ: บรรทัดที่แสดงขั้นตอน (A) และ (B) ถูกแบ่งออกเป็นสองส่วนเมื่อผ่าน user-agent
Figure 4: flow ของ implicit grant
flow ใน Figure 4 มีขั้นตอนดังนี้:
-
(A) client เริ่ม flow โดยส่ง user-agent ของ resource owner ไปยัง authorization endpoint client ใส่ client identifier, scope ที่ขอ, local state และ redirection URI ซึ่ง authorization server จะใช้ส่ง user-agent กลับมาเมื่อให้สิทธิ์ (หรือปฏิเสธ) แล้ว
-
(B) authorization server ยืนยันตัวตนของ resource owner (ผ่าน user-agent) และตรวจสอบว่า resource owner อนุญาตหรือปฏิเสธ access request ของ client
-
(C) ถ้า resource owner อนุญาต authorization server จะ redirect user-agent กลับไปที่ client โดยใช้ redirection URI ที่ระบุไว้ก่อนหน้า redirection URI นี้มี access token อยู่ใน URI fragment
-
(D) user-agent ทำตามคำสั่ง redirect โดยส่ง request ไปยัง web-hosted client resource (ซึ่งไม่รวม fragment ตาม [RFC2616]) user-agent เก็บข้อมูล fragment ไว้ในเครื่อง
-
(E) web-hosted client resource ส่งหน้าเว็บกลับมา (โดยทั่วไปเป็นเอกสาร HTML ที่ฝังสคริปต์) ซึ่งเข้าถึง redirection URI แบบเต็มรวมถึง fragment ที่ user-agent เก็บไว้ได้ และดึง access token (กับ parameter อื่น) ที่อยู่ใน fragment ออกมาได้
-
(F) user-agent รันสคริปต์ที่ web-hosted client resource ส่งมาในเครื่อง เพื่อดึง access token ออกมา
-
(G) user-agent ส่ง access token ไปให้ client
ดูพื้นหลังของการใช้ implicit grant ได้ใน Sections 1.3.2 และ 9 ดูข้อควรพิจารณาด้านความปลอดภัยที่สำคัญเมื่อใช้ implicit grant ได้ใน Sections 10.3 และ 10.16
4.2.1. Authorization Request
client สร้าง request URI โดยเพิ่ม parameter ต่อไปนี้ลงใน query component ของ URI ของ authorization endpoint ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B:
-
response_type: REQUIRED ค่า MUST ตั้งเป็น "token"
-
client_id: REQUIRED client identifier ตามที่อธิบายใน Section 2.2
-
redirect_uri: OPTIONAL ตามที่อธิบายใน Section 3.1.2
-
scope: OPTIONAL scope ของ access request ตามที่อธิบายใน Section 3.3
-
state: RECOMMENDED ค่า opaque ที่ client ใช้เก็บ state ระหว่าง request กับ callback authorization server จะใส่ค่านี้กลับมาเมื่อ redirect user-agent กลับไปที่ client SHOULD ใช้ parameter นี้เพื่อป้องกัน cross-site request forgery ตามที่อธิบายใน Section 10.12
client ส่ง resource owner ไปยัง URI ที่สร้างขึ้นด้วย HTTP redirection response หรือด้วยวิธีอื่นที่ทำได้ผ่าน user-agent
ตัวอย่างเช่น client สั่งให้ user-agent ส่ง HTTP request ต่อไปนี้ผ่าน TLS (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
GET /authorize?response_type=token&client_id=s6BhdRkqt3&state=xyz
&redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
Host: server.example.com
authorization server ตรวจสอบ request เพื่อให้แน่ใจว่ามี parameter ที่จำเป็นครบและถูกต้อง authorization server MUST ตรวจสอบว่า redirection URI ที่จะใช้ redirect access token ไปนั้นตรงกับ redirection URI ที่ client ลงทะเบียนไว้ ตามที่อธิบายใน Section 3.1.2
ถ้า request ถูกต้อง authorization server จะยืนยันตัวตนของ resource owner และหาการตัดสินใจเรื่องการอนุญาต (โดยถาม resource owner หรือรับการอนุมัติด้วยวิธีอื่น)
เมื่อได้การตัดสินใจแล้ว authorization server จะส่ง user-agent ไปยัง redirection URI ของ client ที่ระบุมา ด้วย HTTP redirection response หรือด้วยวิธีอื่นที่ทำได้ผ่าน user-agent
4.2.2. Access Token Response
ถ้า resource owner อนุญาต access request authorization server จะออก access token และส่งให้ client โดยเพิ่ม parameter ต่อไปนี้ลงใน fragment component ของ redirection URI ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B:
-
access_token: REQUIRED access token ที่ authorization server ออกให้
-
token_type: REQUIRED ประเภทของ token ที่ออก ตามที่อธิบายใน Section 7.1 ค่าไม่แยกตัวพิมพ์ใหญ่เล็ก (case insensitive)
-
expires_in: RECOMMENDED อายุของ access token เป็นวินาที เช่น ค่า "3600" หมายความว่า access token จะหมดอายุใน 1 ชั่วโมงนับจากเวลาที่สร้าง response ถ้าไม่ระบุ authorization server SHOULD บอกเวลาหมดอายุด้วยวิธีอื่น หรือระบุค่า default ไว้ในเอกสาร
-
scope: OPTIONAL ถ้าเหมือนกับ scope ที่ client ขอ ไม่เช่นนั้นเป็น REQUIRED scope ของ access token ตามที่อธิบายใน Section 3.3
-
state: REQUIRED ถ้า parameter "state" อยู่ใน authorization request ของ client ค่าเดิมทุกประการที่ได้รับจาก client
authorization server MUST NOT ออก refresh token
ตัวอย่างเช่น authorization server redirect user-agent โดยส่ง HTTP response ต่อไปนี้ (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
HTTP/1.1 302 Found
Location: http://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA
&state=xyz&token_type=example&expires_in=3600
ผู้พัฒนาควรทราบว่า user-agent บางตัวไม่รองรับการใส่ fragment component ใน HTTP response header field "Location" client เหล่านั้นต้องใช้วิธีอื่นในการ redirect client แทน 3xx redirection response เช่น ส่งหน้า HTML ที่มีปุ่ม 'continue' ซึ่งมี action ผูกกับ redirection URI
client MUST เพิกเฉยต่อ response parameter ที่ไม่รู้จัก ข้อกำหนดนี้ไม่ได้กำหนดขนาดของ string ที่เป็น access token client ไม่ควรสันนิษฐานเกี่ยวกับขนาดของค่า authorization server SHOULD ระบุขนาดของค่าทุกตัวที่ออกไว้ในเอกสาร
4.2.2.1. Response เมื่อเกิดข้อผิดพลาด
ถ้า request ล้มเหลวเพราะ redirection URI หายไป ไม่ถูกต้อง หรือไม่ตรงกัน หรือเพราะ client identifier หายไปหรือไม่ถูกต้อง authorization server SHOULD แจ้ง resource owner ว่าเกิดข้อผิดพลาด และ MUST NOT redirect user-agent ไปยัง redirection URI ที่ไม่ถูกต้องนั้นโดยอัตโนมัติ
ถ้า resource owner ปฏิเสธ access request หรือ request ล้มเหลวด้วยเหตุอื่นที่ไม่ใช่ redirection URI หายไปหรือไม่ถูกต้อง authorization server จะแจ้ง client โดยเพิ่ม parameter ต่อไปนี้ลงใน fragment component ของ redirection URI ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B:
-
error: REQUIRED error code แบบ ASCII [USASCII] เพียงค่าเดียวจากรายการต่อไปนี้:
invalid_request request ไม่มี parameter ที่จำเป็น มีค่า parameter ที่ไม่ถูกต้อง มี parameter ซ้ำมากกว่าหนึ่งครั้ง หรือมีรูปแบบผิดด้วยเหตุอื่น
unauthorized_client client ไม่ได้รับอนุญาตให้ขอ access token ด้วยวิธีนี้
access_denied resource owner หรือ authorization server ปฏิเสธ request
unsupported_response_type authorization server ไม่รองรับการขอ access token ด้วยวิธีนี้
invalid_scope scope ที่ขอไม่ถูกต้อง ไม่รู้จัก หรือมีรูปแบบผิด
server_error authorization server พบเงื่อนไขที่ไม่คาดคิดซึ่งทำให้ทำตาม request ไม่ได้ (ต้องมี error code นี้เพราะส่ง HTTP status code 500 Internal Server Error กลับไปที่ client ผ่าน HTTP redirect ไม่ได้)
temporarily_unavailable authorization server ไม่สามารถจัดการ request ได้ในขณะนี้ เพราะ server โอเวอร์โหลดชั่วคราวหรืออยู่ระหว่างการบำรุงรักษา (ต้องมี error code นี้เพราะส่ง HTTP status code 503 Service Unavailable กลับไปที่ client ผ่าน HTTP redirect ไม่ได้)
ค่าของ parameter "error" MUST NOT มีตัวอักษรนอกเซต %x20-21 / %x23-5B / %x5D-7E
-
error_description: OPTIONAL ข้อความ ASCII [USASCII] ที่คนอ่านได้ ให้ข้อมูลเพิ่มเติมเพื่อช่วยผู้พัฒนา client เข้าใจข้อผิดพลาดที่เกิดขึ้น ค่าของ parameter "error_description" MUST NOT มีตัวอักษรนอกเซต %x20-21 / %x23-5B / %x5D-7E
-
error_uri: OPTIONAL URI ที่ชี้ไปยังหน้าเว็บที่คนอ่านได้ซึ่งมีข้อมูลเกี่ยวกับข้อผิดพลาด ใช้ให้ข้อมูลเพิ่มเติมเกี่ยวกับข้อผิดพลาดแก่ผู้พัฒนา client ค่าของ parameter "error_uri" MUST เป็นไปตามไวยากรณ์ URI-reference จึง MUST NOT มีตัวอักษรนอกเซต %x21 / %x23-5B / %x5D-7E
-
state: REQUIRED ถ้า parameter "state" อยู่ใน authorization request ของ client ค่าเดิมทุกประการที่ได้รับจาก client
ตัวอย่างเช่น authorization server redirect user-agent โดยส่ง HTTP response ต่อไปนี้:
HTTP/1.1 302 Found
Location: https://client.example.com/cb#error=access_denied&state=xyz
4.3. Resource Owner Password Credentials Grant
resource owner password credentials grant type เหมาะกับกรณีที่ resource owner มีความสัมพันธ์ไว้วางใจกับ client เช่น ระบบปฏิบัติการของอุปกรณ์ หรือแอปพลิเคชันที่มีสิทธิ์สูง authorization server ควรระมัดระวังเป็นพิเศษเมื่อเปิดใช้ grant type นี้ และอนุญาตเฉพาะเมื่อ flow อื่นใช้ไม่ได้
grant type นี้เหมาะกับ client ที่ขอ credentials ของ resource owner (username และ password โดยทั่วไปผ่านฟอร์มที่ให้กรอก) ได้ นอกจากนี้ยังใช้ย้าย client เดิมที่ใช้ direct authentication scheme เช่น HTTP Basic หรือ Digest authentication ไปเป็น OAuth ได้ โดยแปลง credentials ที่เก็บไว้เป็น access token
sequenceDiagram
participant RO as Resource Owner
participant C as Client
participant AS as Authorization Server
RO->>C: (A) Resource Owner Password Credentials
C->>AS: (B) Resource Owner Password Credentials
AS-->>C: (C) Access Token (w/ Optional Refresh Token)
Figure 5: flow ของ resource owner password credentials
flow ใน Figure 5 มีขั้นตอนดังนี้:
-
(A) resource owner ให้ username และ password ของตนแก่ client
-
(B) client ขอ access token จาก token endpoint ของ authorization server โดยส่ง credentials ที่ได้รับจาก resource owner ไปด้วย ตอนส่ง request นี้ client ยืนยันตัวตนกับ authorization server
-
(C) authorization server ยืนยันตัวตนของ client และตรวจสอบ credentials ของ resource owner ถ้าถูกต้องจึงออก access token
4.3.1. Authorization Request และ Response
วิธีที่ client ได้ credentials ของ resource owner มาอยู่นอกขอบเขตของข้อกำหนดนี้ client MUST ลบ credentials ทิ้งทันทีที่ได้ access token แล้ว
4.3.2. Access Token Request
client ส่ง request ไปยัง token endpoint โดยเพิ่ม parameter ต่อไปนี้ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B ด้วยการเข้ารหัสอักขระ UTF-8 ใน entity-body ของ HTTP request:
-
grant_type: REQUIRED. ค่า MUST ถูกตั้งค่าเป็น "password".
-
username: REQUIRED username ของ resource owner
-
password: REQUIRED password ของ resource owner
-
scope: OPTIONAL scope ของ access request ตามที่อธิบายใน Section 3.3
ถ้า client เป็นประเภท confidential หรือ client ได้รับ client credentials (หรือถูกกำหนดข้อกำหนดด้านการยืนยันตัวตนอื่น) client MUST ยืนยันตัวตนกับ authorization server ตามที่อธิบายใน Section 3.2.1
ตัวอย่างเช่น client ส่ง HTTP request ต่อไปนี้ผ่าน transport-layer security (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=password&username=johndoe&password=A3ddj3w
authorization server MUST:
-
บังคับให้ confidential client หรือ client ใดที่ได้รับ client credentials (หรือมีข้อกำหนดด้านการยืนยันตัวตนอื่น) ต้องทำ client authentication,
-
ยืนยันตัวตนของ client ถ้ามี client authentication มาด้วย และ
-
ตรวจสอบ resource owner password credentials ด้วย algorithm ตรวจสอบ password ที่มีอยู่เดิมของตน
เนื่องจาก access token request นี้ใช้ password ของ resource owner authorization server MUST ปกป้อง endpoint จาก brute force attack (เช่น ใช้ rate-limitation หรือสร้าง alert)
4.3.3. Access Token Response
ถ้า access token request ถูกต้องและได้รับอนุญาต authorization server จะออก access token และ refresh token (ถ้ามี) ตามที่อธิบายใน Section 5.1 ถ้า request ไม่ผ่าน client authentication หรือไม่ถูกต้อง authorization server จะส่ง error response ตามที่อธิบายใน Section 5.2
ตัวอย่าง response ที่สำเร็จ:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter":"example_value"
}
4.4. Client Credentials Grant
client ขอ access token โดยใช้เพียง client credentials ของตน (หรือวิธียืนยันตัวตนอื่นที่รองรับ) ได้ เมื่อ client ขอเข้าถึง protected resource ที่อยู่ในความควบคุมของตน หรือของ resource owner รายอื่นที่ตกลงไว้กับ authorization server ล่วงหน้า (วิธีตกลงอยู่นอกขอบเขตของข้อกำหนดนี้)
client credentials grant type MUST ใช้โดย confidential client เท่านั้น
sequenceDiagram
participant C as Client
participant AS as Authorization Server
C->>AS: (A) Client Authentication
AS-->>C: (B) Access Token
Figure 6: flow ของ client credentials
flow ใน Figure 6 มีขั้นตอนดังนี้:
-
(A) client ยืนยันตัวตนกับ authorization server และขอ access token จาก token endpoint
-
(B) authorization server ยืนยันตัวตนของ client ถ้าถูกต้องจึงออก access token
4.4.1. Authorization Request และ Response
เนื่องจากใช้ client authentication เป็น authorization grant จึงไม่ต้องมี authorization request เพิ่มเติม
4.4.2. Access Token Request
client ส่ง request ไปยัง token endpoint โดยเพิ่ม parameter ต่อไปนี้ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B ด้วยการเข้ารหัสอักขระ UTF-8 ใน entity-body ของ HTTP request:
-
grant_type: REQUIRED. ค่า MUST ถูกตั้งค่าเป็น "client_credentials".
-
scope: OPTIONAL scope ของ access request ตามที่อธิบายใน Section 3.3
client MUST ยืนยันตัวตนกับ authorization server ตามที่อธิบายใน Section 3.2.1
ตัวอย่างเช่น client ส่ง HTTP request ต่อไปนี้ผ่าน transport-layer security (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
authorization server MUST ยืนยันตัวตนของ client
4.4.3. Access Token Response
ถ้า access token request ถูกต้องและได้รับอนุญาต authorization server จะออก access token ตามที่อธิบายใน Section 5.1 SHOULD NOT ใส่ refresh token มาด้วย ถ้า request ไม่ผ่าน client authentication หรือไม่ถูกต้อง authorization server จะส่ง error response ตามที่อธิบายใน Section 5.2
ตัวอย่าง response ที่สำเร็จ:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"example_parameter":"example_value"
}
4.5. Extension Grants
client ใช้ extension grant type โดยระบุ grant type ด้วย absolute URI (ที่ authorization server กำหนด) เป็นค่าของ parameter "grant_type" ของ token endpoint และเพิ่ม parameter อื่นที่จำเป็น
ตัวอย่างเช่น เพื่อขอ access token โดยใช้ Security Assertion Markup Language (SAML) 2.0 assertion grant type ตามที่กำหนดใน [OAuth-SAML2] client อาจส่ง HTTP request ต่อไปนี้ผ่าน TLS (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
POST /token HTTP/1.1
Host: server.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Asaml2-
bearer&assertion=PEFzc2VydGlvbiBJc3N1ZUluc3RhbnQ9IjIwMTEtMDU
[...omitted for brevity...]aG5TdGF0ZW1lbnQ-PC9Bc3NlcnRpb24-
ถ้า access token request ถูกต้องและได้รับอนุญาต authorization server จะออก access token และ refresh token (ถ้ามี) ตามที่อธิบายใน Section 5.1 ถ้า request ไม่ผ่าน client authentication หรือไม่ถูกต้อง authorization server จะส่ง error response ตามที่อธิบายใน Section 5.2
5. การออก access token
ถ้า access token request ถูกต้องและได้รับอนุญาต authorization server จะออก access token และ refresh token (ถ้ามี) ตามที่อธิบายใน Section 5.1 ถ้า request ไม่ผ่าน client authentication หรือไม่ถูกต้อง authorization server จะส่ง error response ตามที่อธิบายใน Section 5.2
5.1. Response ที่สำเร็จ
authorization server ออก access token และ refresh token (ถ้ามี) แล้วสร้าง response โดยเพิ่ม parameter ต่อไปนี้ลงใน entity-body ของ HTTP response ที่มี status code 200 (OK):
-
access_token: REQUIRED access token ที่ authorization server ออกให้
-
token_type: REQUIRED ประเภทของ token ที่ออก ตามที่อธิบายใน Section 7.1 ค่าไม่แยกตัวพิมพ์ใหญ่เล็ก (case insensitive)
-
expires_in: RECOMMENDED อายุของ access token เป็นวินาที เช่น ค่า "3600" หมายความว่า access token จะหมดอายุใน 1 ชั่วโมงนับจากเวลาที่สร้าง response ถ้าไม่ระบุ authorization server SHOULD บอกเวลาหมดอายุด้วยวิธีอื่น หรือระบุค่า default ไว้ในเอกสาร
-
refresh_token: OPTIONAL refresh token ซึ่งใช้ขอ access token ใหม่ภายใต้ authorization grant เดียวกันได้ ตามที่อธิบายใน Section 6
-
scope: OPTIONAL ถ้าเหมือนกับ scope ที่ client ขอ ไม่เช่นนั้นเป็น REQUIRED scope ของ access token ตามที่อธิบายใน Section 3.3
parameter ถูกใส่ไว้ใน entity-body ของ HTTP response โดยใช้ media type "application/json" ตามที่กำหนดใน [RFC4627] parameter จะถูก serialize เป็นโครงสร้าง JavaScript Object Notation (JSON) โดยเพิ่ม parameter แต่ละตัวไว้ที่ระดับบนสุดของโครงสร้าง ชื่อ parameter และค่าที่เป็น string ใส่เป็น JSON string ค่าตัวเลขใส่เป็น JSON number ลำดับของ parameter ไม่มีผลและเปลี่ยนไปได้
authorization server MUST รวม HTTP "Cache-Control" response header field [RFC2616] พร้อมค่า "no-store" ในทุก response ที่มี tokens, credentials หรือข้อมูลที่ละเอียดอ่อนอื่น ๆ รวมถึง "Pragma" response header field [RFC2616] พร้อมค่า "no-cache"
ตัวอย่างเช่น:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"access_token":"2YotnFZFEjr1zCsicMWpAA",
"token_type":"example",
"expires_in":3600,
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter":"example_value"
}
client MUST เพิกเฉยต่อชื่อค่าที่ไม่รู้จักใน response ข้อกำหนดนี้ไม่ได้กำหนดขนาดของ token และค่าอื่นที่ได้รับจาก authorization server client ไม่ควรสันนิษฐานเกี่ยวกับขนาดของค่า authorization server SHOULD ระบุขนาดของค่าทุกตัวที่ออกไว้ในเอกสาร
5.2. Response เมื่อเกิดข้อผิดพลาด
authorization server ตอบด้วย HTTP status code 400 (Bad Request) (เว้นแต่จะระบุเป็นอย่างอื่น) และใส่ parameter ต่อไปนี้ใน response:
-
error: REQUIRED error code แบบ ASCII [USASCII] เพียงค่าเดียวจากรายการต่อไปนี้:
invalid_request request ไม่มี parameter ที่จำเป็น มีค่า parameter ที่ไม่รองรับ (ไม่นับ grant type) ส่ง parameter ซ้ำ มี credentials หลายชุด ใช้กลไกยืนยันตัวตนของ client มากกว่าหนึ่งกลไก หรือมีรูปแบบผิดด้วยเหตุอื่น
invalid_client client authentication ล้มเหลว (เช่น ไม่รู้จัก client, ไม่มี client authentication มาด้วย หรือใช้วิธียืนยันตัวตนที่ไม่รองรับ) authorization server MAY ตอบ HTTP status code 401 (Unauthorized) เพื่อบอกว่ารองรับ HTTP authentication scheme ใดบ้าง ถ้า client พยายามยืนยันตัวตนผ่าน request header field "Authorization" authorization server MUST ตอบ HTTP status code 401 (Unauthorized) และใส่ response header field "WWW-Authenticate" ที่ตรงกับ authentication scheme ที่ client ใช้
invalid_grant authorization grant ที่ให้มา (เช่น authorization code, credentials ของ resource owner) หรือ refresh token ไม่ถูกต้อง หมดอายุ ถูกเพิกถอน ไม่ตรงกับ redirection URI ที่ใช้ใน authorization request หรือถูกออกให้ client อื่น
unauthorized_client client ที่ยืนยันตัวตนแล้วไม่ได้รับอนุญาตให้ใช้ authorization grant type นี้
unsupported_grant_type authorization server ไม่รองรับ authorization grant type นี้
invalid_scope scope ที่ขอไม่ถูกต้อง ไม่รู้จัก มีรูปแบบผิด หรือเกิน scope ที่ resource owner ให้ไว้
ค่าของ parameter "error" MUST NOT มีตัวอักษรนอกเซต %x20-21 / %x23-5B / %x5D-7E
-
error_description: OPTIONAL ข้อความ ASCII [USASCII] ที่คนอ่านได้ ให้ข้อมูลเพิ่มเติมเพื่อช่วยผู้พัฒนา client เข้าใจข้อผิดพลาดที่เกิดขึ้น ค่าของ parameter "error_description" MUST NOT มีตัวอักษรนอกเซต %x20-21 / %x23-5B / %x5D-7E
-
error_uri: OPTIONAL URI ที่ชี้ไปยังหน้าเว็บที่คนอ่านได้ซึ่งมีข้อมูลเกี่ยวกับข้อผิดพลาด ใช้ให้ข้อมูลเพิ่มเติมเกี่ยวกับข้อผิดพลาดแก่ผู้พัฒนา client ค่าของ parameter "error_uri" MUST เป็นไปตามไวยากรณ์ URI-reference จึง MUST NOT มีตัวอักษรนอกเซต %x21 / %x23-5B / %x5D-7E
parameter ถูกใส่ไว้ใน entity-body ของ HTTP response โดยใช้ media type "application/json" ตามที่กำหนดใน [RFC4627] parameter จะถูก serialize เป็นโครงสร้าง JSON โดยเพิ่ม parameter แต่ละตัวไว้ที่ระดับบนสุดของโครงสร้าง ชื่อ parameter และค่าที่เป็น string ใส่เป็น JSON string ค่าตัวเลขใส่เป็น JSON number ลำดับของ parameter ไม่มีผลและเปลี่ยนไปได้
ตัวอย่างเช่น:
HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"error":"invalid_request"
}
6. การ refresh access token
ถ้า authorization server ออก refresh token ให้ client แล้ว client ส่ง refresh request ไปยัง token endpoint โดยเพิ่ม parameter ต่อไปนี้ในรูปแบบ "application/x-www-form-urlencoded" ตาม Appendix B ด้วยการเข้ารหัสอักขระ UTF-8 ใน entity-body ของ HTTP request:
-
grant_type: REQUIRED. ค่า MUST ถูกตั้งค่าเป็น "refresh_token".
-
refresh_token: REQUIRED. refresh token ที่ออกให้ client.
-
scope: OPTIONAL scope ของ access request ตามที่อธิบายใน Section 3.3 scope ที่ขอ MUST NOT มี scope ที่ resource owner ไม่ได้ให้ไว้ตั้งแต่แรก และถ้าไม่ระบุ จะถือว่าเท่ากับ scope ที่ resource owner ให้ไว้ตั้งแต่แรก
เนื่องจาก refresh token มักเป็น credentials ที่มีอายุยาวและใช้ขอ access token เพิ่ม refresh token จึงผูกกับ client ที่ได้รับมัน ถ้า client เป็นประเภท confidential หรือ client ได้รับ client credentials (หรือถูกกำหนดข้อกำหนดด้านการยืนยันตัวตนอื่น) client MUST ยืนยันตัวตนกับ authorization server ตามที่อธิบายใน Section 3.2.1
ตัวอย่างเช่น client ส่ง HTTP request ต่อไปนี้ผ่าน transport-layer security (ขึ้นบรรทัดใหม่เพิ่มเพื่อการแสดงผลเท่านั้น):
POST /token HTTP/1.1
Host: server.example.com
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
Content-Type: application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA
authorization server MUST:
-
บังคับให้ confidential client หรือ client ใดที่ได้รับ client credentials (หรือมีข้อกำหนดด้านการยืนยันตัวตนอื่น) ต้องทำ client authentication,
-
ยืนยันตัวตนของ client ถ้ามี client authentication มาด้วย และตรวจสอบว่า refresh token ถูกออกให้ client ที่ยืนยันตัวตนแล้ว และ
-
ตรวจสอบ refresh token.
ถ้าถูกต้องและได้รับอนุญาต authorization server จะออก access token ตามที่อธิบายใน Section 5.1 ถ้า request ไม่ผ่านการตรวจสอบหรือไม่ถูกต้อง authorization server จะส่ง error response ตามที่อธิบายใน Section 5.2
authorization server MAY ออก refresh token ใหม่ ซึ่งในกรณีนั้น client MUST ทิ้ง refresh token เก่าแล้วใช้ refresh token ใหม่แทน authorization server MAY เพิกถอน refresh token เก่าหลังออก refresh token ใหม่ให้ client ถ้าออก refresh token ใหม่ scope ของ refresh token MUST เหมือนกับ scope ของ refresh token ที่ client ส่งมาใน request
7. การเข้าถึง protected resource
client เข้าถึง protected resource โดยแสดง access token ให้ resource server resource server MUST ตรวจสอบ access token และให้แน่ใจว่ายังไม่หมดอายุและ scope ของมันครอบคลุมทรัพยากรที่ขอ วิธีที่ resource server ใช้ตรวจสอบ access token (รวมถึง error response ใด ๆ) อยู่นอกขอบเขตของข้อกำหนดนี้ แต่โดยทั่วไปต้องมีการโต้ตอบหรือประสานงานกันระหว่าง resource server กับ authorization server
วิธีการที่ client ใช้ access token เพื่อให้ตนเองได้รับการยืนยันตัวตนกับ resource server ขึ้นอยู่กับประเภทของ access token ที่ออกโดย authorization server โดยทั่วไปแล้ว จะเกี่ยวข้องกับการใช้ HTTP "Authorization" request header field [RFC2617] พร้อมกับ authentication scheme ที่กำหนดโดยข้อกำหนดของประเภท access token ที่ใช้ เช่น [RFC6750]
7.1. ประเภทของ access token
access token type ให้ข้อมูลที่ client ต้องใช้เพื่อใช้ access token ส่ง protected resource request ได้สำเร็จ (พร้อม attribute เฉพาะของแต่ละ type) client MUST NOT ใช้ access token ถ้าไม่เข้าใจ token type นั้น
ตัวอย่างเช่น "bearer" token type ที่กำหนดใน [RFC6750] ใช้โดยใส่ access token string ลงใน request ได้เลย:
GET /resource/1 HTTP/1.1
Host: example.com
Authorization: Bearer mF_9.B5f-4.1JqM
ส่วน "mac" token type ที่กำหนดใน [OAuth-HTTP-MAC] ใช้โดยออก Message Authentication Code (MAC) key มาพร้อมกับ access token ซึ่งใช้ลงนามในบางส่วนของ HTTP request:
GET /resource/1 HTTP/1.1
Host: example.com
Authorization: MAC id="h480djs93hd8",
nonce="274312:dj83hs9s",
mac="kDZvddkndxvhGRXZhvuDjEWhGeE="
ตัวอย่างข้างต้นมีไว้เพื่อการอธิบายเท่านั้น นักพัฒนาควรปรึกษาเอกสาร [RFC6750] และ [OAuth-HTTP-MAC] ก่อนใช้งาน
คำนิยามของ access token type แต่ละแบบระบุ attribute เพิ่มเติม (ถ้ามี) ที่ส่งให้ client พร้อมกับ response parameter "access_token" และยังกำหนดวิธี HTTP authentication ที่ใช้ใส่ access token เมื่อส่ง protected resource request ด้วย
7.2. Response เมื่อเกิดข้อผิดพลาด
ถ้า resource access request ล้มเหลว resource server SHOULD แจ้ง client ถึงข้อผิดพลาด รายละเอียดของ error response เหล่านี้อยู่นอกขอบเขตของข้อกำหนดนี้ แต่เอกสารนี้สร้าง registry กลางไว้ใน Section 11.4 สำหรับค่า error ที่ใช้ร่วมกันระหว่าง OAuth token authentication scheme ต่าง ๆ
authentication scheme ใหม่ที่ออกแบบมาเพื่อ OAuth token authentication เป็นหลัก SHOULD กำหนดกลไกส่ง error status code ให้ client โดยค่า error ที่อนุญาตต้องลงทะเบียนไว้ใน error registry ที่ข้อกำหนดนี้สร้างขึ้น
scheme เหล่านั้น MAY จำกัดชุด error code ที่ใช้ได้ให้เป็นส่วนย่อยของค่าที่ลงทะเบียนไว้ ถ้าส่ง error code กลับมาด้วย parameter ที่มีชื่อ ชื่อ parameter SHOULD เป็น "error"
scheme อื่นที่ใช้กับ OAuth token authentication ได้ แต่ไม่ได้ออกแบบมาเพื่อวัตถุประสงค์นี้เป็นหลัก MAY ผูกค่า error ของตนกับ registry ด้วยวิธีเดียวกัน
authentication scheme ใหม่ MAY เลือกระบุให้ใช้ parameter "error_description" และ "error_uri" เพื่อส่งข้อมูลข้อผิดพลาดกลับ ในลักษณะเดียวกับที่ใช้ในข้อกำหนดนี้
8. ความสามารถในการขยาย
8.1. การกำหนด access token type
access token type กำหนดได้สองวิธี: ลงทะเบียนใน registry Access Token Types (ตามขั้นตอนใน Section 11.1) หรือใช้ absolute URI ที่ไม่ซ้ำกันเป็นชื่อ
type ที่ใช้ชื่อเป็น URI SHOULD จำกัดไว้เฉพาะ implementation เฉพาะของผู้ผลิตแต่ละราย ที่ไม่ได้ใช้ได้ทั่วไป และเฉพาะเจาะจงกับรายละเอียดการ implement ของ resource server ที่ใช้งาน
type อื่นทั้งหมด MUST ลงทะเบียน ชื่อ type MUST เป็นไปตาม ABNF ของ type-name ถ้าคำนิยาม type มี HTTP authentication scheme ใหม่ ชื่อ type SHOULD เหมือนกับชื่อ HTTP authentication scheme (ตามที่กำหนดใน [RFC2617]) token type "example" สงวนไว้ใช้ในตัวอย่าง
type-name = 1*name-char
name-char = "-" / "." / "_" / DIGIT / ALPHA
8.2. การกำหนด endpoint parameter ใหม่
request หรือ response parameter ใหม่สำหรับใช้กับ authorization endpoint หรือ token endpoint ถูกกำหนดและลงทะเบียนใน registry OAuth Parameters ตามขั้นตอนใน Section 11.2
ชื่อ parameter MUST เป็นไปตาม ABNF ของ param-name และไวยากรณ์ของค่า parameter MUST ถูกนิยามไว้อย่างชัดเจน (เช่น ใช้ ABNF หรืออ้างอิงไวยากรณ์ของ parameter ที่มีอยู่แล้ว)
param-name = 1*name-char
name-char = "-" / "." / "_" / DIGIT / ALPHA
parameter ส่วนขยายเฉพาะของผู้ผลิตที่ไม่ได้ลงทะเบียน ซึ่งไม่ได้ใช้ได้ทั่วไปและเฉพาะเจาะจงกับรายละเอียดการ implement ของ authorization server ที่ใช้งาน SHOULD ใช้ prefix เฉพาะของผู้ผลิตที่ไม่น่าจะชนกับค่าอื่นที่ลงทะเบียนไว้ (เช่น ขึ้นต้นด้วย 'companyname_')
8.3. การกำหนด authorization grant type ใหม่
กำหนด authorization grant type ใหม่ได้โดยกำหนด absolute URI ที่ไม่ซ้ำกันให้ เพื่อใช้กับ parameter "grant_type" ถ้า extension grant type ต้องใช้ parameter เพิ่มเติมของ token endpoint parameter เหล่านั้น MUST ลงทะเบียนใน registry OAuth Parameters ตามที่อธิบายใน Section 11.2
8.4. การกำหนด response type ใหม่ของ authorization endpoint
response type ใหม่สำหรับใช้กับ authorization endpoint ถูกกำหนดและลงทะเบียนใน registry Authorization Endpoint Response Types ตามขั้นตอนใน Section 11.3 ชื่อ response type MUST เป็นไปตาม ABNF ของ response-type
response-type = response-name *( SP response-name )
response-name = 1*response-char
response-char = "_" / DIGIT / ALPHA
ถ้า response type มีช่องว่างหนึ่งตัวหรือมากกว่า (%x20) จะถูกเปรียบเทียบเป็นรายการค่าที่คั่นด้วยช่องว่าง ซึ่งลำดับของค่าไม่มีผล ลงทะเบียนได้เพียงลำดับเดียวของค่า ซึ่งครอบคลุมการเรียงลำดับอื่นทั้งหมดของชุดค่าเดียวกัน
ตัวอย่างเช่น response type "token code" ไม่ได้กำหนดไว้ในข้อกำหนดนี้ แต่ extension สามารถกำหนดและลงทะเบียน response type "token code" ได้ เมื่อลงทะเบียนแล้ว จะลงทะเบียนชุดค่าเดียวกันเป็น "code token" อีกไม่ได้ แต่ใช้ทั้งสองค่าเพื่อระบุ response type เดียวกันได้
8.5. การกำหนด error code เพิ่มเติม
ในกรณีที่ protocol extension (เช่น access token type, extension parameter หรือ extension grant type) ต้องใช้ error code เพิ่มเติมกับ error response ของ authorization code grant (Section 4.1.2.1), error response ของ implicit grant (Section 4.2.2.1), token error response (Section 5.2) หรือ resource access error response (Section 7.2) ก็ MAY กำหนด error code เหล่านั้นได้
extension error code MUST ลงทะเบียน (ตามขั้นตอนใน Section 11.4) ถ้า extension ที่ใช้ร่วมกันเป็น access token type ที่ลงทะเบียนแล้ว endpoint parameter ที่ลงทะเบียนแล้ว หรือ extension grant type error code ที่ใช้กับ extension ที่ไม่ได้ลงทะเบียน MAY ลงทะเบียนได้
error code MUST เป็นไปตาม ABNF ของ error และ SHOULD นำหน้าด้วยชื่อที่ระบุตัวตนเมื่อทำได้ ตัวอย่างเช่น error ที่ระบุว่าค่าที่ตั้งให้ extension parameter "example" ไม่ถูกต้อง SHOULD ตั้งชื่อว่า "example_invalid"
error = 1*error-char
error-char = %x20-21 / %x23-5B / %x5D-7E
9. Native application
native application คือ client ที่ติดตั้งและทำงานบนอุปกรณ์ที่ resource owner ใช้ (เช่น แอปพลิเคชันเดสก์ท็อป, native mobile application) native application ต้องพิจารณาเป็นพิเศษในเรื่องความปลอดภัย ความสามารถของแพลตฟอร์ม และประสบการณ์โดยรวมของ end-user
authorization endpoint ต้องมีการโต้ตอบระหว่าง client กับ user-agent ของ resource owner native application สามารถเรียก user-agent ภายนอก หรือฝัง user-agent ไว้ในแอปพลิเคชันได้ ตัวอย่างเช่น:
-
External user-agent - native application รับ response จาก authorization server ได้โดยใช้ redirection URI ที่มี scheme ซึ่งลงทะเบียนไว้กับระบบปฏิบัติการเพื่อเรียก client เป็นตัวจัดการ, คัดลอก credentials แล้ววางด้วยมือ, รัน web server ในเครื่อง, ติดตั้ง extension ของ user-agent หรือระบุ redirection URI ที่ชี้ไปยังทรัพยากรบน server ที่อยู่ในความควบคุมของ client ซึ่งจะส่ง response ต่อให้ native application อีกที
-
Embedded user-agent - native application ได้ response โดยสื่อสารกับ embedded user-agent โดยตรง ด้วยการเฝ้าดูการเปลี่ยนแปลงของ state ที่ปล่อยออกมาระหว่างโหลด resource หรือเข้าถึง cookie storage ของ user-agent
เมื่อเลือกระหว่าง external user-agent กับ embedded user-agent ผู้พัฒนาควรพิจารณาสิ่งต่อไปนี้:
-
external user-agent อาจช่วยให้ทำกระบวนการสำเร็จมากขึ้น เพราะ resource owner อาจมี session ที่ active กับ authorization server อยู่แล้ว จึงไม่ต้องยืนยันตัวตนซ้ำ ทั้งยังให้ประสบการณ์และฟังก์ชันที่ end-user คุ้นเคย resource owner ยังอาจพึ่งพาฟีเจอร์หรือ extension ของ user-agent เพื่อช่วยยืนยันตัวตน (เช่น password manager, อุปกรณ์อ่านรหัส 2-factor)
-
embedded user-agent อาจใช้งานได้สะดวกกว่า เพราะไม่ต้องสลับบริบทและเปิดหน้าต่างใหม่
-
embedded user-agent เป็นความท้าทายด้านความปลอดภัย เพราะ resource owner ต้องยืนยันตัวตนในหน้าต่างที่ระบุตัวตนไม่ได้ และไม่มีการป้องกันด้านภาพที่พบใน external user-agent ส่วนใหญ่ embedded user-agent ยังสอนให้ end-user เชื่อถือคำขอยืนยันตัวตนที่ระบุที่มาไม่ได้ (ทำให้โจมตีแบบ phishing ได้ง่ายขึ้น)
เมื่อเลือกระหว่าง implicit grant type กับ authorization code grant type ควรพิจารณาสิ่งต่อไปนี้:
-
native application ที่ใช้ authorization code grant type SHOULD ใช้โดยไม่มี client credentials เนื่องจาก native application เก็บ client credentials เป็นความลับไม่ได้
-
เมื่อใช้ flow ของ implicit grant type จะไม่มีการส่ง refresh token กลับมา จึงต้องทำกระบวนการขอการอนุญาตซ้ำเมื่อ access token หมดอายุ
10. ข้อควรพิจารณาด้านความปลอดภัย
OAuth เป็น framework ที่ยืดหยุ่นและขยายได้ ข้อควรพิจารณาด้านความปลอดภัยของ OAuth จึงขึ้นกับหลายปัจจัย ส่วนต่อไปนี้ให้แนวทางด้านความปลอดภัยแก่ผู้ implement โดยเน้นที่ client profile สามแบบที่อธิบายใน Section 2.1 ได้แก่ web application, user-agent-based application และ native application
[OAuth-THREATMODEL] ให้ security model และการวิเคราะห์ของ OAuth แบบครอบคลุม รวมถึงที่มาของการออกแบบโปรโตคอล
10.1. Client Authentication
authorization server กำหนด client credentials ร่วมกับ client ที่เป็น web application เพื่อใช้ client authentication authorization server ควรพิจารณาวิธี client authentication ที่แข็งแรงกว่า client password web application client MUST รักษาความลับของ client password และ client credentials อื่น
authorization server MUST NOT ออก client password หรือ client credentials อื่นให้ client ที่เป็น native application หรือ user-agent-based application เพื่อใช้ client authentication authorization server MAY ออก client password หรือ credentials อื่นสำหรับการติดตั้ง native application client บนอุปกรณ์เครื่องใดเครื่องหนึ่งโดยเฉพาะ
เมื่อทำ client authentication ไม่ได้ authorization server SHOULD ใช้วิธีอื่นตรวจสอบตัวตนของ client เช่น กำหนดให้ลงทะเบียน client redirection URI หรือให้ resource owner ช่วยยืนยันตัวตน redirection URI ที่ถูกต้องไม่พอจะยืนยันตัวตนของ client ตอนขอการอนุญาตจาก resource owner แต่ใช้ป้องกันไม่ให้ส่ง credentials ไปให้ client ปลอมหลังจากได้รับการอนุญาตจาก resource owner แล้วได้
authorization server ต้องพิจารณาผลด้านความปลอดภัยของการโต้ตอบกับ client ที่ไม่ได้ยืนยันตัวตน และดำเนินมาตรการจำกัดความเสี่ยงที่ credentials อื่น (เช่น refresh token) ที่ออกให้ client เหล่านั้นจะถูกเปิดเผย
10.2. การปลอมเป็น client
client ที่เป็นอันตรายอาจปลอมเป็น client อื่นและเข้าถึง protected resource ได้ ถ้า client ที่ถูกปลอมไม่รักษา client credentials ของตนเป็นความลับ หรือรักษาไม่ได้
authorization server MUST ยืนยันตัวตนของ client ทุกครั้งที่ทำได้ ถ้า authorization server ยืนยันตัวตนของ client ไม่ได้เพราะธรรมชาติของ client authorization server MUST บังคับให้ลงทะเบียน redirection URI ใดที่ใช้รับ authorization response และ SHOULD ใช้วิธีอื่นปกป้อง resource owner จาก client ที่อาจเป็นอันตรายเหล่านี้ ตัวอย่างเช่น authorization server อาจให้ resource owner ช่วยระบุ client และ origin ของมัน
authorization server SHOULD บังคับให้ resource owner ยืนยันตัวตนอย่างชัดแจ้ง และให้ข้อมูลเกี่ยวกับ client ตลอดจน scope และอายุของการอนุญาตที่ขอแก่ resource owner resource owner เป็นผู้ทบทวนข้อมูลนี้ในบริบทของ client ปัจจุบัน แล้วตัดสินใจอนุญาตหรือปฏิเสธ request
authorization server SHOULD NOT ประมวลผล authorization request ที่ส่งซ้ำโดยอัตโนมัติ (โดยไม่มี resource owner โต้ตอบจริง) ถ้าไม่ได้ยืนยันตัวตนของ client หรือไม่ได้อาศัยมาตรการอื่นเพื่อให้แน่ใจว่า request ที่ส่งซ้ำมาจาก client ตัวเดิม ไม่ใช่ผู้ปลอมตัว
10.3. Access token
credentials ของ access token (รวมถึง attribute ที่เป็นความลับของ access token) MUST เก็บเป็นความลับทั้งระหว่างส่งและระหว่างเก็บ และแบ่งปันเฉพาะระหว่าง authorization server, resource server ที่ access token ใช้ได้ และ client ที่ได้รับ access token นั้น credentials ของ access token MUST ส่งผ่าน TLS เท่านั้น ตามที่อธิบายใน Section 1.6 พร้อมการยืนยันตัวตนของ server ตามที่กำหนดใน [RFC2818]
เมื่อใช้ implicit grant type, access token จะถูกส่งใน URI fragment ซึ่งอาจเปิดเผยให้บุคคลที่ไม่มีสิทธิ์เข้าถึงได้
authorization server MUST ทำให้แน่ใจว่าบุคคลที่ไม่ได้รับอนุญาตไม่สามารถสร้าง แก้ไข หรือเดา access token เพื่อให้ได้ access token ที่ใช้ได้จริง
client SHOULD ขอ access token ด้วย scope น้อยที่สุดเท่าที่จำเป็น authorization server SHOULD นำตัวตนของ client มาพิจารณาเมื่อเลือกว่าจะให้ scope ที่ขอมากน้อยเพียงใด และ MAY ออก access token ที่มีสิทธิ์น้อยกว่าที่ขอ
ข้อกำหนดนี้ไม่ได้ให้วิธีการใด ๆ แก่ resource server เพื่อให้แน่ใจว่า access token ที่ client ตัวหนึ่งแสดงต่อมัน ถูก authorization server ออกให้ client ตัวนั้นจริง
10.4. Refresh token
authorization server MAY ออก refresh token ให้ web application client และ native application client
refresh token MUST เก็บเป็นความลับทั้งระหว่างส่งและระหว่างเก็บ และแบ่งปันเฉพาะระหว่าง authorization server กับ client ที่ได้รับ refresh token นั้น authorization server MUST รักษาการผูกระหว่าง refresh token กับ client ที่ได้รับมัน refresh token MUST ส่งผ่าน TLS เท่านั้น ตามที่อธิบายใน Section 1.6 พร้อมการยืนยันตัวตนของ server ตามที่กำหนดใน [RFC2818]
authorization server MUST ตรวจสอบการผูกระหว่าง refresh token กับตัวตนของ client ทุกครั้งที่ยืนยันตัวตนของ client ได้ เมื่อทำ client authentication ไม่ได้ authorization server SHOULD ใช้วิธีอื่นตรวจจับการใช้ refresh token ในทางที่ผิด
ตัวอย่างเช่น authorization server อาจใช้ refresh token rotation ซึ่งออก refresh token ใหม่ทุกครั้งที่ตอบ access token refresh response ส่วน refresh token ตัวก่อนหน้าจะถูกทำให้ใช้ไม่ได้ แต่ authorization server ยังเก็บไว้ ถ้า refresh token ถูกบุกรุกแล้วทั้งผู้โจมตีและ client ตัวจริงนำมาใช้ภายหลัง ฝ่ายใดฝ่ายหนึ่งจะแสดง refresh token ที่ใช้ไม่ได้แล้ว ซึ่งทำให้ authorization server รู้ว่ามีการละเมิดเกิดขึ้น
authorization server MUST ทำให้แน่ใจว่าบุคคลที่ไม่ได้รับอนุญาตไม่สามารถสร้าง แก้ไข หรือเดา refresh token เพื่อให้ได้ refresh token ที่ใช้ได้จริง
10.5. Authorization code
การส่ง authorization code SHOULD ทำผ่านช่องทางที่ปลอดภัย และ client SHOULD บังคับให้ใช้ TLS กับ redirection URI ของตน ถ้า URI นั้นชี้ไปยังทรัพยากรบนเครือข่าย เนื่องจาก authorization code ถูกส่งผ่านการ redirect ของ user-agent จึงอาจรั่วไหลผ่านประวัติของ user-agent และ HTTP referrer header ได้
authorization code ทำหน้าที่เป็น bearer credentials แบบ plaintext ใช้ยืนยันว่า resource owner ที่ให้การอนุญาตที่ authorization server เป็นคนเดียวกับ resource owner ที่กลับมาที่ client เพื่อทำกระบวนการให้เสร็จ ดังนั้น ถ้า client พึ่ง authorization code ในการยืนยันตัวตน resource owner ของตนเอง client redirection endpoint MUST บังคับให้ใช้ TLS
authorization code MUST มีอายุสั้นและใช้ได้ครั้งเดียว ถ้า authorization server พบความพยายามหลายครั้งในการแลก authorization code เป็น access token authorization server SHOULD พยายามเพิกถอน access token ทั้งหมดที่ให้ไปแล้วจาก authorization code ที่ถูกบุกรุกนั้น
หาก client สามารถยืนยันตัวตนได้, authorization servers MUST ยืนยัน client และตรวจสอบว่า authorization code ถูกออกให้กับ client เดียวกัน.
10.6. การแก้ไข redirection URI ของ authorization code
เมื่อขอการอนุญาตด้วย authorization code grant type client สามารถระบุ redirection URI ผ่าน parameter "redirect_uri" ได้ ถ้าผู้โจมตีแก้ค่า redirection URI ได้ ก็อาจทำให้ authorization server redirect user-agent ของ resource owner พร้อม authorization code ไปยัง URI ที่ผู้โจมตีควบคุมอยู่
ผู้โจมตีสร้างบัญชีที่ client ตัวจริงแล้วเริ่ม authorization flow เมื่อ user-agent ของผู้โจมตีถูกส่งไปที่ authorization server เพื่อให้สิทธิ์เข้าถึง ผู้โจมตีจะเก็บ authorization URI ที่ client ตัวจริงให้มา แล้วแทนที่ redirection URI ของ client ด้วย URI ที่ผู้โจมตีควบคุม จากนั้นผู้โจมตีหลอกให้เหยื่อกดลิงก์ที่ถูกแก้นั้นเพื่ออนุญาตการเข้าถึงให้ client ตัวจริง
เมื่อเหยื่อมาถึง authorization server เหยื่อจะเห็น request ปกติที่ถูกต้องในนามของ client ที่ถูกต้องและน่าเชื่อถือ แล้วอนุญาต request นั้น จากนั้นเหยื่อถูก redirect พร้อม authorization code ไปยัง endpoint ที่ผู้โจมตีควบคุม ผู้โจมตีทำ authorization flow ให้เสร็จโดยส่ง authorization code ไปให้ client โดยใช้ redirection URI เดิมที่ client ให้ไว้ client แลก authorization code เป็น access token และผูกไว้กับบัญชี client ของผู้โจมตี ซึ่งตอนนี้สามารถเข้าถึง protected resource ที่เหยื่ออนุญาตไว้ (ผ่าน client) ได้
เพื่อป้องกันการโจมตีแบบนี้ authorization server MUST ทำให้แน่ใจว่า redirection URI ที่ใช้ขอ authorization code เหมือนกับ redirection URI ที่ให้มาตอนแลก authorization code เป็น access token authorization server MUST บังคับให้ public client และ SHOULD บังคับให้ confidential client ลงทะเบียน redirection URI ของตน ถ้า request ระบุ redirection URI มา authorization server MUST ตรวจสอบกับค่าที่ลงทะเบียนไว้
10.7. Resource Owner Password Credentials
resource owner password credentials grant type มักใช้เพราะเหตุผลด้าน legacy หรือการ migrate grant type นี้ลดความเสี่ยงโดยรวมจากการที่ client เก็บ username และ password แต่ไม่ได้ขจัดความจำเป็นที่ต้องเปิดเผย credentials ที่มีสิทธิ์สูงให้ client
grant type นี้มีความเสี่ยงสูงกว่า grant type อื่น เพราะยังคง password anti-pattern ที่โปรโตคอลนี้พยายามหลีกเลี่ยง client อาจใช้ password ในทางที่ผิด หรือ password อาจถูกเปิดเผยให้ผู้โจมตีโดยไม่ได้ตั้งใจ (เช่น ผ่านไฟล์ log หรือบันทึกอื่นที่ client เก็บไว้)
นอกจากนี้ เนื่องจาก resource owner ควบคุมกระบวนการอนุญาตไม่ได้ (การมีส่วนร่วมของ resource owner จบลงเมื่อมอบ credentials ให้ client) client จึงอาจได้ access token ที่มี scope กว้างกว่าที่ resource owner ต้องการ authorization server ควรพิจารณา scope และอายุของ access token ที่ออกผ่าน grant type นี้
authorization server และ client SHOULD ใช้ grant type นี้ให้น้อยที่สุด และใช้ grant type อื่นทุกครั้งที่ทำได้
10.8. ความลับของ request
access token, refresh token, password ของ resource owner และ client credentials MUST NOT ถูกส่งแบบไม่เข้ารหัส authorization code SHOULD NOT ถูกส่งแบบไม่เข้ารหัส
parameter "state" และ "scope" SHOULD NOT มีข้อมูลที่ละเอียดอ่อนของ client หรือ resource owner เป็น plain text เพราะอาจถูกส่งผ่านช่องทางที่ไม่ปลอดภัยหรือถูกเก็บอย่างไม่ปลอดภัย
10.9. การทำให้แน่ใจว่า endpoint เป็นของจริง
เพื่อป้องกัน man-in-the-middle attack authorization server MUST บังคับให้ใช้ TLS พร้อมการยืนยันตัวตนของ server ตามที่กำหนดใน [RFC2818] กับ request ทุกตัวที่ส่งไปยัง authorization endpoint และ token endpoint client MUST ตรวจสอบ TLS certificate ของ authorization server ตามที่กำหนดใน [RFC6125] และตามข้อกำหนดของตนเองเรื่องการยืนยันตัวตนของ server
10.10. การโจมตีด้วยการเดา credentials
authorization server MUST ป้องกันไม่ให้ผู้โจมตีเดา access token, authorization code, refresh token, password ของ resource owner และ client credentials
ความน่าจะเป็นที่ผู้โจมตีจะเดา token ที่สร้างขึ้น (และ credentials อื่นที่ไม่ได้ออกแบบให้ end-user จัดการ) ได้ MUST น้อยกว่าหรือเท่ากับ 2^(-128) และ SHOULD น้อยกว่าหรือเท่ากับ 2^(-160)
authorization server MUST ใช้วิธีอื่นปกป้อง credentials ที่ออกแบบให้ end-user ใช้
10.11. การโจมตีแบบ phishing
การใช้โปรโตคอลนี้และโปรโตคอลที่คล้ายกันอย่างแพร่หลายอาจทำให้ end-user ชินกับการถูก redirect ไปยังเว็บไซต์ที่ให้กรอก password ถ้า end-user ไม่ระวังตรวจสอบว่าเว็บไซต์เหล่านี้เป็นของจริงก่อนกรอก credentials ผู้โจมตีก็อาจใช้ความเคยชินนี้ขโมย password ของ resource owner ได้
ผู้ให้บริการควรพยายามให้ความรู้ end-user เกี่ยวกับความเสี่ยงของการโจมตีแบบ phishing และควรมีกลไกที่ช่วยให้ end-user ยืนยันได้ง่ายว่าไซต์ของตนเป็นของจริง ผู้พัฒนา client ควรพิจารณาผลด้านความปลอดภัยของวิธีที่ตนโต้ตอบกับ user-agent (เช่น external, embedded) และความสามารถของ end-user ในการตรวจสอบว่า authorization server เป็นของจริง
เพื่อลดความเสี่ยงของการโจมตีแบบ phishing authorization server MUST บังคับให้ใช้ TLS บนทุก endpoint ที่ใช้โต้ตอบกับ end-user
10.12. Cross-Site Request Forgery
Cross-site request forgery (CSRF) คือการโจมตีที่ผู้โจมตีทำให้ user-agent ของ end-user ที่เป็นเหยื่อเปิด URI ที่เป็นอันตราย (เช่น ส่งให้ user-agent เป็นลิงก์ รูปภาพ หรือการ redirect ที่หลอกลวง) ไปยัง server ที่เชื่อถือ (โดยทั่วไปเกิดจากการมี session cookie ที่ถูกต้องอยู่)
CSRF attack ต่อ redirection URI ของ client ทำให้ผู้โจมตีแทรก authorization code หรือ access token ของตนเองได้ ซึ่งอาจทำให้ client ใช้ access token ที่เกี่ยวกับ protected resource ของผู้โจมตีแทนของเหยื่อ (เช่น บันทึกข้อมูลบัญชีธนาคารของเหยื่อลงใน protected resource ที่ผู้โจมตีควบคุม)
client MUST implement CSRF protection ให้ redirection URI ของตน ซึ่งโดยทั่วไปทำโดยกำหนดให้ request ที่ส่งไปยัง endpoint ของ redirection URI ต้องมีค่าที่ผูก request กับสถานะที่ยืนยันตัวตนแล้วของ user-agent (เช่น hash ของ session cookie ที่ใช้ยืนยันตัวตนของ user-agent) client SHOULD ใช้ request parameter "state" เพื่อส่งค่านี้ไปให้ authorization server ตอนส่ง authorization request
เมื่อได้รับการอนุญาตจาก end-user แล้ว authorization server จะ redirect user-agent ของ end-user กลับไปที่ client พร้อมค่าผูกที่ต้องใช้ใน parameter "state" ค่าผูกนี้ทำให้ client ตรวจสอบความถูกต้องของ request ได้ โดยจับคู่ค่าผูกกับสถานะที่ยืนยันตัวตนแล้วของ user-agent ค่าผูกที่ใช้ทำ CSRF protection MUST มีค่าที่เดาไม่ได้ (ตามที่อธิบายใน Section 10.10) และสถานะที่ยืนยันตัวตนแล้วของ user-agent (เช่น session cookie, HTML5 local storage) MUST เก็บไว้ในที่ที่เข้าถึงได้เฉพาะ client และ user-agent (คือได้รับการปกป้องด้วย same-origin policy)
CSRF attack ต่อ authorization endpoint ของ authorization server ทำให้ผู้โจมตีได้รับการอนุญาตจาก end-user ให้ client ที่เป็นอันตรายโดยที่ end-user ไม่รู้ตัวและไม่ถูกแจ้งเตือน
authorization server MUST ใช้ CSRF protection สำหรับ authorization endpoint และทำให้ client ที่เป็นอันตรายไม่สามารถได้รับ authorization โดยไม่ได้รับความรู้และความยินยอมอย่างชัดเจนจาก resource owner.
10.13. Clickjacking
ใน clickjacking attack ผู้โจมตีลงทะเบียน client ที่ถูกต้องแล้วสร้างไซต์อันตรายที่โหลดหน้าเว็บ authorization endpoint ของ authorization server ใน iframe โปร่งใสซ้อนทับบนชุดปุ่มหลอก ซึ่งออกแบบมาอย่างระมัดระวังให้ไปอยู่ตรงใต้ปุ่มสำคัญบนหน้าอนุญาตพอดี เมื่อ end-user คลิกปุ่มที่มองเห็นซึ่งหลอกลวง end-user ก็กำลังคลิกปุ่มที่มองไม่เห็นบนหน้าอนุญาต (เช่นปุ่ม "Authorize") วิธีนี้ทำให้ผู้โจมตีหลอก resource owner ให้อนุญาตการเข้าถึงแก่ client ของตนโดยที่ end-user ไม่รู้ตัว
เพื่อป้องกันการโจมตีแบบนี้ native application SHOULD ใช้ browser ภายนอกแทนการฝัง browser ไว้ในแอปพลิเคชันเมื่อขอการอนุญาตจาก end-user สำหรับ browser รุ่นใหม่ส่วนใหญ่ authorization server สามารถบังคับไม่ให้ใช้ iframe ได้ด้วย header "x-frame-options" (ที่ไม่ใช่มาตรฐาน) header นี้มีสองค่าคือ "deny" และ "sameorigin" ซึ่งจะบล็อกการทำ framing ทั้งหมด หรือ framing โดยไซต์ที่มี origin ต่างกัน ตามลำดับ สำหรับ browser รุ่นเก่า ใช้เทคนิค frame-busting ด้วย JavaScript ได้ แต่อาจไม่ได้ผลในทุก browser
10.14. Code Injection และ Input Validation
code injection attack เกิดขึ้นเมื่อแอปพลิเคชันใช้ input หรือตัวแปรภายนอกอื่นโดยไม่ sanitize แล้วทำให้ logic ของแอปพลิเคชันถูกแก้ไข ซึ่งอาจทำให้ผู้โจมตีเข้าถึงอุปกรณ์หรือข้อมูลของแอปพลิเคชัน ทำให้เกิด denial of service หรือก่อให้เกิดผลข้างเคียงที่เป็นอันตรายได้หลากหลาย
authorization server และ client MUST sanitize (และ validate เมื่อทำได้) ค่าทุกตัวที่ได้รับ โดยเฉพาะค่าของ parameter "state" และ "redirect_uri"
10.15. Open Redirectors
authorization server, authorization endpoint, และ client redirection endpoint สามารถถูกกำหนดค่าไม่ถูกต้อง และทำงานเป็น open redirectors open redirector คือ endpoint ที่ใช้ parameter เพื่อทำการส่งต่อ user-agent โดยอัตโนมัติไปยังตำแหน่งที่ระบุโดยค่า parameter โดยไม่มีการตรวจสอบใด ๆ
open redirector ใช้ในการโจมตีแบบ phishing ได้ หรือผู้โจมตีอาจใช้เพื่อให้ end-user เข้าเว็บไซต์อันตราย โดยใช้ URI authority component ของปลายทางที่คุ้นเคยและน่าเชื่อถือ นอกจากนี้ ถ้า authorization server ให้ client ลงทะเบียน redirection URI เพียงบางส่วน ผู้โจมตีสามารถใช้ open redirector ที่ client ให้บริการอยู่สร้าง redirection URI ที่ผ่านการตรวจสอบของ authorization server แต่ส่ง authorization code หรือ access token ไปยัง endpoint ที่ผู้โจมตีควบคุม
10.16. การใช้ access token ในทางที่ผิดเพื่อปลอมเป็น resource owner ใน Implicit Flow
สำหรับ public client ที่ใช้ implicit flow ข้อกำหนดนี้ไม่มีวิธีให้ client ตรวจสอบได้ว่า access token ถูกออกให้ client ตัวใด
resource owner อาจยินยอมมอบสิทธิ์เข้าถึงทรัพยากรโดยให้ access token แก่ client ที่เป็นอันตรายของผู้โจมตีด้วยความเต็มใจ ซึ่งอาจเกิดจาก phishing หรืออุบายอื่น ผู้โจมตีอาจขโมย token ด้วยกลไกอื่นก็ได้ จากนั้นผู้โจมตีอาจพยายามปลอมเป็น resource owner โดยนำ access token ไปให้ public client ตัวจริงที่ถูกต้อง
ใน implicit flow (response_type=token) ผู้โจมตีสามารถสลับ token ใน response จาก authorization server ได้ง่าย โดยแทนที่ access token จริงด้วย token ที่เคยออกให้ผู้โจมตี
server ที่สื่อสารกับ native application ซึ่งอาศัยการส่ง access token มาทาง back channel เพื่อระบุผู้ใช้ของ client อาจถูกโจมตีในลักษณะเดียวกัน เมื่อผู้โจมตีสร้างแอปพลิเคชันที่ถูกดัดแปลงให้แทรก access token ที่ขโมยมาอันไหนก็ได้
public client ใดก็ตามที่สมมติว่ามีแต่ resource owner เท่านั้นที่ส่ง access token ที่ถูกต้องของทรัพยากรนั้นมาให้ได้ จะตกเป็นเหยื่อของการโจมตีแบบนี้
การโจมตีแบบนี้อาจทำให้ข้อมูลของ resource owner ที่ client ตัวจริงเก็บไว้รั่วไปถึงผู้โจมตี (client ที่เป็นอันตราย) และยังทำให้ผู้โจมตีทำการต่าง ๆ ที่ client ตัวจริงได้ด้วยสิทธิ์เดียวกับ resource owner ที่ให้ access token หรือ authorization code นั้นไว้แต่แรก
การยืนยันตัวตนของ resource owner ต่อ client อยู่นอกขอบเขตของข้อกำหนดนี้ ข้อกำหนดใดที่ใช้กระบวนการอนุญาตเป็นรูปแบบหนึ่งของการยืนยันตัวตน end-user แบบมอบหมายให้ client (เช่น บริการ sign-in ของบุคคลที่สาม) MUST NOT ใช้ implicit flow โดยไม่มีกลไกความปลอดภัยเพิ่มเติมที่ทำให้ client ตรวจสอบได้ว่า access token ถูกออกมาให้ตนใช้ (เช่น จำกัด audience ของ access token)
11. ข้อควรพิจารณาของ IANA
11.1. OAuth Access Token Types Registry
ข้อกำหนดนี้สร้าง registry OAuth Access Token Types
access token type ลงทะเบียนด้วยนโยบาย Specification Required ([RFC5226]) หลังช่วงทบทวนสองสัปดาห์ใน mailing list [email protected] ตามคำแนะนำของ Designated Expert หนึ่งคนขึ้นไป อย่างไรก็ตาม เพื่อให้จัดสรรค่าได้ก่อนเผยแพร่ Designated Expert อาจอนุมัติการลงทะเบียนได้เมื่อพอใจว่าข้อกำหนดนั้นจะถูกเผยแพร่
คำขอลงทะเบียนต้องส่งไปยัง mailing list [email protected] เพื่อทบทวนและให้ความเห็น โดยมีหัวเรื่องที่เหมาะสม (เช่น "Request for access token type: example")
ภายในช่วงทบทวน Designated Expert จะอนุมัติหรือปฏิเสธคำขอลงทะเบียน แล้วแจ้งการตัดสินใจนี้ไปยัง mailing list ที่ใช้ทบทวนและ IANA การปฏิเสธควรมีคำอธิบาย และถ้ามี ก็ควรมีข้อเสนอแนะว่าจะทำอย่างไรให้คำขอผ่าน
IANA ต้องรับการอัปเดต registry จาก Designated Expert เท่านั้น และควรส่งคำขอลงทะเบียนทั้งหมดไปยัง mailing list ที่ใช้ทบทวน
11.1.1. แม่แบบการลงทะเบียน
-
Type name: ชื่อที่ขอ (เช่น "example")
-
Additional Token Endpoint Response Parameters: response parameter เพิ่มเติมที่ส่งกลับมาพร้อม parameter "access_token" parameter ใหม่ MUST ลงทะเบียนแยกต่างหากใน registry OAuth Parameters ตามที่อธิบายใน Section 11.2
-
HTTP Authentication Scheme(s): ชื่อ HTTP authentication scheme (ถ้ามี) ที่ใช้ยืนยันตัวตนของ protected resource request ที่ใช้ access token ประเภทนี้
-
Change controller: สำหรับ RFC ที่เป็น Standards Track ให้ระบุ "IETF" สำหรับกรณีอื่น ให้ระบุชื่อของผู้รับผิดชอบ อาจใส่รายละเอียดอื่นด้วย (เช่น ที่อยู่ไปรษณีย์ ที่อยู่อีเมล URI ของหน้าแรก)
-
Specification document(s): การอ้างอิงถึงเอกสารที่ระบุ parameter นี้ โดยควรมี URI ที่ใช้ดึงสำเนาของเอกสารได้ อาจระบุส่วนที่เกี่ยวข้องด้วยแต่ไม่บังคับ
11.2. OAuth Parameters Registry
ข้อกำหนดนี้สร้าง registry OAuth Parameters
parameter เพิ่มเติมที่จะใส่ใน authorization endpoint request, authorization endpoint response, token endpoint request หรือ token endpoint response ลงทะเบียนด้วยนโยบาย Specification Required ([RFC5226]) หลังช่วงทบทวนสองสัปดาห์ใน mailing list [email protected] ตามคำแนะนำของ Designated Expert หนึ่งคนขึ้นไป อย่างไรก็ตาม เพื่อให้จัดสรรค่าได้ก่อนเผยแพร่ Designated Expert อาจอนุมัติการลงทะเบียนได้เมื่อพอใจว่าข้อกำหนดนั้นจะถูกเผยแพร่
คำขอลงทะเบียนต้องส่งไปยัง mailing list [email protected] เพื่อทบทวนและให้ความเห็น โดยมีหัวเรื่องที่เหมาะสม (เช่น "Request for parameter: example")
ภายในช่วงทบทวน Designated Expert จะอนุมัติหรือปฏิเสธคำขอลงทะเบียน แล้วแจ้งการตัดสินใจนี้ไปยัง mailing list ที่ใช้ทบทวนและ IANA การปฏิเสธควรมีคำอธิบาย และถ้ามี ก็ควรมีข้อเสนอแนะว่าจะทำอย่างไรให้คำขอผ่าน
IANA ต้องรับการอัปเดต registry จาก Designated Expert เท่านั้น และควรส่งคำขอลงทะเบียนทั้งหมดไปยัง mailing list ที่ใช้ทบทวน
11.2.1. แม่แบบการลงทะเบียน
-
Parameter name: ชื่อที่ขอ (เช่น "example")
-
Parameter usage location: ตำแหน่งที่ใช้ parameter ได้ ตำแหน่งที่เป็นไปได้คือ authorization request, authorization response, token request หรือ token response
-
Change controller: สำหรับ RFC ที่เป็น Standards Track ให้ระบุ "IETF" สำหรับกรณีอื่น ให้ระบุชื่อของผู้รับผิดชอบ อาจใส่รายละเอียดอื่นด้วย (เช่น ที่อยู่ไปรษณีย์ ที่อยู่อีเมล URI ของหน้าแรก)
-
Specification document(s): การอ้างอิงถึงเอกสารที่ระบุ parameter นี้ โดยควรมี URI ที่ใช้ดึงสำเนาของเอกสารได้ อาจระบุส่วนที่เกี่ยวข้องด้วยแต่ไม่บังคับ
11.2.2. เนื้อหาเริ่มต้นของ registry
เนื้อหาเริ่มต้นของ registry OAuth Parameters คือ:
-
Parameter name: client_id
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization request, token request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: client_secret
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): token request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: response_type
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: redirect_uri
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization request, token request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: scope
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization request, authorization response, token request, token response
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: state
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization request, authorization response
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: code
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization response, token request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: error_description
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization response, token response
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: error_uri
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization response, token response
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: grant_type
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): token request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: access_token
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization response, token response
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: token_type
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization response, token response
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: expires_in
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): authorization response, token response
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: username
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): token request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: password
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): token request
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Parameter name: refresh_token
-
Parameter usage location (ตำแหน่งที่ใช้ parameter): token request, token response
-
Change controller: IETF
-
Specification document(s): RFC 6749
11.3. OAuth Authorization Endpoint Response Types Registry
ข้อกำหนดนี้สร้าง registry OAuth Authorization Endpoint Response Types
response type เพิ่มเติมสำหรับใช้กับ authorization endpoint ลงทะเบียนด้วยนโยบาย Specification Required ([RFC5226]) หลังช่วงทบทวนสองสัปดาห์ใน mailing list [email protected] ตามคำแนะนำของ Designated Expert หนึ่งคนขึ้นไป อย่างไรก็ตาม เพื่อให้จัดสรรค่าได้ก่อนเผยแพร่ Designated Expert อาจอนุมัติการลงทะเบียนได้เมื่อพอใจว่าข้อกำหนดนั้นจะถูกเผยแพร่
คำขอลงทะเบียนต้องส่งไปยัง mailing list [email protected] เพื่อทบทวนและให้ความเห็น โดยมีหัวเรื่องที่เหมาะสม (เช่น "Request for response type: example")
ภายในช่วงทบทวน Designated Expert จะอนุมัติหรือปฏิเสธคำขอลงทะเบียน แล้วแจ้งการตัดสินใจนี้ไปยัง mailing list ที่ใช้ทบทวนและ IANA การปฏิเสธควรมีคำอธิบาย และถ้ามี ก็ควรมีข้อเสนอแนะว่าจะทำอย่างไรให้คำขอผ่าน
IANA ต้องรับการอัปเดต registry จาก Designated Expert เท่านั้น และควรส่งคำขอลงทะเบียนทั้งหมดไปยัง mailing list ที่ใช้ทบทวน
11.3.1. แม่แบบการลงทะเบียน
-
Response type name: ชื่อที่ขอ (เช่น "example")
-
Change controller: สำหรับ RFC ที่เป็น Standards Track ให้ระบุ "IETF" สำหรับกรณีอื่น ให้ระบุชื่อของผู้รับผิดชอบ อาจใส่รายละเอียดอื่นด้วย (เช่น ที่อยู่ไปรษณีย์ ที่อยู่อีเมล URI ของหน้าแรก)
-
Specification document(s): การอ้างอิงถึงเอกสารที่ระบุ type นี้ โดยควรมี URI ที่ใช้ดึงสำเนาของเอกสารได้ อาจระบุส่วนที่เกี่ยวข้องด้วยแต่ไม่บังคับ
11.3.2. เนื้อหาเริ่มต้นของ registry
เนื้อหาเริ่มต้นของ registry OAuth Authorization Endpoint Response Types คือ:
-
Response type name: code
-
Change controller: IETF
-
Specification document(s): RFC 6749
-
Response type name: token
-
Change controller: IETF
-
Specification document(s): RFC 6749
11.4. OAuth Extensions Error Registry
ข้อกำหนดนี้สร้าง registry OAuth Extensions Error
error code เพิ่มเติมที่ใช้ร่วมกับ protocol extension อื่น (เช่น extension grant type, access token type หรือ extension parameter) ลงทะเบียนด้วยนโยบาย Specification Required ([RFC5226]) หลังช่วงทบทวนสองสัปดาห์ใน mailing list [email protected] ตามคำแนะนำของ Designated Expert หนึ่งคนขึ้นไป อย่างไรก็ตาม เพื่อให้จัดสรรค่าได้ก่อนเผยแพร่ Designated Expert อาจอนุมัติการลงทะเบียนได้เมื่อพอใจว่าข้อกำหนดนั้นจะถูกเผยแพร่
คำขอลงทะเบียนต้องส่งไปยัง mailing list [email protected] เพื่อทบทวนและให้ความเห็น โดยมีหัวเรื่องที่เหมาะสม (เช่น "Request for error code: example")
ภายในช่วงทบทวน Designated Expert จะอนุมัติหรือปฏิเสธคำขอลงทะเบียน แล้วแจ้งการตัดสินใจนี้ไปยัง mailing list ที่ใช้ทบทวนและ IANA การปฏิเสธควรมีคำอธิบาย และถ้ามี ก็ควรมีข้อเสนอแนะว่าจะทำอย่างไรให้คำขอผ่าน
IANA ต้องรับการอัปเดต registry จาก Designated Expert เท่านั้น และควรส่งคำขอลงทะเบียนทั้งหมดไปยัง mailing list ที่ใช้ทบทวน
11.4.1. แม่แบบการลงทะเบียน
-
Error name: ชื่อที่ขอ (เช่น "example") ค่าของชื่อ error MUST NOT มีตัวอักษรนอกเซต %x20-21 / %x23-5B /%x5D-7E
-
Error usage location: ตำแหน่งที่ใช้ error ได้ ตำแหน่งที่เป็นไปได้คือ error response ของ authorization code grant (Section 4.1.2.1), error response ของ implicit grant (Section 4.2.2.1), token error response (Section 5.2) หรือ resource access error response (Section 7.2)
-
Related protocol extension: ชื่อของ extension grant type, access token type หรือ extension parameter ที่ใช้ร่วมกับ error code นี้
-
Change controller: สำหรับ RFC ที่เป็น Standards Track ให้ระบุ "IETF" สำหรับกรณีอื่น ให้ระบุชื่อของผู้รับผิดชอบ อาจใส่รายละเอียดอื่นด้วย (เช่น ที่อยู่ไปรษณีย์ ที่อยู่อีเมล URI ของหน้าแรก)
-
Specification document(s): การอ้างอิงถึงเอกสารที่ระบุ error code นี้ โดยควรมี URI ที่ใช้ดึงสำเนาของเอกสารได้ อาจระบุส่วนที่เกี่ยวข้องด้วยแต่ไม่บังคับ