beego: github.com/astaxie/beego/plugins/auth Index | Files

package auth

import "github.com/astaxie/beego/plugins/auth"

Package auth provides handlers to enable basic auth support. Simple Usage:

import(
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/plugins/auth"
)

func main(){
	// authenticate every request
	beego.InsertFilter("*", beego.BeforeRouter,auth.Basic("username","secretpassword"))
	beego.Run()
}

Advanced Usage:

func SecretAuth(username, password string) bool {
	return username == "astaxie" && password == "helloBeego"
}
authPlugin := auth.NewBasicAuthenticator(SecretAuth, "Authorization Required")
beego.InsertFilter("*", beego.BeforeRouter,authPlugin)

Index

Package Files

basic.go

func Basic Uses

func Basic(username string, password string) beego.FilterFunc

Basic is the http basic auth

func NewBasicAuthenticator Uses

func NewBasicAuthenticator(secrets SecretProvider, Realm string) beego.FilterFunc

NewBasicAuthenticator return the BasicAuth

type BasicAuth Uses

type BasicAuth struct {
    Secrets SecretProvider
    Realm   string
}

BasicAuth store the SecretProvider and Realm

func (*BasicAuth) CheckAuth Uses

func (a *BasicAuth) CheckAuth(r *http.Request) string

CheckAuth Checks the username/password combination from the request. Returns either an empty string (authentication failed) or the name of the authenticated user. Supports MD5 and SHA1 password entries

func (*BasicAuth) RequireAuth Uses

func (a *BasicAuth) RequireAuth(w http.ResponseWriter, r *http.Request)

RequireAuth http.Handler for BasicAuth which initiates the authentication process (or requires reauthentication).

type SecretProvider Uses

type SecretProvider func(user, pass string) bool

SecretProvider is the SecretProvider function

Package auth imports 5 packages (graph) and is imported by 6 packages. Updated 2019-01-03. Refresh now. Tools for package owners.