Skip to content

bariyer/express-basic-auth-example

Repository files navigation

@bariyer/express
basic authentication example

bariyer sub brand express logo

Report Bug  •  Request Feature

Installation

1. Clone the repository

git clone https://github.com/bariyer/express-basic-auth-example.git

2. Install dependencies

npm i
yarn

3. Rename .env.example to .env and fill the values

mv .env.example .env

Example:

PORT=3000
BASIC_AUTH_USERNAME=admin
BASIC_AUTH_PASSWORD=admin

3. Run the example server

yarn start
npm start

4. Open Postman or similar tool to test the API

For Postman users

  1. Click import button
  2. Select Link tab.
  3. Paste this link https://www.getpostman.com/collections/2aa26e7d392d7237378c
  4. Run the basic auth request

For non-Postman users

GET http://localhost:3000/

Headers:

Authorization: Basic am9objoxMjM0NTY= This is the base64 encoded string of john:123456 john is username and 123456 is password

5. See the response

Response Code: 200 OK Response Body:

[
    {
        "id": 1,
        "name": "Milk"
    },
    {
        "id": 2,
        "name": "Cheese"
    }
]

Contributing

Contributions are what make the open source community such an amazing place to be inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feat/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feat/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

About

@bariyer/express basic authentication example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published