Get Third-Party Authorization Info
POST/auth/v1/provider/token
API Description
Obtain authorization information from third-party services. For example, when logging in with OAuth, use this API to get the authorized user information for the OAuth client and generate a provider_token.
Input Requirements
client_id: Client ID corresponding to the application (optional, defaults to environment ID)x-device-id: Device ID (required, passed in the request header)- Request body parameters (
v1GrantProviderTokenRequest):provider_id: Identity provider ID (required, e.g., github, wechat)provider_code: Login code obtained from the third-party system (required, used to exchange for user identity)provider_redirect_uri: Identity provider callback URL (optional)
Prerequisites
- You must first obtain an authorization code (
code) via the third-party authorization flow. - The third-party identity provider must be configured in the CloudBase console.
Output
- Returns
provider_tokenandprovider_profile(v1GrantProviderTokenResponse). provider_tokenis used when calling subsequent login APIs.provider_profilecontains the basic information of the third-party user.
Request Example
POST /auth/v1/provider/token
x-device-id: device_123456
Content-Type: application/json
{
"provider_id": "github",
"provider_code": "authorization_code_from_github",
"provider_redirect_uri": "https://your-app.com/callback"
}
Response Example
{
"provider_token": "your_provider_token",
"expires_in": 3600,
"provider_profile": {
"provider_id": "github",
"sub": "1234567890",
"name": "Zhang San",
"picture": "https://avatars.githubusercontent.com/u/1234567890",
"email": "zhangsan@example",
"provider": "github"
}
}
Usage Flow
- After the user completes third-party authorization, obtain the authorization code (
code). - Call this API with the authorization code to exchange it for a
provider_token. - Use the
provider_tokento call the Third-party Authorization Info Login API to complete login.
Key Characteristics
- The
provider_tokenis valid for 3600 seconds (1 hour). - The returned
provider_profilecontains the full information of the third-party user. - Supports auto-registering a new user if the user does not exist.
- Supports binding to an existing user account.
Request
Responses
- 200
- 500
A successful response.
Response Headers
An unexpected error response.