60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package application
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/core/application"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/services"
|
|
"git.coopgo.io/coopgo-apps/parcoursmob/core/utils/identification"
|
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
|
"github.com/coreos/go-oidc/v3/oidc"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Handler struct {
|
|
cfg *viper.Viper
|
|
renderer *renderer.Renderer
|
|
applicationHandler *application.ApplicationHandler
|
|
idp *identification.IdentificationProvider
|
|
services *services.ServicesHandler
|
|
}
|
|
|
|
func NewHandler(cfg *viper.Viper, renderer *renderer.Renderer, applicationHandler *application.ApplicationHandler, idp *identification.IdentificationProvider, services *services.ServicesHandler) *Handler {
|
|
return &Handler{
|
|
cfg: cfg,
|
|
renderer: renderer,
|
|
applicationHandler: applicationHandler,
|
|
idp: idp,
|
|
services: services,
|
|
}
|
|
}
|
|
|
|
func (h *Handler) currentGroup(r *http.Request) (current_group storage.Group, err error) {
|
|
g := r.Context().Value(identification.GroupKey)
|
|
if g == nil {
|
|
return storage.Group{}, errors.New("current group not found")
|
|
}
|
|
current_group = g.(storage.Group)
|
|
|
|
return current_group, nil
|
|
}
|
|
|
|
func (h *Handler) currentUser(r *http.Request) (current_user_token *oidc.IDToken, current_user_claims map[string]any, err error) {
|
|
// Get current user ID
|
|
u := r.Context().Value(identification.IdtokenKey)
|
|
if u == nil {
|
|
return nil, nil, errors.New("current user not found")
|
|
}
|
|
current_user_token = u.(*oidc.IDToken)
|
|
|
|
// Get current user claims
|
|
c := r.Context().Value(identification.ClaimsKey)
|
|
if c == nil {
|
|
return nil, nil, errors.New("current user claims not found")
|
|
}
|
|
current_user_claims = c.(map[string]any)
|
|
|
|
return current_user_token, current_user_claims, nil
|
|
} |