Updated on 2024-12-30 GMT+08:00

Obtaining an Authorization Code

Function

When a user accesses an integrated application, the application sends an authorization request (in redirection mode) to OneAccess. The user enters their username and password to complete the authentication. OneAccess redirects the user to the application callback address with an authorization code transferred in the code parameter.

Constraints

null

URI

GET /api/v1/oauth2/authorize

Table 1 Query Parameters

Parameter

Mandatory

Type

Description

response_type

Yes

String

Grant type. The value is fixed at code.

client_id

Yes

String

Application ID, which is a client ID allocated to an application after registration.

scope

No

String

Scope of the granted access. The value is fixed at get_user_info.

redirect_uri

No

String

Callback address for successful authorization. The address can be the callback address or the domain name entered during application registration. You are advised to set the address to the home page or the application user center. Note that URLEncode processing needs to be performed on the URI.

state

No

String

Application status, which is used to prevent CSRF attacks. After successful authorization, the status is returned during callback to verify the mapping between the authentication and callback requests. The status can contain letters and digits.

Request Parameters

None

Response Parameters

Status code: 302

Table 2 Response header parameters

Parameter

Type

Description

Location

String

Redirection address used after successful authentication. Example: https://example.com?code=z2D...&state=test

Example Requests

Obtain the OAuth 2.0 authorization code. The value of the grant type is fixed at code. Configure clientId generated in the application registration. Callback address after the grant is successful: https://example.com. The value of the scope of the granted access is fixed at get_user_info.

GET https://{domain_name}/api/v1/oauth2/authorize?response_type=code&client_id=NzZeWuiJa91dPSRdZQChMazIh13AW...&redirect_uri=https://example.com&scope=get_user_info&state=test

Example Responses

None

Status Codes

Status Code

Description

302

The login fails, and the user is redirected to the login page. The login is successful, and the user is redirected to redirect_uri with an authorization code. Example: https://example.com?code=z2D...&state=test

Error Codes

See Error Codes.