auth

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

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

import(
	"github.com/beego/beego/v2"
	"github.com/beego/beego/v2/server/web/filter/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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basic

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

Basic is the http basic auth

func NewBasicAuthenticator

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

NewBasicAuthenticator return the BasicAuth

Types

type BasicAuth

type BasicAuth auth.BasicAuth

BasicAuth store the SecretProvider and Realm

func (*BasicAuth) CheckAuth

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

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

type SecretProvider auth.SecretProvider

SecretProvider is the SecretProvider function

Jump to

Keyboard shortcuts

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