auth

package
v0.0.0-...-0484061 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2020 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Allowed

func Allowed(req *http.Request) error

Allowed returns Authenticator.Allowed result, it user is not allowed to use current resource, an non nil error is returned.

func Get

func Get(id string) (*user.User, error)

func GetCurrentUser

func GetCurrentUser(req *http.Request) *user.User

func GetCurrentUsername

func GetCurrentUsername(req *http.Request) (string, error)

GetCurrentUsername returns Authenticator.GetCurrentUsername response, it must give the current logged user name. If user is not logged so an error is returned. If something goes wrong to read the user name, an non-nil error is also returned.

func Login

func Login(u *user.User) error

Login will return the Authenticator.Login result - if the user login process failed, an error is returned.

func SetAuthenticator

func SetAuthenticator(authenticator Authenticator)

SetAuthenticator will register given Authenticator to use.

func SetStats

func SetStats(s Stats)

func Signup

func Signup(u *user.User) error

func Update

func Update(u *user.User) error

Types

type Authenticator

type Authenticator interface {
	// Login should take a user as parameter and return error if login failed
	Login(*user.User) error

	// Signup should take a user, check it and register it.
	Signup(*user.User) error

	// Update the user. Please make nice checks on password.
	Update(u *user.User) error

	// Logout should take a user as paramter and return error if logout failed.
	// That one is not mandatory for the entire authenticator, some use JWT so that method can only
	// return nil.
	Logout(*user.User) error

	// Allowed take request as parameter to check some header, cookies, and so on. An error
	// should be returned if the current user is not allowed to see the resource.
	Allowed(*http.Request) error

	// GetCurrentUsername must use header to return username. Note that this method is ONLY used
	// to get username and NOT to check authorization !
	GetCurrentUsername(*http.Request) (string, error) // deprecated ?

	// GetCurrentUser should give the current logged in user
	GetCurrentUser(*http.Request) *user.User

	// Get user from any db. ID should be manipulate by authenticator instance.
	Get(id string) (*user.User, error)
}

Authenticator interface to implement user management (eg. LDAP, Database, CAS).

type Stats

type Stats interface {
	CountUsers() int
}

func GetStats

func GetStats() Stats

Jump to

Keyboard shortcuts

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