auth

package
v0.0.0-...-e417875 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AuthModeNone means no auth required
	AuthModeNone = "NONE"
	// AuthModeBasic is basic mode
	AuthModeBasic = "BASIC"
	// AuthModeOAuth is OAuth mode
	AuthModeOAuth = "OAUTH"
	// AuthModeCustom is custom mode
	AuthModeCustom = "CUSTOM"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseHandler

type BaseHandler struct{}

BaseHandler provides some basic functions like validation.

func (*BaseHandler) Authorize

func (b *BaseHandler) Authorize(req *http.Request, cred *Credential) error

Authorize implements @Handler.Authorize

func (*BaseHandler) Mode

func (b *BaseHandler) Mode() string

Mode implements @Handler.Mode

type BasicAuthHandler

type BasicAuthHandler struct {
	*BaseHandler
}

BasicAuthHandler handle the basic auth mode.

func (*BasicAuthHandler) Authorize

func (b *BasicAuthHandler) Authorize(req *http.Request, cred *Credential) error

Authorize implements @Handler.Authorize

func (*BasicAuthHandler) Mode

func (b *BasicAuthHandler) Mode() string

Mode implements @Handler.Mode

type Credential

type Credential struct {
	Mode string

	// Keep the auth data.
	// If authMode is 'BASIC', then 'username' and 'password' are stored;
	// If authMode is 'OAUTH', then 'token' is stored'
	// If authMode is 'CUSTOM', then 'header_key' with corresponding header value are stored.
	Data map[string]string
}

Credential stores the related data for authorization.

type CustomAuthHandler

type CustomAuthHandler struct {
	*BaseHandler
}

CustomAuthHandler handle the custom auth mode.

func (*CustomAuthHandler) Authorize

func (c *CustomAuthHandler) Authorize(req *http.Request, cred *Credential) error

Authorize implements @Handler.Authorize

func (*CustomAuthHandler) Mode

func (c *CustomAuthHandler) Mode() string

Mode implements @Handler.Mode

type Handler

type Handler interface {
	// Append authorization data to the request depends on cred modes.
	//
	// If everything is ok, nil error will be returned.
	// Otherwise, an error will be got.
	Authorize(req *http.Request, cred *Credential) error

	// Mode returns the auth mode identity.
	Mode() string
}

Handler defines how to add authorization data to the requests depending on the different auth modes.

func GetAuthHandler

func GetAuthHandler(mode string) (Handler, bool)

GetAuthHandler gets the handler per the mode

type NoneAuthHandler

type NoneAuthHandler struct{}

NoneAuthHandler handles the case of no credentail required.

func (*NoneAuthHandler) Authorize

func (nah *NoneAuthHandler) Authorize(req *http.Request, _ *Credential) error

Authorize implements @Handler.Authorize

func (*NoneAuthHandler) Mode

func (nah *NoneAuthHandler) Mode() string

Mode implements @Handler.Mode

type TokenAuthHandler

type TokenAuthHandler struct {
	*BaseHandler
}

TokenAuthHandler handles the OAuth auth mode.

func (*TokenAuthHandler) Authorize

func (t *TokenAuthHandler) Authorize(req *http.Request, cred *Credential) error

Authorize implements @Handler.Authorize

func (*TokenAuthHandler) Mode

func (t *TokenAuthHandler) Mode() string

Mode implements @Handler.Mode

Jump to

Keyboard shortcuts

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