Implementation Procedure
Prerequisites
- A custom authentication function has been created. For details, see section "Creating a Function from Scratch" in the FunctionGraph User Guide. The function's return value must have a context field with key-value pairs, where the values are limited to string, boolean, or integer. The key-value pair corresponds to the Parameter Name and Condition Value of the System parameter - Frontend authentication parameter configured in Policy Conditions.
Figure 1 Custom authentication function
- A custom frontend authorizer has been created. If no custom authorizer is available, create one by following the instructions in section "Custom Authorizer" in the API Gateway User Guide.
Configuring the API Frontend
- Log in to the APIG console.
- Select a gateway at the top of the navigation pane.
- In the navigation pane, choose API Management > APIs.
- Click Create API > Create API and configure the frontend.
Table 1 Frontend configuration Parameter
Description
API Name
Enter a name that conforms to specific rules to facilitate search.
Group
The default option is DEFAULT.
URL
Method: Request method of the API. Default: GET.
Protocol: Request protocol of the API. Default: HTTPS.
Subdomain Name: The system automatically allocates a subdomain name to each API group for internal testing. The subdomain name can be accessed 1,000 times a day.
Path: Path for requesting the API. In this example, enter /1234.
Gateway Response
Select a response to be displayed if the gateway fails to process an API request.
The default gateway response is default.
Authentication Mode
API authentication mode. Select Custom.
Custom Authorizer
Select the custom authorizer created in Prerequisites.
Configuring the API Backend
- After configuring the frontend, click Next.
Set Backend Type to Mock and enter Default backend in the Response.
- Click to add a backend policy based on the following table.
Table 2 Policy backend configuration Parameter
Description
Name
Enter a policy name that conforms to specific rules to facilitate search.
Backend Type
Select Mock.
Response
Enter Policy backend.
Policy Conditions
- Source: Select System parameter - Frontend authentication parameter.
- Parameter Name: Enter authstatus1 under the context field in the response body of the custom authentication function created in Prerequisites.
- Condition Type: Select Equal.
- Condition Value: Enter False under the context field in the response body of the custom authentication function created in Prerequisites.
- Click Finish.
Debugging the API
The Mock backend type helps you view the result with a response. For other backend types, you can check whether the backend address is successfully accessed.
- On the APIs page, click Debug to debug the created API.
If 200 OK is displayed in Response, the API is successfully invoked. If the Policy backend is also returned, the configured policy backend condition matches the key-value pair in the context field in the response body of the custom authentication function, and the API invokes the policy backend. Otherwise, rectify the fault by following the instructions provided in "Published API Calling" > "Error Codes" in the API Gateway User Guide.
- On the APIs page, click Modify. The API configuration page is displayed.
- Click Next. On the backend configuration page, change Condition Value of the added policy to True.
- Click Finish.
- Debug the API again.
The policy backend parameter and condition value do not match any key-value pair of the frontend custom authentication function. Therefore, the API policy backend cannot be matched based on the frontend authentication parameters. In this case, 200 OK is displayed with the return result of Default backend, indicating that the default backend of the API is invoked. Otherwise, rectify the fault by following the instructions provided in "Published API Calling" > "Error Codes" in the API Gateway User Guide.
Feedback
Was this page helpful?
Provide feedbackThank 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