Merge commit from fork
Docker / Build and Push (push) Has been cancelled
github-pages / deploy (push) Has been cancelled
Docker / release (push) Has been cancelled

This commit is contained in:
h44z
2026-07-23 23:01:13 +02:00
committed by GitHub
parent 20c2d6faff
commit 207d9ae1c3
3 changed files with 132 additions and 3 deletions
@@ -16,16 +16,22 @@ const (
)
type UserAuthenticator interface {
IsUserValid(ctx context.Context, id domain.UserIdentifier) bool
}
type UserRepository interface {
GetUser(ctx context.Context, id domain.UserIdentifier) (*domain.User, error)
}
type AuthenticationHandler struct {
authenticator UserAuthenticator
userRepo UserRepository
}
func NewAuthenticationHandler(authenticator UserAuthenticator) AuthenticationHandler {
func NewAuthenticationHandler(authenticator UserAuthenticator, userRepo UserRepository) AuthenticationHandler {
return AuthenticationHandler{
authenticator: authenticator,
userRepo: userRepo,
}
}
@@ -44,7 +50,7 @@ func (h AuthenticationHandler) LoggedIn(scopes ...Scope) func(next http.Handler)
// check if user exists in DB
ctx := domain.SetUserInfo(r.Context(), domain.SystemAdminContextUserInfo())
user, err := h.authenticator.GetUser(ctx, domain.UserIdentifier(username))
user, err := h.userRepo.GetUser(ctx, domain.UserIdentifier(username))
if err != nil {
// Abort the request with the appropriate error code
respond.JSON(w, http.StatusUnauthorized,
@@ -60,6 +66,13 @@ func (h AuthenticationHandler) LoggedIn(scopes ...Scope) func(next http.Handler)
return
}
// ensure that user is still valid
if valid := h.authenticator.IsUserValid(r.Context(), domain.UserIdentifier(user.Identifier)); !valid {
respond.JSON(w, http.StatusForbidden,
model.Error{Code: http.StatusForbidden, Message: "account disabled or locked"})
return
}
if !UserHasScopes(user, scopes...) {
// Abort the request with the appropriate error code
respond.JSON(w, http.StatusForbidden,