ErrNoUserForSession=errors.New(`no user for session token`)
)
// Authenticator handles cookies, authentication and authorization of http routes by providing middlewares, logint/logout methods, user sessions and retriving the userID of an authenticated request.
// Authenticator should be used by clients to provide authentication functions and mapping of session tokens to users
typeAuthenticatorinterface{
// CheckUserPassword is called to login a user and create a corresponding session, see also "SessionTokenFromUser"
// MiddlewareConfig configures the middleware to only accept logged users (if "RequireLogged" is true) and with certain permissions (user must have all permissions inside "WithPermissions")
// MiddlewareConfig configures the middleware to only accept logged users (if "RequireLogged" is true) and with certain permissions (user must have all permissions inside "NeedPermissions")
typeMiddlewareConfigstruct{
// RequireLogged rejects not logged users if true
RequireLoggedbool
@ -41,15 +41,25 @@ type MiddlewareConfig struct {
NeedPermissions[]string
}
// AuthService is the spec of this library
// AuthSessionService given an Authenticator provides functions to login and logout users and an http.Handler middleware that accept users based on permissions and login status
typeAuthSessionServicestruct{
SessionCookieNamestring
SessionCookieNamestring
SessionCookiePathstring
SessionCookieDurationtime.Duration
Authenticator
}
// NewAuthSessionService creates a new *AuthSessionService with a default session cookie name
// NewAuthSessionService creates a new "*AuthSessionService" with a default session cookie name and path