Giter VIP home page Giter VIP logo

http-basic-auth's Introduction

http-basic-auth

The simplest form of web authentication is HTTP basic authentication. The request contains a header field in the form of Authorization: Basic where credentials is the Base64 encoding of ID and password joined by a single colon :, e.g. Authorisation: Basic dGVzdDpzZWNyZXQ=

Server

The server will check if the Authorization header field is present and if the value is a valid username / password combination.

Examples

The httpie is a user-friendly HTTP client that can be used to test the API:

Missing Authorization header

$ http http://localhost:8080
HTTP/1.1 401 Unauthorized
Content-Length: 36
Content-Type: application/json
Date: Sat, 19 Jun 2021 13:16:34 GMT
Www-Authenticate: Basic realm="Give username and password"

{
    "message": "No basic auth present"
}

Valid Authorization header

$ http http://localhost:8080 "Authorization:Basic dGVzdDpzZWNyZXQ="
HTTP/1.1 200 OK
Content-Length: 39
Content-Type: application/json
Date: Sat, 19 Jun 2021 13:38:01 GMT

{
    "message": "welcome to golang world!"
}

dGVzdDpzZWNyZXQ= is the Base64 encoded test:secret string.

Client

The client demonstrates how to set the Authorization header required for HTTP basic authentication.

Credits

The code is from How to Implement HTTP Basic Auth in Go.

http-basic-auth's People

Contributors

mthaler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.