Documentation ¶
Overview ¶
Attar package provide simple way to get http user auth (via sessions and cookie).
It use part of great Gorilla web toolkit, 'gorilla/sessions' package (http://github.com/gorilla/sessions).
Index ¶
- type Attar
- func (a *Attar) AuthHandler(res http.ResponseWriter, req *http.Request)
- func (a *Attar) GlobalAuthProxy(next http.Handler) http.HandlerFunc
- func (a *Attar) SetAttarOptions(o *AttarOptions)
- func (a *Attar) SetAuthProvider(f authProvider)
- func (a *Attar) SetCookieSessionKeys(authKey, encryptionKey []byte)
- func (a *Attar) SetGorillaCookieStore(c *sessions.CookieStore)
- func (a *Attar) SetLoginRoute(r string)
- func (a *Attar) SimpleAuthProvider(userlist map[string]string) authProvider
- type AttarOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attar ¶
type Attar struct {
// contains filtered or unexported fields
}
func New ¶
func New() *Attar
Return Attar struct with default options.
By default contain pre-set keys to 'gorilla/sessions' NewCookieStore func (provide in *Attar.CookieSessionKeys). It is not secure. Keys must be changed!
For more information about NewCookieStore() refer to http://www.gorillatoolkit.org/pkg/sessions#NewCookieStore.
func (*Attar) AuthHandler ¶
func (a *Attar) AuthHandler(res http.ResponseWriter, req *http.Request)
Auth handler, for grub login form data, and init cookie session.
func (*Attar) GlobalAuthProxy ¶
func (a *Attar) GlobalAuthProxy(next http.Handler) http.HandlerFunc
Function for check auth session.
func (*Attar) SetAttarOptions ¶
func (a *Attar) SetAttarOptions(o *AttarOptions)
Set attar options (*AttarOptions).
func (*Attar) SetAuthProvider ¶
func (a *Attar) SetAuthProvider(f authProvider)
Method for set "auth provider" function, and user verification.
User functon must take 'user' and 'password' arguments, and return true (if user auth successfully) or false (if auth data false).
As alternative use preset attar auth provider functions (like attar.SimpleAuthProvider)
Example of auth provider function:
// user code func checkAuth(u, p string) bool { if u == "user" && p == "qwerty" { return true } return false }
And define it:
// user code a := attar.New() a.SetAuthProvider(checkAuth)
func (*Attar) SetCookieSessionKeys ¶
Set 'gorilla/sessions' session cookie keys.
Attention! Conflict with attar.SetGorillaCookieStore.
For more information about NewCookieStore() refer to http://www.gorillatoolkit.org/pkg/sessions#NewCookieStore.
func (*Attar) SetGorillaCookieStore ¶
func (a *Attar) SetGorillaCookieStore(c *sessions.CookieStore)
Set pre-define 'gorilla/sessions' CookieStore as attar CookieStore.
Attention! Conflict with attar.SetCookieSessionKeys.
Example:
import ( "github.com/gorilla/sessions" "github.com/SpiritOfStallman/attar" ) func main() { .. gorillaSessions := sessions.NewCookieStore( []byte("261AD9502C583BD7D8AA03083598653B"), []byte("E9F6FDFAC2772D33FC5C7B3D6E4DDAFF"), ) .. a := attar.New() a.SetGorillaCookieStore(gorillaSessions) .. }
func (*Attar) SimpleAuthProvider ¶
User auth provider function, for simple user/password check.
Example of usage:
// users list based on map[user]password userList := map[string]string{ "user": "qwerty", "admin": "asdfgh", } a := attar.New() a.SetAuthProvider(a.SimpleAuthProvider(userList))
type AttarOptions ¶
type AttarOptions struct { // 'gorilla/sessions' section: // description see on http://www.gorillatoolkit.org/pkg/sessions#Options // or source on github Path string Domain string MaxAge int Secure bool HttpOnly bool // attar section: // name of cookie browser session SessionName string // default: "attar-session" SessionLifeTime int // default: 86400; in sec // bind browser useragent to cookie SessionBindUseragent bool // bind user IP addr to cookie SessionBindUserHost bool // html field names, to retrieve // user name and password from // login form LoginFormUserFieldName string // default: "login" LoginFormPasswordFieldName string // default: "password" }
Primary attar options (except for basic settings also accommodates a 'gorilla/sessions' options (http://www.gorillatoolkit.org/pkg/sessions#Options)).