auth

package
v0.0.0-...-b5fa30d Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 4 Imported by: 1

Documentation

Overview

Base on https://github.com/martini-contrib/sessionauth

Index

Constants

View Source
const (
	DefaultKey = "github.com/hb-go/echo-web/modules/auth"
)

Variables

View Source
var (
	// RedirectUrl should be the relative URL for your login route
	RedirectUrl string = "/login"

	// RedirectParam is the query string parameter that will be set
	// with the page the user was trying to visit before they were
	// intercepted.
	RedirectParam string = "return_url"

	// SessionKey is the key containing the unique ID in your session
	SessionKey string = "AUTHUNIQUEID"
)

Functions

func AuthenticateSession

func AuthenticateSession(s session.Session, user User) error

AuthenticateSession will mark the session and user object as authenticated. Then the Login() user function will be called. This function should be called after you have validated a user.

func LoginRequired

func LoginRequired() echo.MiddlewareFunc

LoginRequired verifies that the current user is authenticated. Any routes that require a login should have this handler placed in the flow. If the user is not authenticated, they will be redirected to /login with the "next" get parameter set to the attempted URL.

func Logout

func Logout(s session.Session, user User)

Logout will clear out the session and call the Logout() user function.

func New

func New(newUser func() User) echo.MiddlewareFunc

func UpdateUser

func UpdateUser(s session.Session, user User) error

UpdateUser updates the User object stored in the session. This is useful incase a change is made to the user model that needs to persist across requests.

Types

type Auth

type Auth struct {
	User
}

func Default

func Default(c echo.Context) Auth

shortcut to get Auth

func (Auth) LogoutTest

func (a Auth) LogoutTest(s session.Session)

type User

type User interface {
	// Return whether this user is logged in or not
	IsAuthenticated() bool

	// Set any flags or extra data that should be available
	Login()

	// Clear any sensitive data out of the user
	Logout()

	// Return the unique identifier of this user object
	UniqueId() interface{}

	// Populate this user object with values
	GetById(id interface{}) error
}

Jump to

Keyboard shortcuts

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