Documentation ¶
Index ¶
Constants ¶
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
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 ¶
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, cred *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