Documentation ¶
Index ¶
- func AddTokenCookieForTesting(r *http.Request, config *Config) error
- func CurrentPermissions(r *http.Request) *permissions.Permissions
- func CurrentUser(r *http.Request) *users.User
- func CurrentUserHasPermission(r *http.Request, perm permissions.Permission) bool
- func CurrentUsername(r *http.Request) string
- type Config
- type Handler
- func (h *Handler) RequireAuth(httpHandler http.Handler) http.Handler
- func (h *Handler) RequireAuthFunc(handleFunc func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)
- func (h *Handler) RequirePermission(httpHandler http.Handler, perm permissions.Permission) http.Handler
- func (h *Handler) RequirePermissionFunc(handleFunc func(http.ResponseWriter, *http.Request), ...) func(http.ResponseWriter, *http.Request)
- func (h *Handler) UpdatePassword(username, password string) error
- func (h *Handler) UpdateUserPassword(username string) error
- type LoginStatus
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddTokenCookieForTesting ¶
AddTokenCookie adds a cookie to the request to make us be logged in, for testing.
func CurrentPermissions ¶
func CurrentPermissions(r *http.Request) *permissions.Permissions
CurrentPermissions returns the set of permissions for the user from the request context, or an empty list if there is no user found.
func CurrentUser ¶
CurrentUser returns the user from the request context, or nil if no user found there.
func CurrentUserHasPermission ¶
func CurrentUserHasPermission(r *http.Request, perm permissions.Permission) bool
CurrentUserHasPermissions returns true if the user from the request context has the specified permission, or false if they do not, or if there is no user found.
func CurrentUsername ¶
CurrentUsername returns the current username, or a placeholder string if there is no current user.
Types ¶
type Config ¶
type Config struct { Prefix string // The prefix string used for our API calls Store store.Store // The storage module to load and save our data. TokenCookieName string // The name of the cookie we use to store our auth data. TokenTimeoutDuration time.Duration // Amount of idle time until token times out. TokenExpiryDuration time.Duration // Amount of time until hard expire of the token. }
type Handler ¶
func NewHandler ¶
func (*Handler) RequireAuth ¶
RequireAuth enforces Authentication. Use this function to wrap the call to your handler when you call http.NewServeMux().Handle(). If the user is not authenticated, it returns StatusUnauthorized with the message "not authenticated". See also RequirePermission and RequireAuthFunc.
func (*Handler) RequireAuthFunc ¶
func (h *Handler) RequireAuthFunc(handleFunc func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)
RequireAuthFunc is like RequireAuth, except that it is for use to wrap a handler func rather than a Handler.
func (*Handler) RequirePermission ¶
func (h *Handler) RequirePermission(httpHandler http.Handler, perm permissions.Permission) http.Handler
RequirePermission enforces Authentication and having one permission. Use this function to wrap the call to your handler when you call http.NewServeMux().Handle(). If the user is not authenticated, it returns StatusUnauthorized with the message "not authenticated". If the user does not have the specified permission, it returns StatusUnauthorized with a the message "not authorized". If both checks pass, the specified handler is called. For more control, you can use RequireAuth instead of RequirePermission, then call CurrentUserHasPermission to check that condition. See also RequirePermissionFunc.
func (*Handler) RequirePermissionFunc ¶
func (h *Handler) RequirePermissionFunc(handleFunc func(http.ResponseWriter, *http.Request), perm permissions.Permission) func(http.ResponseWriter, *http.Request)
RequirePermissionFunc is like RequirePermission, except that it is for use to wrap a handler func rather than a Handler.
func (*Handler) UpdatePassword ¶
Set the saltword for a user into our database based on the username and the given password, with a randomly generated salt.
func (*Handler) UpdateUserPassword ¶
Read a password from the terminal and pass it to UpdatePassword. This function is difficult to test automatically. It should be tested manually.