Skip to Content
🚀 Welcome to Humansoft Open API Documentation

Token Endpoint

แลก authorization code เป็น tokens, refresh token เพื่อขอ access token ใหม่, หรือขอ token ด้วย client credentials

Endpoint นี้ส่ง response ตรงตามมาตรฐาน OAuth 2.0 โดยไม่ wrap ใน {code, payload}

Endpoint

POST /oauth2/v1/token Content-Type: application/json

Grant Type: authorization_code

แลก authorization code จาก Authorization Code Flow เป็น tokens

Request Parameters

ParameterTypeRequiredDescription
grant_typestringต้องเป็น authorization_code
codestringAuthorization code จาก authorization endpoint
client_idstringClient application ID
redirect_uristringต้องตรงกับ authorization request
client_secretstring🔷Required สำหรับ confidential clients (ถ้าไม่ได้ใช้ PKCE)
code_verifierstring🔷Required ถ้าใช้ PKCE

ต้องระบุ client_secret หรือ code_verifier อย่างใดอย่างหนึ่ง ขึ้นอยู่กับว่าใช้ Client Secret Authentication หรือ PKCE

Success Response

{ "token_type": "Bearer", "expires_in": 3600, "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjEyMyJ9...", "refresh_token": "REFRESH_TOKEN_STRING", "id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjEyMyJ9...", "scope": "openid profile email" }

id_token จะมีเฉพาะเมื่อ scope มี openid เท่านั้น

Access Token Payload (decoded)

{ "iss": "https://auth.humansoft.co.th", "aud": "my-app", "sub": "user-credential-id", "iat": 1735090800, "scope": "openid profile email", "user_id": "456" }

ID Token Payload (decoded)

{ "iss": "https://auth.humansoft.co.th", "aud": "my-app", "sub": "user-credential-id", "iat": 1735090800, "scope": "openid profile email", "user_credential_id": "123", "user_id": "456", "employee_code": "EMP001", "first_name": "John", "last_name": "Doe", "email": "john@example.com", "photograph": "https://...", "user_type": "hrs", "instance_server_code": "COMPANY_A" }

Code Examples

curl -X POST https://auth.humansoft.co.th/oauth2/v1/token \ -H "Content-Type: application/json" \ -d '{ "grant_type": "authorization_code", "code": "AUTH_CODE_HERE", "client_id": "my-app", "redirect_uri": "https://myapp.com/callback", "code_verifier": "VERIFIER_STRING" }'

Grant Type: refresh_token

ใช้ refresh token เพื่อขอ access token ใหม่โดยไม่ต้องให้ user login อีกครั้ง

Refresh token จะถูก rotate ทุกครั้งที่ใช้ — token เก่าจะถูกยกเลิกทันที ต้องใช้ refresh token ใหม่ที่ได้รับจาก response เสมอ

Request Parameters

ParameterTypeRequiredDescription
grant_typestringต้องเป็น refresh_token
refresh_tokenstringRefresh token จาก response ก่อนหน้า
client_idstringClient application ID

Success Response

{ "token_type": "Bearer", "expires_in": 3600, "access_token": "NEW_ACCESS_TOKEN", "refresh_token": "NEW_REFRESH_TOKEN", "scope": "openid profile email" }

Code Examples

curl -X POST https://auth.humansoft.co.th/oauth2/v1/token \ -H "Content-Type: application/json" \ -d '{ "grant_type": "refresh_token", "refresh_token": "REFRESH_TOKEN_STRING", "client_id": "my-app" }'

Grant Type: client_credentials

ขอ access token โดยใช้ client credentials โดยตรง สำหรับ machine-to-machine communication

Request Parameters

ParameterTypeRequiredDescription
grant_typestringต้องเป็น client_credentials
client_idstringClient application ID
client_secretstringClient secret

Success Response

{ "token_type": "Bearer", "expires_in": 3600, "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjEyMyJ9...", "scope": "" }

Code Examples

curl -X POST https://auth.humansoft.co.th/oauth2/v1/token \ -H "Content-Type: application/json" \ -d '{ "grant_type": "client_credentials", "client_id": "my-app", "client_secret": "CLIENT_SECRET" }'

Error Responses

Common Error Codes

Error CodeHTTP StatusDescription
invalid_request400Missing or invalid parameters
invalid_client401Client authentication failed
invalid_grant400Invalid authorization code or refresh token
unsupported_grant_type400Grant type not supported
invalid_scope400Requested scope is invalid
Last updated on