本文檔描述了您需要調用的端點以實施 OAuth 2.0 授權碼流程,以及其他在您的應用中實施認證所需的端點。
基本 URLhttps://apis.roblox.com/oauth
端點GET v1/authorizePOST v1/tokenPOST v1/token/introspectPOST v1/token/resourcesPOST v1/token/revokeGET v1/userinfoGET .well-known/openid-configuration
授權
GET v1/authorize
從用戶那裡獲取授權,以便使用其 Roblox 帳戶進行認證。 期待一個有效的授權 URL,並使用指定的參數構建。該端點支持 PKCE 認證。
查詢參數
| 名稱 | 描述 | 是否必需 | 範例 |
|---|---|---|---|
| client_id | 應用的客戶端 ID。 | 是 | 816547628409595165403873012 |
| redirect_uri | 用戶完成授權流程後重定向回的 URL。 | 是 | `https://www.roblox.com/example-redirect`` |
| scope | 請求的範圍,以空格分隔。使用 openid 範圍以接收 ID 令牌。使用 openid 和 profile 範圍以獲取更多用戶信息。 | 是 | openid profile |
| response_type | 應用希望返回的憑證。默認為授權碼授予類型。 | 是 | none,code |
| prompt | 指定向用戶顯示的認證和同意頁面。某些屏幕對於第三方應用是必需的,無法跳過。 | 否 | none,login,consent,select_account |
| nonce | 將令牌與客戶端綁定的加密數字。 | 否 | <random_value_1> |
| state | 防止跨站請求偽造的一個不透明值,這是一種惡意攻擊。授權後將返回到應用。 | 否 | <app-provided-opaque-value> |
| code_challenge | 將 code_challenge_method 應用到 code_verifier 的結果字符串。 | 否 | Base64-URL 編碼字符串 |
| code_challenge_method | 應用於 code_verifier 的函數。 | 否 | S256 |
請求
導向授權流程的範例請求https://apis.roblox.com/oauth/v1/authorize?client_id=816547628409595165403873012&redirect_uri=https://my-app.com/redirect&scope=openid&response_type=code&nonce=12345&state=6789
響應
調用此端點後,用戶將被重定向到指定的重定向 URL,其中包含授權碼在 code 查詢參數中。 授權碼:
- 有一分鐘的有效期。
- 只能使用一次。
- 使用一次後無效。
令牌交換
要獲取訪問 API 的令牌,將 授權碼 兌換為一組機密令牌。所有令牌端點支持兩種客戶端 身份驗證:
- 使用授權標頭的 HTTP 基本身份驗證方案: Authorization: Basic Base64 編碼(<client_id>:<client_secret>)。
- 在請求主體中作為參數發送客戶端 ID 和密碼。
以下列表描述了您從此端點獲得的各種令牌。
訪問令牌 - 表示創作者或用戶授權第三方應用訪問其受保護的 Roblox 資源。它是一個表示特定範圍、有效期限和其他訪問屬性的字符串。一旦 Roblox 授權伺服器向應用發出訪問令牌,該令牌:
- 有效期為 15 分鐘。
- 在到期之前可以多次使用。
- 如果應用用戶撤銷了授權,可以在到期之前使其無效。
刷新令牌 - 刷新授權會話。應用可以使用刷新令牌獲取一組新的令牌,包括訪問令牌、刷新令牌和 ID 令牌。刷新令牌:
- 有效期為 90 天。
- 在到期之前只能使用一次來刷新令牌。
- 如果應用用戶撤銷了授權,可以在到期之前使其無效。
ID 令牌 - 提供用戶身份已被驗證的證據。其內容取決於請求的範圍,可以包含基本的用戶信息,包括用戶的 Roblox 顯示名稱和用戶名。ID 令牌僅用於身份驗證目的,不提供訪問任何 Roblox 資源的權限。
POST v1/token
使用授權碼獲取一組令牌。
請求
(x-www-form-urlencoded)
| 鍵 | 值 |
|---|---|
| code | <authorization code> |
| code_verifier | <pkce code verifier value> |
| grant_type | authorization_code |
| client_id | <client_id> |
| client_secret | <client_secret> |
範例獲取令牌請求curl --location --request POST 'https://apis.roblox.com/oauth/v1/token' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'client_id=840974200211308101' \--data-urlencode 'client_secret=RBX-CR9...St12L' \--data-urlencode 'grant_type=authorization_code' \--data-urlencode 'code=yCnq4ofX1...XmGpdx'
響應
範例獲取令牌響應
{
"access_token": "...",
"refresh_token": "...",
"token_type": "Bearer",
"expires_in": 899,
"scope": "universe-messaging-service:publish"
}
POST v1/token
使用刷新令牌獲取一組令牌。
請求
(x-www-form-urlencoded)
| 鍵 | 值 |
|---|---|
| grant_type | refresh_token |
| refresh_token | <refresh_token> |
| client_id | <client_id> |
| client_secret | <client_secret> |
範例刷新令牌請求curl --location --request POST 'https://apis.roblox.com/oauth/v1/token' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'grant_type=refresh_token' \--data-urlencode 'refresh_token=Ujfstayclfdlbm...BGydlsnU' \--data-urlencode 'client_id=840974200211308101' \--data-urlencode 'client_secret=RBX-CR9...St12L'
響應
範例刷新令牌響應
{
"access_token": "...",
"refresh_token": "...",
"token_type": "Bearer",
"expires_in": 899,
"scope": "universe-messaging-service:publish"
}
POST v1/token/introspect
接收有關令牌的信息。驗證該令牌當前是否有效且尚未過期。對於無狀態驗證非常有用。僅在您訪問的 API 不需要資源(例如 Assets API)或者您只想查看令牌的特定聲明時使用。
請求
(x-www-form-urlencoded)
| 鍵 | 值 |
|---|---|
| token | <access_token>、<refresh_token> 或 <id_token> |
| client_id | <client_id> |
| client_secret | <client_secret> |
範例檢查令牌請求curl --location --request POST 'https://apis.roblox.com/oauth/v1/token/introspect' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'token=eyjlflabtfl...4gxqYBG' \--data-urlencode 'client_id=840974200211308101' \--data-urlencode 'client_secret=RBX-CR9...St12L'
響應
範例檢查令牌響應
{
"active": true,
"jti": "RT.2GcjvTduKzk6QY9tjTfm",
"iss": "https://apis.roblox.com/oauth/",
"token_type": "Bearer",
"client_id": "840974200211308101",
"aud": "4239311013248676173",
"sub": "1516563360",
"scope": "universe-messaging-service:publish",
"exp": 1676394509,
"iat": 1660842510
}
POST v1/token/resources
檢查令牌是否可以訪問特定資源,方法是獲取用戶授權的用戶資源列表。這對於有狀態驗證非常有用。
請求
(x-www-form-urlencoded)
| 鍵 | 值 |
|---|---|
| token | <access_token> |
| client_id | <client_id> |
| client_secret | <client_secret> |
範例獲取令牌資源請求curl --location --request POST 'https://apis.roblox.com/oauth/v1/token/resources' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'token=eyjlflabtfl...4gxqYBG' \--data-urlencode 'client_id=840974200211308101' \--data-urlencode 'client_secret=RBX-CR9...St12L'
響應
值 U 在 ids 中表明某個範圍已授予對授權 owner 擁有的資源的訪問權限。
範例獲取令牌資源響應
{
"resource_infos": [
{
"owner": {
"id": "1516563360",
"type": "User"
},
"resources": {
"universe": {
"ids": ["3828411582"]
},
"creator": {
"ids": ["U"]
}
}
}
]
}
POST v1/token/revoke
使用提供的刷新令牌撤銷授權會話。
請求
(x-www-form-urlencoded)
| 鍵 | 值 |
|---|---|
| token | <refresh_token> |
| client_id | <client_id> |
| client_secret | <client_secret> |
範例撤銷令牌請求curl --location --request POST 'https://apis.roblox.com/oauth/v1/token/revoke' \--header 'Content-Type: application/x-www-form-urlencoded' \--data-urlencode 'token=Ujfstayclfdlbm...BGydlsnU' \--data-urlencode 'client_id=840974200211308101' \--data-urlencode 'client_secret=RBX-CR9...St12L'
響應
200 OK,響應內容為空
用戶信息
GET /v1/userinfo
獲取 Roblox 用戶 ID 和其他用戶元數據。
請求
授權標頭: Authorization: Bearer <access_token>
範例獲取用戶信息請求curl --location --request GET 'https://apis.roblox.com/oauth/v1/userinfo' \--header 'Authorization: Bearer eyjlflabtfl...4gxqYBG'
響應
您可以使用 sub 值來唯一識別用戶。用戶可以更改其 Roblox 用戶名和顯示名稱,因此請勿將它們用作您應用中的唯一識別符。
| 聲明 | 描述 |
|---|---|
| sub | Roblox 用戶 ID。 |
| name | Roblox 顯示名稱。 |
| nickname | Roblox 顯示名稱。 |
| preferred_username | Roblox 用戶名。 |
| created_at | Roblox 帳戶的創建時間,為 Unix 時戳。 |
| profile | Roblox 帳戶個人資料 URL。 |
| picture | Roblox 角色頭像圖片。如果尚未生成或已經被審核,則可以為 null。 |
範例具有個人資料範圍的用戶
{
"sub": "1516563360",
"name": "exampleuser",
"nickname": "exampleuser",
"preferred_username": "exampleuser",
"created_at": 1584682495,
"profile": "https://www.roblox.com/users/1516563360/profile",
"picture": "https://tr.rbxcdn.com/03dc2a9abe7b1aacaaf93ea46d5c0646/150/150/AvatarHeadshot/Png"
}
範例無個人資料範圍的用戶
{
"sub": "1516563360"
}
发现
OpenID Connect (OIDC) 探索文檔是一個 JSON 文檔,其中包含有關 Open Cloud 配置詳細信息的元數據,包括支持的身份相關範圍和聲明的列表。您可以使用它來動態發現有關 Open Cloud OAuth 2.0 端點和配置的信息,例如授權端點、令牌端點和公鑰集。
在從探索文檔 URI 獲取和提取探索文檔後,您可以手動檢查響應中的字段以驗證信息,也可以創建您自己的自定義庫來映射響應架構中的字段以自動化工作流程。
GET .well-known/openid-configuration
響應
所有探索文檔的響應都遵循與以下示例響應相同的架構。
範例探索文檔響應
{
"issuer": "https://apis.roblox.com/oauth/",
"authorization_endpoint": "https://apis.roblox.com/oauth/v1/authorize",
"token_endpoint": "https://apis.roblox.com/oauth/v1/token",
"introspection_endpoint": "https://apis.roblox.com/oauth/v1/token/introspect",
"revocation_endpoint": "https://apis.roblox.com/oauth/v1/token/revoke",
"resources_endpoint": "https://apis.roblox.com/oauth/v1/token/resources",
"userinfo_endpoint": "https://apis.roblox.com/oauth/v1/userinfo",
"jwks_uri": "https://apis.roblox.com/oauth/v1/certs",
"registration_endpoint": "https://create.roblox.com/dashboard/credentials",
"service_documentation": "https://create.roblox.com/docs/reference/cloud",
"scopes_supported": [
"openid",
"profile",
"email",
"verification",
"credentials",
"age",
"premium",
"roles"
],
"response_types_supported": ["none", "code"],
"subject_types_supported": ["public"],
"id_token_signing_alg_values_supported": ["ES256"],
"claims_supported": [
"sub",
"type",
"iss",
"aud",
"exp",
"iat",
"nonce",
"name",
"nickname",
"preferred_username",
"created_at",
"profile",
"email",
"email_verified",
"verified",
"age_bracket",
"premium",
"roles",
"internal_user"
],
"token_endpoint_auth_methods_supported": [
"client_secret_post",
"client_secret_basic"
]
}