BasicAuth plugin

更新时间:
复制 MD 格式

The BasicAuth plugin provides HTTP Basic Authentication for your APIs, allowing you to control access by defining usernames and passwords.

For more information about cross-domain resource access with BasicAuth, see this article.

Plugin configuration

You can configure the plugin in JSON or YAML format. Both formats use the same schema. To convert the configuration format, you can search for a YAML-to-JSON conversion tool. The following example shows a YAML configuration template.

---
users:
  - username: alice
     password: 123456
  - username: bob
     password: 666666
  - username: charlie
     password: 888888
  - username: dave
     password: 111111

BasicAuth plugin support for plugin datasets

Create a plug-in dataset

  1. Log on to the API Gateway console. In the navigation pane on the left, click API Management > Plug-in Management, and then click the Plug-in Datasets tab.

  2. In the upper-right corner, click Create Dataset. In the dialog box that appears, set a custom Name for the dataset, set Type to BASIC_AUTH_ACCESS, and then click OK.

  3. Go to the dataset that you created. In the upper-right corner, click Create Dataset Entry. On the page that appears, configure the username, password, and time-to-live (TTL) for the BasicAuth plug-in.

BasicAuth Plugin Configuration: Sample Plugin Dataset

---
users:
  - username: alice
    password: 123456
usersDatasetId: 42f224a17a3e4bd9b098XXXXXXXX3f   # The ID of the BasicAuth plug-in dataset
Note

Basic authentication plug-ins support the following special characters: @, !, <, >, #, $, %, and *.

For more information about plug-in datasets, see Plug-in dataset.