Skip to content

Commit

Permalink
fix subpath handling
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
Frank Jogeleit committed Apr 11, 2024
1 parent 629d8df commit fc6af3d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
14 changes: 9 additions & 5 deletions backend/pkg/auth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ import (
)

type Handler struct {
basePath string
}

func NewHandler() *Handler {
return &Handler{}
func NewHandler(basePath string) *Handler {
return &Handler{
basePath: basePath,
}
}

func (h *Handler) Callback(ctx *gin.Context) {
user, err := gothic.CompleteUserAuth(ctx.Writer, ctx.Request)
if err != nil {
zap.L().Error("failed to complete user", zap.Error(err))
ctx.AbortWithError(http.StatusInternalServerError, err)
return
}
Expand All @@ -34,7 +38,7 @@ func (h *Handler) Callback(ctx *gin.Context) {
return
}

ctx.Redirect(http.StatusTemporaryRedirect, "/")
ctx.Redirect(http.StatusTemporaryRedirect, h.basePath)
}

func (h *Handler) Login(ctx *gin.Context) {
Expand All @@ -47,7 +51,7 @@ func (h *Handler) Login(ctx *gin.Context) {
session := sessions.Default(ctx)
session.Set("profile", NewProfile(user))

ctx.Redirect(http.StatusTemporaryRedirect, "/")
ctx.Redirect(http.StatusTemporaryRedirect, h.basePath)
}

func (h *Handler) Logout(ctx *gin.Context) {
Expand All @@ -56,7 +60,7 @@ func (h *Handler) Logout(ctx *gin.Context) {
session.Clear()
session.Save()

ctx.Redirect(http.StatusTemporaryRedirect, "/login")
ctx.Redirect(http.StatusTemporaryRedirect, h.basePath+"login")
}

func (h *Handler) Profile(ctx *gin.Context) {
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/auth/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func Setup(engine *gin.Engine, basePath, provider, tempDir string) {
authStore.Options = &gsessions.Options{
HttpOnly: true,
MaxAge: 86400 * 30,
Path: basePath,
Path: "/",
}

gothic.Store = authStore

engine.Use(sessions.Sessions(SessionKey, NewStore(authStore)))

handler := NewHandler()
handler := NewHandler(basePath)

engine.GET("/login", Provider(provider), handler.Login)
engine.GET("/logout", Provider(provider), handler.Logout)
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/config/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (r *Resolver) SetupOAuth(ctx context.Context, engine *gin.Engine) ([]gin.Ha
}

goth.UseProviders(provider)
auth.Setup(engine, config.Provider, r.config.OAuth.BasePath(), r.config.TempDir)
auth.Setup(engine, r.config.OAuth.BasePath(), config.Provider, r.config.TempDir)

return []gin.HandlerFunc{auth.Provider(r.config.OAuth.Provider), auth.Auth(r.config.OAuth.BasePath())}, nil
}
Expand All @@ -277,7 +277,7 @@ func (r *Resolver) SetupOIDC(ctx context.Context, engine *gin.Engine) ([]gin.Han

goth.UseProviders(provider)

auth.Setup(engine, "openid-connect", r.config.OpenIDConnect.BasePath(), r.config.TempDir)
auth.Setup(engine, r.config.OpenIDConnect.BasePath(), "openid-connect", r.config.TempDir)

return []gin.HandlerFunc{auth.Provider("openid-connect"), auth.Auth(r.config.OpenIDConnect.BasePath())}, nil
}
Expand Down
4 changes: 4 additions & 0 deletions backend/pkg/server/api/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ type Handler struct {
reporter *reports.ReportGenerator
}

func (h *Handler) Healthz(ctx *gin.Context) {
ctx.JSON(http.StatusOK, nil)
}

func (h *Handler) Config(ctx *gin.Context) {
ctx.JSON(http.StatusOK, h.config)
}
Expand Down
1 change: 1 addition & 0 deletions backend/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (s *Server) RegisterCluster(name string, client *core.Client, plugins map[s
func (s *Server) RegisterAPI(c *api.Config, customBoards map[string]api.CustomBoard) {
handler := api.NewHandler(c, s.apis, customBoards)

s.engine.GET("healthz", handler.Healthz)
s.api.GET("config", handler.Config)
s.api.GET("custom-board/list", handler.ListCustomBoards)
s.api.GET("config/:cluster/custom-board/:id", handler.GetCustomBoard)
Expand Down

0 comments on commit fc6af3d

Please sign in to comment.