git clone https://github.com/bariyer/express-basic-auth-example.git
npm i
yarn
mv .env.example .env
Example:
PORT=3000
BASIC_AUTH_USERNAME=admin
BASIC_AUTH_PASSWORD=admin
yarn start
npm start
4. Open Postman or similar tool to test the API
- Click import button
- Select
Link
tab. - Paste this link https://www.getpostman.com/collections/2aa26e7d392d7237378c
- Run the basic auth request
Authorization: Basic am9objoxMjM0NTY=
This is the base64 encoded string of john:123456
john is username and 123456 is password
Response Code: 200 OK
Response Body:
[
{
"id": 1,
"name": "Milk"
},
{
"id": 2,
"name": "Cheese"
}
]
-
If get an error, feel free to open issue.
-
If you have any questions, feel free to open discussion.
Contributions are what make the open source community such an amazing place to be inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feat/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feat/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.