Documentation ¶
Index ¶
- Constants
- func CookieDigest(payload string, secret []byte) []byte
- func CreateSessionID(realIP string, userAgent []string) string
- func DecodeCookie(cookieValue string, secret []byte) ([]byte, error)
- type Config
- type ISessionAuth
- type SessionAuth
- func (s *SessionAuth) AuthMiddlewareFunc(next echo.HandlerFunc) echo.HandlerFunc
- func (s *SessionAuth) DeleteCookie(ctx echo.Context)
- func (s *SessionAuth) FreshLoginRequired(ctx echo.Context) error
- func (s *SessionAuth) GetCookie(ctx echo.Context) (interface{}, error)
- func (s *SessionAuth) GetSessionMiddleware() echo.MiddlewareFunc
- func (s *SessionAuth) Login(ctx echo.Context, UserId string, fresh bool, remember bool) error
- func (s *SessionAuth) LoginRequired(ctx echo.Context) error
- func (s *SessionAuth) Logout(ctx echo.Context)
- func (s *SessionAuth) PathIsExcluded(path string) bool
- func (s *SessionAuth) SetCookie(ctx echo.Context, UserID string)
Constants ¶
View Source
const ( ProtectionLevelBasic int = 1 ProtectionLevelStrong int = 2 )
TODO: Protection Level
View Source
const ( InvalidCookie = "invalid cookie" InvalidCookieIndentifier = "invalid cookie identifier" )
Variables ¶
This section is empty.
Functions ¶
func CookieDigest ¶
Create a endrypted remember cookie
func CreateSessionID ¶
Create auth session
Types ¶
type Config ¶
type Config struct { // Session auth cookie name AuthSessionName string // Secret key that would be used for cookie and more // Loaded from shell environment `SECRET_KEY` SecretKey []byte // Redirection path for unauthorized access to protected page UnAuthRedirect string // Exluded path list. E.g. "/logout", "/register", etc Excluded []string // Exluded regex path. E.g. "/static/*" ExcludedRegex []*regexp.Regexp // Choose between `ProtectionLevelBasic` or `ProtectionLevelStrong` ProtectionLevel int // cookie name for login with `remember me` flag CookieName string CookieDomain string CookiePath string CookieSecure bool CookieHTTPOnly bool CookieSameSite http.SameSite // Cookie duration in seconds CookieDuration int SessionFresh string SessionID string SessionKey string SessionNext string SessionRememberCookie string SessionRememberDuration string }
Initial configurations
type ISessionAuth ¶
type ISessionAuth interface { // Get Session (extended against our config) middleware function GetSessionMiddleware() echo.MiddlewareFunc // Get authentication middleware function AuthMiddlewareFunc() echo.HandlerFunc // Set authentication session and cookie Login(ctx echo.Context, UserId string, fresh bool) error // Clean authentication session and cookie Logout(ctx echo.Context) // Check if path is in excluded pattern list PathIsExcluded(path string) }
type SessionAuth ¶
type SessionAuth struct { Config *Config Cookie *sessions.CookieStore // Get user method // error is not nil if user is not found GetUser func(c echo.Context, UserId any) error }
func Create ¶
func Create(config *Config, getUser func(c echo.Context, UserId any) error) (*SessionAuth, error)
Create SessionAuth by
func (*SessionAuth) AuthMiddlewareFunc ¶
func (s *SessionAuth) AuthMiddlewareFunc(next echo.HandlerFunc) echo.HandlerFunc
func (*SessionAuth) DeleteCookie ¶
func (s *SessionAuth) DeleteCookie(ctx echo.Context)
func (*SessionAuth) FreshLoginRequired ¶
func (s *SessionAuth) FreshLoginRequired(ctx echo.Context) error
Need to be called on restricted endpoints that accessed by freshly authenticated user Returns redirect to "config.UnauthRedirect" with last path as next URL query
func (*SessionAuth) GetCookie ¶
func (s *SessionAuth) GetCookie(ctx echo.Context) (interface{}, error)
func (*SessionAuth) GetSessionMiddleware ¶
func (s *SessionAuth) GetSessionMiddleware() echo.MiddlewareFunc
func (*SessionAuth) Login ¶
func (s *SessionAuth) Login(ctx echo.Context, UserId string, fresh bool, remember bool) error
Save authenticated user session if "remember" is true, save remember_me cookie UserID should be represented as string
func (*SessionAuth) LoginRequired ¶
func (s *SessionAuth) LoginRequired(ctx echo.Context) error
Need to be called on restricted endpoints that accessed by authenticated user Returns redirect to "config.UnauthRedirect" with last path as next URL query
func (*SessionAuth) Logout ¶
func (s *SessionAuth) Logout(ctx echo.Context)
func (*SessionAuth) PathIsExcluded ¶
func (s *SessionAuth) PathIsExcluded(path string) bool
func (*SessionAuth) SetCookie ¶
func (s *SessionAuth) SetCookie(ctx echo.Context, UserID string)
Click to show internal directories.
Click to hide internal directories.