tencent cloud

All product documents
Customer Identity and Access Management
PKCE Authorization Code Mode
Last updated: 2023-12-22 11:42:07
PKCE Authorization Code Mode
Last updated: 2023-12-22 11:42:07

API Description

This API is used to get the Access Token and ID Token for login after the application system gets the code returned by the authentication portal through the Proof Key for Code Exchange (PKCE) authorization code mode.

Supported Applications

Web applications, single-page applications (SPA), and mobile applications.

Request Method

POST

Request Path

/oauth2/token

Request Content-Type

application/x-www-form-urlencoded

Sample Requests

POST /oauth2/token HTTP/1.1
Host: sample.portal.tencentciam.com
Content-Type: application/x-www-form-urlencoded

client_id=TENANT_CLIENT_ID&grant_type=authorization_code&code=MOCK_CODE&redirect_uri=https%3A%2F%2Fexample.com%2Fcallback&code_verifier=MOCK_CODE_VERIFIER

Request Parameters

Parameter
Optional
Description
client_id
false
The client_id of the application. This should be the same as the one used for getting the authorization code.
grant_type
false
Fixed value: authorization_code.
code
false
The authorization code returned.
redirect_uri
false
The redirected address after authorization. This should be the same as the one used for getting the authorization code.
code_verifier
false
PKCE code verifier. This should be the same as the code_verifier used to generate the code_challenge.

Sample Success Responses

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
"access_token" : "eyJraWQiOiJkNDliYzUwNS01NTcyLTRlZDYtOWU0OC0zODhjM2Q0NGJiNDYiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJNT0NLX1VTRVJOQU1FIiwiYXVkIjoiVEVOQU5UX0NMSUVOVF9JRCIsIm5iZiI6MTYzNjQ0OTIzMiwic2NvcGUiOlsib3BlbmlkIl0sImlzcyI6Imh0dHBzOlwvXC9URU5BTlQuUE9SVEFMLkRPTUFJTiIsImV4cCI6MTYzNjQ0OTUzMiwiaWF0IjoxNjM2NDQ5MjMyLCJqdGkiOiI0NjkyNTUxMC1mNjY0LTQzNTktODIyYS1jMTdiNTlmNzNhOGUifQ.mmM6iEiGCLIURqaKaJV_LbddUP1i5wCJMJvuasM8i6Wu_Ynix0W_EeghvMcQ94QvLh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FtjdL4L13d1VAMPs2F5fTFBHX-p9LjoqF2sIJFEBbapgOX5EO-E_v1IFQ",
"token_type" : "Bearer",
"expires_in" : 299
}

Response Parameters

Parameter
Data Type
Description
access_token
String
OAuth 2.0 Access Token (JWT).
refresh_token
String
OAuth 2.0 Refresh Token.
scope
String
Access Token scope.
id_token
String
OpenID Connect (OIDC) ID Token (JSON Web Token, or JWT).
token_type
String
Token type. Fixed value: Bearer.
expires_in
Number
Validity period of Access Token (unit: sec)
Note:
Customer Identity Access Management (CIAM) returns ID Token in JWT format. For more information about how to decrypt and verify the ID Token, see the OpenID Connect document. You can also use the development library for decryption and verification. You can get the public key for verification by calling the API for getting the JWT public key.

Sample Error Responses

The client_id parameter is missing or incorrect.
HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=UTF-8
{
"error" : "invalid_request"
}
The client_id is not the same as the one used for getting the authorization code and Token.
HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=UTF-8
{
"error" : "invalid_client"
}
The grant_type parameter is incorrect.
HTTP/1.1 401 Unauthorized
The code parameter is incorrect.
HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=UTF-8

{
"error" : "invalid_client"
}
The code_verifier parameter is incorrect.
HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=UTF-8
{
"error" : "invalid_client"
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support