Skip to content
This repository has been archived by the owner on Oct 17, 2023. It is now read-only.

Latest commit

 

History

History
68 lines (49 loc) · 1.64 KB

README.md

File metadata and controls

68 lines (49 loc) · 1.64 KB

Authenticator

PkgGoDev

A useful gas that used to authenticate every request for the web applications built using Air.

Installation

Open your terminal and execute

$ go get github.com/air-gases/authenticator

done.

The only requirement is the Go, at least v1.13.

Usage

The following application will require all home requests to carry an HTTP Basic Authentication (See RFC 2617, Section 2) header with the username part is "foo" and password part is "bar".

package main

import (
	"github.com/air-gases/authenticator"
	"github.com/aofei/air"
)

func main() {
	a := air.Default
	a.DebugMode = true
	a.GET("/", func(req *air.Request, res *air.Response) error {
		return res.WriteString("You are authorized!")
	}, authenticator.BasicAuthGas(authenticator.BasicAuthGasConfig{
		Validator: func(
				username string,
				password string,
				_ *air.Request,
				_ *air.Response,
		) (bool, error) {
			return username == "foo" && password == "bar", nil
		},
	}))
	a.Serve()
}

Community

If you want to discuss Authenticator, or ask questions about it, simply post questions or ideas here.

Contributing

If you want to help build Authenticator, simply follow this to send pull requests here.

License

This project is licensed under the MIT License.

License can be found here.