Documentation ¶
Index ¶
Constants ¶
View Source
const AuthContextString = "userLoginAuthSession"
Variables ¶
View Source
var ( ErrInternal = errors.New("internal error") ErrForbidden = errors.New("forbidden") )
Functions ¶
func RequirePermission ¶
func RequirePermission[P comparable, C any]( ctx context.Context, permission P, authSession *AuthSession[P, C], ) error
Types ¶
type AuthSession ¶
type AuthSession[P comparable, C any] struct { User AuthUser // contains filtered or unexported fields }
AuthSession, user-interaction type
func AuthRun ¶
func AuthRun[P comparable, C any]( ctx context.Context, store SessionStore, dataKey string, backend AuthzBackend[P, C], ) (*AuthSession[P, C], error)
func (*AuthSession[T, C]) Authenticate ¶
func (aS *AuthSession[T, C]) Authenticate( ctx context.Context, creds C, ) (AuthUser, error)
Verifies the provided credentials via the backend returning the authenticated user if valid and otherwise `nil`.
type AuthUser ¶
type AuthUser interface { // Returns some identifying feature of the user. UserId() any // Returns a hash that's used by the session to verify the session is // valid. // // For example, if users have passwords, this method might return a // cryptographically secure hash of that password. SessionAuthHash() []byte }
Authenticating user type.
type AuthnBackend ¶
type AuthnBackend[C any] interface { // Authenticates the given credentials with the backend. Authenticate(ctx context.Context, creds C) (AuthUser, error) // Gets the user by provided ID from the backend. GetUser(ctx context.Context, userId any) (AuthUser, error) }
A backend which can authenticate users.
Backends must implement:
- [AuthnBackend.Authenticate], a method for authenticating users with credentials and,
- [AuthnBackend.GetUser] a method for getting a user by an identifying feature.
With these two methods, users may be authenticated and later retrieved via the backend.
type AuthzBackend ¶
type AuthzBackend[P comparable, C any] interface { AuthnBackend[C] // Gets the permissions for the provided user. GetUserPermissions( ctx context.Context, user AuthUser, ) (mapset.Set[P], error) // Gets the group permissions for the provided user. GetGroupPermissions( ctx context.Context, user AuthUser, ) (mapset.Set[P], error) }
A backend which can authorize users.
Backends must implement AuthnBackend.
Click to show internal directories.
Click to hide internal directories.