Creating OAuth Authorization
Function
This API is used to create OAuth authorization.
Debugging
You can debug this API in API Explorer which supports automatic authentication. API Explorer automatically generates sample SDK code and provides the debug function.
Authorization Information
Each account has all of the permissions required to call all APIs, but IAM users must have the required permissions specifically assigned.
- If you are using role/policy-based authorization, see the required permissions in Permissions and Supported Actions.
- If you are using identity policy-based authorization, the permission listed below is required.
Action
Access Level
Resource Type (*: required)
Condition Key
Alias
Dependencies
servicestage:repositoryAuth:create
write
repositoryAuth *
-
servicestage:app:create
-
URI
POST /v1/{project_id}/git/auths/{repo_type}/oauth
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| project_id | Yes | String | Definition Tenant's project ID. See Obtaining a Project ID. Constraints N/A Range N/A Default Value N/A |
| repo_type | Yes | String | Definition Code repository. Range
Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| tag | No | String | Definition Site label. Example: ?tag=intl, which indicates an international site. Range N/A Default Value N/A |
Request
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| Content-Type | Yes | String | Definition Message body type (or format). Constraints N/A Range application/json;charset=utf8 Default Value N/A |
| X-Auth-Token | Yes | String | Definition API calling can be authenticated using a token or AK/SK. If you use a token, this parameter is mandatory and must be set to the token. For details about how to obtain the token, see Authentication. Constraints N/A Range N/A Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| name | Yes | String | Definition Authorization name. Range N/A Default Value N/A |
| code | Yes | String | Definition code parameter in the redirection URL after Git repository authorization is performed. Range N/A Default Value N/A |
| state | Yes | String | Definition One-off authentication code and random string received after Git repository authorization is performed. Range N/A Default Value N/A |
To obtain the values of code and state, perform the following steps:
- Enter the URL obtained in Obtaining an Authorization Redirection URL in the address box of the browser and press Enter.
- On the login page, enter your code repository account and password.
If you have logged in to the code repository, skip this step.
- On the Huawei Cloud console login page, enter the account name and password, and click Log In.
If you have logged in to the Huawei Cloud console, skip this step.
- After the system displays a message indicating that the authorization fails to be created, copy the URL in the address box.
https://console.huaweicloud.com/servicestage/oauth?repo_type=github&code=04bed2df009f3fc9***c&state=%242a%2410%24.uQYThj5yKFs51w9s9ajeuQ0NSGshPH7IUfXoZLPlz7J%2FoAJ8B***
- Decode the obtained URL to obtain the decoded URL.
https://console.huaweicloud.com/servicestage/oauth?repo_type=github&code=04bed2df009f3fc9***c&state=$2a$10$.uQYThj5yKFs51w9s9ajeuQ0NSGshPH7IUfXoZLPlz7J/oAJ8B***
Obtain the values of code and state.
The value of the obtained state is a one-off authentication code and random string, which can be used only once. If you need to call this API again to create OAuth authorization, follow the steps in Obtaining an Authorization Redirection URL again to obtain the URL and obtain the values of code and state.
Response
| Parameter | Type | Description |
|---|---|---|
| authorization | Object | Definition Authorization structure. See Table 6. |
| Parameter | Type | Description |
|---|---|---|
| name | String | Definition Authorization name. Range N/A |
| repo_type | String | Definition Code repository. Range
|
| repo_host | String | Definition Repository address. Range N/A |
| repo_home | String | Definition Repository homepage. Range N/A |
| repo_user | String | Definition Repository username. Range N/A |
| avartar | String | Definition Repository avatar. Range N/A |
| token_type | String | Definition Repository authorization type. Range
|
| create_time | Long | Definition Repository authorization creation timestamp. Range N/A |
| update_time | Long | Definition Repository authorization update timestamp. Range N/A |
| status | Integer | Definition Repository authorization status. Range
|
Example Request
Create OAuth authorization auth1.
{
"name": "auth1",
"code": "04bed2df009f3fc9***c",
"state": "$2a$10$.uQYThj5yKFs51w9s9ajeuQ0NSGshPH7IUfXoZLPlz7J/oAJ8B***"
} Example Response
{
"authorization": {
"name": "auth1",
"repo_type": "github",
"repo_host": "https://api.github.com",
"repo_home": "https://github.com/tom-repo",
"repo_user": "repo",
"avartar": "https://avatars.githubusercontent.com/u/73919200?v=4",
"token_type": "oauth",
"create_time": 1649758626858,
"update_time": 1649758626858,
"status": 0
}
} Status Code
| Status Code | Description |
|---|---|
| 200 | OK |
| 400 | Bad Request |
Error Code
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot