From ee5c21ff6b8b3c1f369d3c9f21dba13989ad7c3d Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Tue, 12 Nov 2019 15:03:50 +0100 Subject: [PATCH] Implement optional login functionality --- doc.go | 2 ++ server.go | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc.go b/doc.go index 548b6b5..f7a7c75 100644 --- a/doc.go +++ b/doc.go @@ -143,6 +143,8 @@ type Resource struct { Methods []string `json:"methods" yaml:"methods"` // WhiteListed permits the prefix through WhiteListed bool `json:"white-listed" yaml:"white-listed"` + // WhiteListed permits the prefix through + OptionalLogin bool `json:"optional-login" yaml:"optional-login"` // RequireAnyRole indicates that ANY of the roles are required, the default is all RequireAnyRole bool `json:"require-any-role" yaml:"require-any-role"` // Roles the roles required to access this url diff --git a/server.go b/server.go index 9f1ba00..2ff7ce1 100644 --- a/server.go +++ b/server.go @@ -264,14 +264,16 @@ func (r *oauthProxy) createReverseProxy() error { r.admissionMiddleware(false, x), r.identityHeadersMiddleware(r.config.AddClaims)) - w := engine.With( + o := engine.With( r.authenticationMiddleware(true), r.admissionMiddleware(true, x), r.identityHeadersMiddleware(r.config.AddClaims)) for _, m := range x.Methods { - if x.WhiteListed { - w.MethodFunc(m, x.URL, emptyHandler) + if x.OptionalLogin { + o.MethodFunc(m, x.URL, emptyHandler) + } else if x.WhiteListed { + engine.MethodFunc(m, x.URL, emptyHandler) } else { e.MethodFunc(m, x.URL, emptyHandler) } -- GitLab