Skip to Content
🚀 Welcome to Humansoft Open API Documentation

Authorization Code Flow

เริ่มต้น OAuth 2.0 Authorization Code Flow เพื่อขอ authorization code สำหรับนำไปแลกเป็น tokens

Authorization code ที่ได้รับมีอายุ 5 นาที และสามารถใช้ได้เพียงครั้งเดียว

Endpoint

GET /oauth2/v1/authorize

Request Parameters

ParameterTypeRequiredDescription
client_idstringClient application ID
redirect_uristringCallback URL (ต้องตรงกับที่ลงทะเบียนไว้)
response_typestringต้องเป็น code
scopestringRequested scopes (space-separated) เช่น openid profile email
statestringRandom string สำหรับ CSRF protection
code_challengestringPKCE code challenge (แนะนำสำหรับ public clients)
code_challenge_methodstringplain หรือ S256 (แนะนำ S256)
sourcestringที่มาของ request เช่น desktop-web (default: desktop-web)
user_idstringUser ID base64 encoded
user_typestringประเภท user เช่น hrs, admin-acp
instance_server_codestringInstance/tenant code

Available Scopes

ScopeDescription
openidRequired สำหรับ OIDC (ได้รับ id_token)
profileข้อมูล user profile (first_name, last_name, photograph, employee_code, user_type, instance_server_code)
emailUser email address

Response Format

Success Response (HTTP 302 Redirect)

เมื่อ authorization สำเร็จ ระบบจะ redirect ไปยัง redirect_uri พร้อม authorization code:

HTTP/1.1 302 Found Location: https://myapp.com/callback?code=AUTH_CODE_HERE&state=abc123

Error Response — Invalid Client

{ "error": "Invalid client_id", "message": "The provided client_id/redirect_uri does not exist or is not registered." }

Error Response — Invalid Scopes

{ "error": "Invalid scopes", "message": "The provided scopes are not available for the client_id.", "non_available_scopes": ["invalid_scope"] }

Code Examples

curl -X GET "https://auth.humansoft.co.th/oauth2/v1/authorize?\ client_id=my-app&\ redirect_uri=https://myapp.com/callback&\ response_type=code&\ scope=openid%20profile%20email&\ state=abc123&\ code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&\ code_challenge_method=S256"

Notes

  • redirect_uri ต้องตรงกับที่ลงทะเบียนไว้กับ client application เท่านั้น
  • state parameter ใช้สำหรับป้องกัน CSRF attack ควรเป็นค่า random ที่ไม่ซ้ำกัน และต้องตรวจสอบค่าที่ได้รับกลับมาด้วย
  • Token Endpoint - แลก authorization code เป็น tokens (Step 2)
  • User Info - ดึงข้อมูล user จาก access token
Last updated on