auth

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticationRules

type AuthenticationRules func(user model.User, method, url string) bool

AuthenticationRules is function to check whether an user allowed to access an URL.

type Authenticator

type Authenticator struct {
	// contains filtered or unexported fields
}

Authenticator is object to authenticate a http request. It also handles login and logout.

func NewAuthenticator

func NewAuthenticator(db *sqlx.DB, rules AuthenticationRules) (*Authenticator, error)

NewAuthenticator returns new Authenticator

func (*Authenticator) AuthenticateUser

func (auth *Authenticator) AuthenticateUser(r *http.Request) error

AuthenticateUser checks whether the session is still valid. If yes, prolong its expiration time as well.

func (*Authenticator) GetSessionFromRequest

func (auth *Authenticator) GetSessionFromRequest(r *http.Request) string

GetSessionFromRequest as its name implies, will get the session ID from http request.

func (*Authenticator) Login

func (auth *Authenticator) Login(username, password string) (string, model.User, error)

Login verify that username and password match, generate session ID then save it to cache.

func (*Authenticator) Logout

func (auth *Authenticator) Logout(r *http.Request) error

Logout invalidates session

func (*Authenticator) MassLogout

func (auth *Authenticator) MassLogout(username string)

MassLogout invalidates all sessions for an user.

func (*Authenticator) MustAuthenticateUser

func (auth *Authenticator) MustAuthenticateUser(r *http.Request)

MustAuthenticateUser is like AuthenticateUser, except it's panic when request doesn't have a valid session.

type SessionManager

type SessionManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SessionManager is struct to manage all sessions

func NewSessionManager

func NewSessionManager(defaultExpiration, cleanupInterval time.Duration) *SessionManager

NewSessionManager returnns new SessionManager.

func (*SessionManager) GetUser

func (sm *SessionManager) GetUser(session string) (model.User, time.Time, bool)

GetUser get user based on specified session

func (*SessionManager) ProlongUserSession

func (sm *SessionManager) ProlongUserSession(session string, duration time.Duration)

ProlongUserSession extends the expiration time for specified session

func (*SessionManager) RegisterUser

func (sm *SessionManager) RegisterUser(user model.User, duration time.Duration) (string, error)

RegisterUser register user and return its session

func (*SessionManager) RemoveUserSession

func (sm *SessionManager) RemoveUserSession(session string)

RemoveUserSession removes the specified session from list of active user sessions.

func (*SessionManager) RemoveUsername

func (sm *SessionManager) RemoveUsername(username string)

RemoveUsername removes the specified username from list of active sessions. Used for mass logout.

Jump to

Keyboard shortcuts

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