هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

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
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

Creating a Frontend Custom Authorizer

Updated on 2022-12-05 GMT+08:00

Overview

To use your own API calling authentication system, create a custom authorizer.

Custom authorizers are classified into the following types:

  • Frontend: ROMA Connect uses a custom authentication function to authenticate API requests.
  • Backend: The backend service of an API uses a custom authentication function to authenticate requests forwarded by ROMA Connect.

This section describes how to create a frontend custom authorizer. Ensure that you have created a function backend before using it for a custom authorizer.

Creating a Function Backend for Frontend Authentication

  1. Log in to the ROMA Connect console. On the Instances page, click View Console next to a specific instance.
  2. In the navigation pane on the left, choose API Connect > Custom Backends. On the Backends tab page, click Create Backend.
  3. On the Create Backend page, set backend parameters and click Create.
    • Backend Request Method must be set to POST.
    • The input parameters are not required. The function backend will obtain the values of the header and query parameters from API requests.
    • For details about the settings of other parameters, see Creating a Function API.

    After the backend is created, the online IDE page is automatically displayed.

  4. Develop a function backend.

    In the upper left corner of the online IDE, choose File > Create Function Backend > Blank Template. In the dialog box displayed, click Yes. Compile a function script for security authentication and click Save.

    The function script used for frontend custom authentication must meet the following conditions:

    • For the request parameters obtained using the function script:
      • Header parameter: indicates the identity source parameter in Header defined in custom authentication. The parameter value is transferred from the API request that uses the frontend custom authentication. The called parameter in the function script is in the format of: body["headers"]["Parameter name"].
      • Query parameter: indicates the identity source parameter in Query defined in custom authentication. The parameter value is transferred from the API request that uses the frontend custom authentication. The called parameter in the function script is in the format of: body["queryStringParameters"]["Parameter name"].
      • Body parameter: user data defined when a custom authorizer is created. The format of calling the body parameter is body["user_data"].
      NOTE:

      During frontend custom authentication, the header and query parameters of API requests are placed in the headers and queryStringParameters parameters of the backend request body and transferred to the authentication function. Therefore, when the header and query parameters need to be called in a function script, the parameters need to be obtained from the backend request body. For details about the examples of headers and queryStringParameters in the backend request body, see Test Procedure Examples.

    • Response

      The response body cannot be greater than 1 MB. The response content must meet the following format:

      {
        "status": "allow/deny",
        "context": {
          "user": "abc"
        }
      }
      • status: identifies the authentication result. This field is mandatory. Only allow or deny is supported. allow indicates that the authentication is successful, and deny indicates that the authentication fails.
      • context: indicates the authentication response result. This field is mandatory. Only key-value pairs of the string type are supported. The key value does not support JSON objects or arrays.

        The data in the context is user-defined. After the authentication is successful, the data can be used as a system parameter (frontend authentication parameter) and mapped to the backend request parameter of the API. The system parameter name set in the API backend service must be the same as the parameter name in the context. The parameter name is case sensitive. The parameter name in context must start with a letter and contain 1 to 32 characters, including letters, digits, underscores (_), and hyphens (-).

    The following is an example of the Header parameter definition script:
    function execute(data){
      data=JSON.parse(data)
      body=data.body
      if(body["headers"]["test"]=='abc'){
        return{
          "status": "allow",
          "context": {
            "user": "abcd"
          }
        }
      }else{
        return{
          "status": "deny"
        }
      }
    }

    The following is an example of the Query parameter definition script:

    function execute(data){
      data=JSON.parse(data)
      body=data.body
      if(body["queryStringParameters"]["test"]=='abc'){
        return{
          "status": "allow",
          "context": {
            "user": "abcd"
          }
        }
      }else{
        return{
          "status": "deny"
        }
      }
    }

    The following is an example of the Body parameter definition script:

    function execute(data){
      data=JSON.parse(data)
      body=data.body
      if(body["user_data"]=='abc'){
        return{
          "status": "allow",
          "context": {
            "user": "abcd"
          }
        }
      }else{
        return{
          "status": "deny"
        }
      }
    }
  5. Test the function backend.

    In the upper right corner of the page, click Test. In the Test Parameters area, add request parameters required for authentication based on the definition of the function backend and click Test to send the request. If the value of status in the test result is allow, the test is successful.

    In the Test Parameters area, set backend request parameters. The Header, Query, and Body authentication parameters must be set in the Body parameter of the backend request. Based on the preceding script examples, the following describes how to set the authentication parameters:

    • Header parameter
      {
        "headers":{
          "test":"abc"
        }
      }
    • Query parameter
      {
        "queryStringParameters":{
          "test":"abc"
        }
      }
    • Body parameter
      {
        "user_data": "abc"
      }
  6. Deploy the function backend.

    After the backend test is complete, click Deploy in the upper right corner of the page. In the dialog box displayed, click Yes to deploy the function backend.

Creating a Frontend Custom Authorizer

Before creating a frontend custom authorizer, ensure that the function backend used for frontend custom authentication has been created. Otherwise, create a function backend first. For details, see Creating a Function Backend for Frontend Authentication.

  1. Log in to the ROMA Connect console. On the Instances page, click View Console next to a specific instance.
  2. In the navigation pane on the left, choose API Connect > API Management. On the Custom Authorizers tab page, click Create.
  3. In the Create Custom Authorizer dialog box, configure custom authorizer information and click Create.
    Table 1 Parameters for creating a frontend custom authorizer

    Parameter

    Description

    Name

    Enter a custom authorizer name. It is recommended that you enter a name based on naming rules to facilitate search.

    Type

    Select Frontend.

    Integration Application

    Select an integration application for the custom authorizer.

    Function URN

    Select a function backend for frontend custom authentication. Only function backends in the Deployed state can be selected.

    Identity Sources

    Add header or query request parameters used for authentication.

    If the value of Cache Duration is not 0, a request parameter must be added. When the authentication result is cached, this parameter is used as the cache index of the authentication result.

    Max. Cache Age (s)

    Set the time for caching authentication results. Value 0 means that authentication results will not be cached. The maximum value is 3600.

    Send Request Body

    Determine whether to send the API request body to the authentication function.

    User Data

    Enter custom parameters, which will be used together with Identity Sources for request authentication.

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