Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
Software Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Authentication

Updated on 2024-12-02 GMT+08:00
Requests for calling an API can be authenticated using either of the following methods:
  • AK/SK authentication: Requests are encrypted using AK/SK pairs. AK/SK authentication is recommended because it is more secure than token authentication.
  • Token authentication: Requests are authenticated using tokens.

AK/SK Authentication

An AK/SK is used to verify the identity of a request sender. In AK/SK authentication, a signature needs to be obtained and then added to requests.

NOTE:

AK: access key ID, which is a unique identifier used in conjunction with a secret access key to sign requests cryptographically.

SK: secret access key, which is used in conjunction with an AK to sign requests cryptographically. It identifies a request sender and prevents the request from being modified.

The following uses a demo project to show how to sign a request and use an HTTP client to send an HTTPS request.

Download the demo project at https://github.com/api-gate-way/SdkDemo.

If you do not need the demo project, visit the following URL to download the API Gateway signing SDK:

Obtain the API Gateway signing SDK from the enterprise administrator.

Decompress the downloaded package and reference the obtained JAR files as dependencies.

Figure 1 Introducing the API Gateway signing SDK
  1. Generate an AK/SK. (If you already have an AK/SK file, skip this step and find it. Generally, the file name is credentials.csv.)

    1. Log in to the management console.
    2. Click the username and select My Credentials from the drop-down list.
    1. In the navigation tree on the left, click Access Keys.
    2. Click Add Access Key.
    3. Enter an access key description and click OK.
    4. Enter the verification code received by email, SMS message, or MFA application.
      NOTE:

      If you have enabled operation protection (Security Settings > Critical Operations > Operation Protection), you need to enter the verification code.

      For users created in IAM that have not bound with any email address or mobile number, only the login password needs to be entered.

    5. Download the access key file.
      NOTE:

      Keep the access key secure.

  2. Download and decompress the demo project.
  3. Import the demo project to Eclipse.

    Figure 2 Selecting Existing Projects into Workspace
    Figure 3 Selecting the demo project
    Figure 4 Structure of the demo project

  4. Sign the request.

    The request signing method is integrated in the JAR files imported in 3. The request needs to be signed before it is sent. The signature will then be added as part of the HTTP header to the request.

    The demo code is classified into the following classes to demonstrate how to sign and send an HTTP request:

    • AccessService: an abstract class that merges the GET, POST, PUT, and DELETE methods into the access method
    • Demo: an execution entry used to simulate the sending of GET, POST, PUT, and DELETE requests
    • AccessServiceImpl: access method implementation, which contains the code required for communication with API Gateway
    1. Edit the main method in the Demo.java file, and replace the bold text with actual values.

      If you use other methods such as POST, PUT, and DELETE, see the corresponding comment.

      Specify region, serviceName, ak/sk, and url as the actual values. In this demo, the URLs for accessing VPC resources are used.

      To obtain the project ID in the URLs, see Obtaining a Project ID.

      To obtain the endpoint, contact the enterprise administrator.

       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
      //TODO: Replace region with the name of the region in which the service to be accessed is located. 
      private static final String region = "";
      
      //TODO: Replace vpc with the name of the service you want to access. For example, ecs, vpc, iam, and elb.
      private static final String serviceName = "";
      
      public static void main(String[] args) throws UnsupportedEncodingException
      {
      //TODO: Replace the AK and SK with those obtained on the My Credentials page.
      String ak = "ZIRRKMTWP******1WKNKB";
      String sk = "Us0mdMNHk******YrRCnW0ecfzl";
      
      //TODO: To specify a project ID (multi-project scenarios), add the X-Project-Id header.
      //TODO: To access a global service, such as IAM, DNS, CDN, and TMS, add the X-Domain-Id header to specify an account ID.
      //TODO: To add a header, find "Add special headers" in the AccessServiceImple.java file.
      
      //TODO: Test the API
      String url = "https://{Endpoint}/v1/{project_id}/vpcs";
      get(ak, sk, url);
      
      //TODO: When creating a VPC, replace {project_id} in postUrl with the actual value.
      //String postUrl = "https://serviceEndpoint/v1/{project_id}/cloudservers";
      //String postbody ="{\"vpc\": {\"name\": \"vpc\",\"cidr\": \"192.168.0.0/16\"}}";
      //post(ak, sk, postUrl, postbody);
      
      //TODO: When querying a VPC, replace {project_id} in url with the actual value.
      //String url = "https://serviceEndpoint/v1/{project_id}/vpcs/{vpc_id}";
      //get(ak, sk, url);
      
      //TODO: When updating a VPC, replace {project_id} and {vpc_id} in putUrl with the actual values.
      //String putUrl = "https://serviceEndpoint/v1/{project_id}/vpcs/{vpc_id}";
      //String putbody ="{\"vpc\":{\"name\": \"vpc1\",\"cidr\": \"192.168.0.0/16\"}}";
      //put(ak, sk, putUrl, putbody);
      
      //TODO: When deleting a VPC, replace {project_id} and {vpc_id} in deleteUrl with the actual values.
      //String deleteUrl = "https://serviceEndpoint/v1/{project_id}/vpcs/{vpc_id}";
      //delete(ak, sk, deleteUrl);
      }
      
    2. Compile the code and call the API.

      In the Package Explorer area on the left, right-click Demo.java and choose Run AS > Java Application from the shortcut menu to run the demo code.

      You can view API call logs on the console.

Token Authentication

NOTE:

The validity period of a token is 24 hours. When using a token for authentication, cache it to prevent frequently calling the IAM API used to obtain a user token.

A token specifies temporary permissions in a computer system. During API authentication using a token, the token is added to requests to get permissions for calling the API. You can obtain a token by calling the Obtaining User Token API.

IMS is a project-level service. When you call the API, set auth.scope in the request body to project.

{
    "auth": {
        "identity": {
            "methods": [
                "password"
            ],
            "password": {
                "user": {
                    "name": "username",   // IAM user name
                    "password": $ADMIN_PASS,  //IAM user password. You are advised to store it in ciphertext in the configuration file or an environment variable and decrypt it when needed to ensure security.
                    "domain": {
                        "name": "domainname"  // Name of the domain to which the IAM user belongs
                    }
                }
            }
        },
        "scope": {
            "project": {
                "name": "xxxxxxxx"    // Project name
            }
        }
    }
}

After a token is obtained, the X-Auth-Token header field must be added to requests to specify the token when calling other APIs. For example, if the token is ABCDEFJ...., X-Auth-Token: ABCDEFJ.... can be added to a request as follows:

1
2
3
POST https://{{endpoint}}/v3/auth/projects
Content-Type: application/json
X-Auth-Token: ABCDEFJ....

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback