authenticator

package module
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2021 License: MIT Imports: 7 Imported by: 1

README

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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAuthGas

func BasicAuthGas(bagc BasicAuthGasConfig) air.Gas

BasicAuthGas returns an `air.Gas` that is used to authenticate ervery request by using the HTTP Basic Authentication (See RFC 2617, Section 2) based on the bagc. It prevents unauthenticated clients from accessing server resources.

Types

type BasicAuthGasConfig

type BasicAuthGasConfig struct {
	Validator       func(username, password string, req *air.Request, res *air.Response) (bool, error)
	Realm           string
	ErrUnauthorized error

	Skippable func(*air.Request, *air.Response) bool
}

BasicAuthGasConfig is a set of configurations for the `BasicAuthGas`.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL