Updated on 2024-04-10 GMT+08:00

Creating a Token

Function

This API is used to create an access token.

URI

POST /v1/tokens

Request Parameters

Table 1 Parameters in the request body

Parameter

Mandatory

Type

Description

client_id

Yes

String

Unique ID of the client

client_secret

Yes

String

Secret string generated for the client to obtain authorization from services in subsequent calls

code

No

String

Authorization code received from the authorization service. This parameter is required when executing an authorization request to obtain access to the token.

device_code

No

String

Used only when the authorization type (grant_type) is the device code (urn:ietf:params:oauth:grant-type:device_code).

grant_type

Yes

String

Authorization type, which can be authorization code, device code, client credential, and refresh token

Enumerated value:

  • authorization_code
  • urn:ietf:params:oauth:grant-type:device_code

redirect_uri

No

String

Application URL that will receive the authorization code. The user authorizes a service to send a request to this URL.

refresh_token

No

String

Refresh token, which can be used to obtain a new access token after the original access token expires

scopes

No

Array of strings

List of scopes defined by a client to restrict permissions for access token authorization

Response Parameters

Status code: 200

Table 2 Parameters in the response body

Parameter

Type

Description

token_info

Object

Token information

Table 3 token_info

Parameter

Type

Description

access_token

String

Opaque token used to access IAM Identity Center resources assigned to users

expires_in

Integer

Expiration time (in seconds) of an access token

id_token

String

Opaque token used to identify a user

refresh_token

String

Refresh token, which can be used to obtain a new access token after the original access token expires

token_type

String

Used to notify the client that the returned token is an access token. The value is BearerToken currently.

Example Request

Creating an access token

POST https://{hostname}/v1/tokens

{
  "client_id" : "example_client_id",
  "client_secret" : "example_client_secret",
  "code" : "1234567890123456",
  "device_code" : null,
  "grant_type" : "authorization_code",
  "redirect_uri" : "https://example-redirect.example.com/redirect/url",
  "refresh_token" : null,
  "scopes" : [ "openid" ]
}

Example Response

Status code: 200

Successful

{
  "token_info" : {
    "access_token" : "example_access_token",
    "expires_in" : 1684955360,
    "id_token" : "example_access_token",
    "refresh_token" : null,
    "token_type" : "Bearer"
  }
}

Status Codes

For details, see Status Codes.

Error Codes

For details, see Error Codes.