github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/docs/plugins/basic.md (about) 1 # HTTP Basic Auth 2 3 Add Basic Authentication to your APIs, with username and password protection. The plugin will check for valid credentials in the `Authorization` header. 4 5 ## Configuration 6 7 The plain basic auth config: 8 9 ```json 10 "basic_auth": { 11 "enabled": true 12 } 13 ``` 14 15 Here is a simple definition of the available configurations. 16 17 | Configuration | Description | 18 |-------------------------------|---------------------------------------------------------------------| 19 | name | Name of the plugin to use, in this case: basic_auth | 20 | enabled | Is the plugin enabled? | 21 22 ## Usage 23 24 In order to use the plugin, you first need to create some users first. By enabling this plugins in any endpoint There is a simple API that you can use to create new users. 25 26 ## Create an User 27 28 You need to create an user that will be used to authenticate. To create an user you can execute the following request: 29 30 {% codetabs name="HTTPie", type="bash" -%} 31 http -v POST http://localhost:8081/credentials/basic_auth "Authorization:Bearer yourToken" username=lanister password=pay-your-debt 32 {%- language name="CURL", type="bash" -%} 33 curl -X POST http://localhost:8081/credentials/basic_auth -H 'authorization: Bearer yourToken' -H 'content-type: application/json' -d '{"username": "lanister", "password": "pay-your-debt"}' 34 {%- endcodetabs %} 35 36 | FORM PARAMETER | Description | 37 |----------------|-------------------------------------------------| 38 | username | The username to use in the Basic Authentication | 39 | password | The password to use in the Basic Authentication | 40 41 ## Using the Credential 42 43 The authorization header must be base64 encoded. For example, if the credential uses `lanister` as the username and `pay-your-debt` as the password, then the field's value is the base64-encoding of lanister:pay-your-debt, or bGFuaXN0ZXI6cGF5LXlvdXItZGVidA==. 44 45 Then the `Authorization` header must appear as: 46 47 Authorization: Basic bGFuaXN0ZXI6cGF5LXlvdXItZGVidA== 48 Simply make a request with the header: 49 50 {% codetabs name="HTTPie", type="bash" -%} 51 http -v http://localhost:8080/example "Authorization:Basic bGFuaXN0ZXI6cGF5LXlvdXItZGVidA==" 52 {%- language name="CURL", type="bash" -%} 53 curl -v http://localhost:8080/example -H 'Authorization:Basic bGFuaXN0ZXI6cGF5LXlvdXItZGVidA==' 54 {%- endcodetabs %}