@@ -75,6 +75,8 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
7575 // Get the container labels
7676 labels , err := h .Docker .GetLabels (appId )
7777
78+ log .Debug ().Interface ("labels" , labels ).Msg ("Got labels" )
79+
7880 // Check if there was an error
7981 if err != nil {
8082 log .Error ().Err (err ).Msg ("Failed to get container labels" )
@@ -183,54 +185,55 @@ func (h *Handlers) AuthHandler(c *gin.Context) {
183185 return
184186 }
185187
186- log .Debug ().Interface ("labels" , labels ).Msg ("Got labels" )
187-
188- // Check if user is in required groups
189- groupOk := h .Auth .OAuthGroup (c , userContext , labels )
190-
191- log .Debug ().Bool ("groupOk" , groupOk ).Msg ("Checking if user is in required groups" )
192-
193- // The user is not allowed to access the app
194- if ! groupOk {
195- log .Warn ().Str ("username" , userContext .Username ).Str ("host" , host ).Msg ("User is not in required groups" )
196-
197- // Set WWW-Authenticate header
198- c .Header ("WWW-Authenticate" , "Basic realm=\" tinyauth\" " )
199-
200- if proxy .Proxy == "nginx" || ! isBrowser {
201- c .JSON (401 , gin.H {
202- "status" : 401 ,
203- "message" : "Unauthorized" ,
204- })
205- return
206- }
207-
208- // Values
209- values := types.UnauthorizedQuery {
210- Resource : strings .Split (host , "." )[0 ],
211- GroupErr : true ,
212- }
213-
214- // Use either username or email
215- if userContext .OAuth {
216- values .Username = userContext .Email
217- } else {
218- values .Username = userContext .Username
219- }
220-
221- // Build query
222- queries , err := query .Values (values )
223-
224- // Handle error (no need to check for nginx/headers since we are sure we are using caddy/traefik)
225- if err != nil {
226- log .Error ().Err (err ).Msg ("Failed to build queries" )
227- c .Redirect (http .StatusPermanentRedirect , fmt .Sprintf ("%s/error" , h .Config .AppURL ))
188+ // Check groups if using OAuth
189+ if userContext .OAuth {
190+ // Check if user is in required groups
191+ groupOk := h .Auth .OAuthGroup (c , userContext , labels )
192+
193+ log .Debug ().Bool ("groupOk" , groupOk ).Msg ("Checking if user is in required groups" )
194+
195+ // The user is not allowed to access the app
196+ if ! groupOk {
197+ log .Warn ().Str ("username" , userContext .Username ).Str ("host" , host ).Msg ("User is not in required groups" )
198+
199+ // Set WWW-Authenticate header
200+ c .Header ("WWW-Authenticate" , "Basic realm=\" tinyauth\" " )
201+
202+ if proxy .Proxy == "nginx" || ! isBrowser {
203+ c .JSON (401 , gin.H {
204+ "status" : 401 ,
205+ "message" : "Unauthorized" ,
206+ })
207+ return
208+ }
209+
210+ // Values
211+ values := types.UnauthorizedQuery {
212+ Resource : strings .Split (host , "." )[0 ],
213+ GroupErr : true ,
214+ }
215+
216+ // Use either username or email
217+ if userContext .OAuth {
218+ values .Username = userContext .Email
219+ } else {
220+ values .Username = userContext .Username
221+ }
222+
223+ // Build query
224+ queries , err := query .Values (values )
225+
226+ // Handle error (no need to check for nginx/headers since we are sure we are using caddy/traefik)
227+ if err != nil {
228+ log .Error ().Err (err ).Msg ("Failed to build queries" )
229+ c .Redirect (http .StatusPermanentRedirect , fmt .Sprintf ("%s/error" , h .Config .AppURL ))
230+ return
231+ }
232+
233+ // We are using caddy/traefik so redirect
234+ c .Redirect (http .StatusTemporaryRedirect , fmt .Sprintf ("%s/unauthorized?%s" , h .Config .AppURL , queries .Encode ()))
228235 return
229236 }
230-
231- // We are using caddy/traefik so redirect
232- c .Redirect (http .StatusTemporaryRedirect , fmt .Sprintf ("%s/unauthorized?%s" , h .Config .AppURL , queries .Encode ()))
233- return
234237 }
235238
236239 c .Header ("Remote-User" , utils .SanitizeHeader (userContext .Username ))
0 commit comments