Documentation
¶
Index ¶
- Variables
- func AddUserToGroupInSession(c echo.Context, group string) error
- func AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc
- func CSRFMiddleware() echo.MiddlewareFunc
- func DatabaseFromContext(c echo.Context) *db.Queries
- func DeleteSession(c echo.Context) error
- func GetCSRFToken(c echo.Context) string
- func GetMessagesOnSession(c echo.Context) ([]string, error)
- func GetUser(c echo.Context) *db.User
- func HTTPError(code int, err error) error
- func HTTPErrorf(code int, format string, args ...any) error
- func HasAnyGroups(c echo.Context, groups ...string) bool
- func InitializeAuthRoutes(g *echo.Group)
- func OptionalAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc
- func RemoveUserFromGroupInSession(c echo.Context, group string) error
- func RenderMessages(messages []string) template.HTML
- func RequireGroupMiddleware(group string) echo.MiddlewareFunc
- func Session(c echo.Context) (*sessions.Session, error)
- func SetMessageOnSession(c echo.Context, messages ...string) error
- func WithDatabase(next echo.HandlerFunc) echo.HandlerFunc
Constants ¶
This section is empty.
Variables ¶
var ( SessionKeyUserID = "user_id" SessionKeyGroups = "groups" SessionKeyAuthState = "auth_state" SessionKeyMessages = "messages" )
var (
ErrNotAuthorized = errors.New("you are not allowed to do that")
)
Functions ¶
func AddUserToGroupInSession ¶
Updates the session store to indicate the current user is in a group that the IDP did not tell us they were in when the user logged in. Should only be used when the IDP is also being told that the user is being added to the group, to allow the user to instantly use their newfound powers.
func AuthMiddleware ¶
func AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc
func CSRFMiddleware ¶
func CSRFMiddleware() echo.MiddlewareFunc
func DatabaseFromContext ¶
DatabaseFromContext retrieves the database queries from the context. This must only be called from a request that has passed through the WithDatabase middleware.
func DeleteSession ¶
func GetCSRFToken ¶
func GetCSRFToken(c echo.Context) string
func HTTPError ¶
HTTPError creates a new HTTP error with the specified status code and error value. It is a simple wrapper for echo.NewHTTPError.
func HTTPErrorf ¶
HTTPErrorf creates a new HTTP error with the specified status code and formatted error message.
func HasAnyGroups ¶
HasAnyGroups returns true if the logged in user has at least one of the listed groups
func InitializeAuthRoutes ¶
func OptionalAuthMiddleware ¶
func OptionalAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc
OptionalAuthMiddleware checks if the user is logged in, but doesn't prevent access if they aren't (user from context may be nil when using this)
func RemoveUserFromGroupInSession ¶
Updates the session store to indicate the current user is not in a group that the IDP told us they were in when the user logged in. Should only be used when the IDP is also being told that theu ser is being removed from the group.
func RenderMessages ¶
func RequireGroupMiddleware ¶
func RequireGroupMiddleware(group string) echo.MiddlewareFunc
func WithDatabase ¶
func WithDatabase(next echo.HandlerFunc) echo.HandlerFunc
WithDatabase is an Echo middleware that retrieves a database connection and sets it in the context for the request.
Types ¶
This section is empty.