文档首页/ 数据治理中心 DataArts Studio/ API参考/ 数据服务API/ API管理接口/ API授权操作(授权/取消授权/申请/续约)
更新时间:2025-08-01 GMT+08:00
分享

API授权操作(授权/取消授权/申请/续约)

功能介绍

  • API主动授权: API审核人可发起,API主动授权成功后,在有效期内,APP即可访问该API。API授权包含授权和续约两部分功能。

    • 授权:授权会给予APP在有效期内访问API的权利。

    • 续约:续约会更新授权有效期,仅支持延长有效期,不能减少。

  • API解除授权: API审核人可发起,解除API对APP的授权关系。解除授权后,APP将不再能够调用该API。API解除已授权的APP关系,需要为APP预留至少2天的准备时间。

  • APP解除授权: APP所有者可发起,解除API对APP的授权关系。解除授权后,APP将不再能够调用该API。APP解除自己的授权关系,无需预留准备时间。

  • APP申请授权: APP所有者可发起,APP申请API后,待API的审核人完成审核,APP即可访问该API。授权会给予APP在有效期内访问API的权利,需要API审核。

  • APP申请续约: APP所有者可发起,续约会更新授权有效期,仅支持延长有效期,不能减少,需要API审核。

  • 申请自己的API推荐采用API主动授权/续约,无需审核。

  • 自己的应用推荐采用APP解除授权,无需预留准备时间。

调用方法

请参见如何调用API

URI

POST /v1/{project_id}/service/apis/authorize/action

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方法请参见项目ID和账号ID

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token,使用Token认证时必选。通过调用IAM服务的“获取用户Token”接口获取响应消息头中X-Subject-Token的值。

workspace

String

工作空间ID,获取方法请参见实例ID和工作空间ID

Dlm-Type

String

数据服务的版本类型,指定SHARED共享版或EXCLUSIVE专享版。

Content-Type

String

消息体的类型(格式),有Body体的情况下必选,没有Body体无需填写。如果请求消息体中含有中文字符,则需要通过charset=utf8指定中文字符集,例如取值为:application/json;charset=utf8。

表3 请求Body参数

参数

是否必选

参数类型

描述

api_id

String

API编号。

instance_id

String

集群ID编号。

app_id

String

APP编号。

apply_type

String

申请类型。

枚举值:

  • APPLY_TYPE_AUTHORIZE:API主动授权

  • APPLY_TYPE_API_CANCEL_AUTHORIZE:API取消授权

  • APPLY_TYPE_APP_CANCEL_AUTHORIZE:APP取消授权

  • APPLY_TYPE_APPLY:审核API

  • APPLY_TYPE_RENEW:续约API

time

String

截止时间。

响应参数

状态码:204

操作API成功。

状态码:400

表4 响应Body参数

参数

参数类型

描述

error_code

String

错误码。

error_msg

String

错误描述。

请求示例

API主动授权/API解除授权/APP解除授权/APP申请授权/APP申请续约。

/v1/0833a5737480d53b2f250010d01a7b88/service/apis/authorize/action

{
  "api_id" : "47046fe7830c1be77cb0dc23bd86afa5",
  "instance_id" : "21398ikjdsjd9087122d4e",
  "app_id" : "908489209a320df61607355c57c82882",
  "apply_type" : "APPLY_TYPE_AUTHORIZE",
  "time" : "2021-01-01T10:00:00.000Z"
}

响应示例

SDK代码示例

SDK代码示例如下。

API主动授权/API解除授权/APP解除授权/APP申请授权/APP申请续约。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.dataartsstudio.v1.region.DataArtsStudioRegion;
import com.huaweicloud.sdk.dataartsstudio.v1.*;
import com.huaweicloud.sdk.dataartsstudio.v1.model.*;


public class AuthorizeActionApiToInstanceSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        DataArtsStudioClient client = DataArtsStudioClient.newBuilder()
                .withCredential(auth)
                .withRegion(DataArtsStudioRegion.valueOf("<YOUR REGION>"))
                .build();
        AuthorizeActionApiToInstanceRequest request = new AuthorizeActionApiToInstanceRequest();
        ApiParaForAuthToInstance body = new ApiParaForAuthToInstance();
        body.withTime("2021-01-01T10:00:00.000Z");
        body.withApplyType(ApiParaForAuthToInstance.ApplyTypeEnum.fromValue("APPLY_TYPE_AUTHORIZE"));
        body.withAppId("908489209a320df61607355c57c82882");
        body.withInstanceId("21398ikjdsjd9087122d4e");
        body.withApiId("47046fe7830c1be77cb0dc23bd86afa5");
        request.withBody(body);
        try {
            AuthorizeActionApiToInstanceResponse response = client.authorizeActionApiToInstance(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

API主动授权/API解除授权/APP解除授权/APP申请授权/APP申请续约。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdataartsstudio.v1.region.dataartsstudio_region import DataArtsStudioRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdataartsstudio.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = DataArtsStudioClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DataArtsStudioRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = AuthorizeActionApiToInstanceRequest()
        request.body = ApiParaForAuthToInstance(
            time="2021-01-01T10:00:00.000Z",
            apply_type="APPLY_TYPE_AUTHORIZE",
            app_id="908489209a320df61607355c57c82882",
            instance_id="21398ikjdsjd9087122d4e",
            api_id="47046fe7830c1be77cb0dc23bd86afa5"
        )
        response = client.authorize_action_api_to_instance(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

API主动授权/API解除授权/APP解除授权/APP申请授权/APP申请续约。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dataartsstudio "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dataartsstudio/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := dataartsstudio.NewDataArtsStudioClient(
        dataartsstudio.DataArtsStudioClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.AuthorizeActionApiToInstanceRequest{}
	timeApiParaForAuthToInstance:= "2021-01-01T10:00:00.000Z"
	applyTypeApiParaForAuthToInstance:= model.GetApiParaForAuthToInstanceApplyTypeEnum().APPLY_TYPE_AUTHORIZE
	appIdApiParaForAuthToInstance:= "908489209a320df61607355c57c82882"
	instanceIdApiParaForAuthToInstance:= "21398ikjdsjd9087122d4e"
	apiIdApiParaForAuthToInstance:= "47046fe7830c1be77cb0dc23bd86afa5"
	request.Body = &model.ApiParaForAuthToInstance{
		Time: &timeApiParaForAuthToInstance,
		ApplyType: &applyTypeApiParaForAuthToInstance,
		AppId: &appIdApiParaForAuthToInstance,
		InstanceId: &instanceIdApiParaForAuthToInstance,
		ApiId: &apiIdApiParaForAuthToInstance,
	}
	response, err := client.AuthorizeActionApiToInstance(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

204

操作API成功。

400

BadRequest。

相关文档