A useful gas that used to authenticate every request for the web applications built using Air.
Open your terminal and execute
$ go get github.com/air-gases/authenticator
done.
The only requirement is the Go, at least v1.13.
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()
}
If you want to discuss Authenticator, or ask questions about it, simply post questions or ideas here.
If you want to help build Authenticator, simply follow this to send pull requests here.
This project is licensed under the MIT License.
License can be found here.