| @@ -37,7 +37,8 @@ | ||||
|     address = ":80" | ||||
|  | ||||
|     [entryPoints.http.auth.forward] | ||||
|     address = "http://forward-oauth:4181" | ||||
|     address = "http://traefik-forward-auth:4181" | ||||
|     authResponseHeaders = ["X-Forwarded-User"] | ||||
|  | ||||
| ################################################################ | ||||
| # Traefik logs configuration | ||||
|   | ||||
							
								
								
									
										1
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								main.go
									
									
									
									
									
								
							| @@ -70,6 +70,7 @@ func handler(w http.ResponseWriter, r *http.Request) { | ||||
|   } | ||||
|  | ||||
|   // Valid request | ||||
|   w.Header().Set("X-Forwarded-User", email) | ||||
|   w.WriteHeader(200) | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										15
									
								
								main_test.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								main_test.go
									
									
									
									
									
								
							| @@ -15,6 +15,9 @@ import ( | ||||
|   "github.com/op/go-logging" | ||||
| ) | ||||
|  | ||||
| /** | ||||
|  * Utilities | ||||
|  */ | ||||
|  | ||||
| type TokenServerHandler struct {} | ||||
| func (t *TokenServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||||
| @@ -79,6 +82,10 @@ func qsDiff(one, two url.Values) { | ||||
|   } | ||||
| } | ||||
|  | ||||
| /** | ||||
|  * Tests | ||||
|  */ | ||||
|  | ||||
| func TestHandler(t *testing.T) { | ||||
|   fw = &ForwardAuth{ | ||||
|     Path: "_oauth", | ||||
| @@ -138,6 +145,14 @@ func TestHandler(t *testing.T) { | ||||
|   if res.StatusCode != 200 { | ||||
|     t.Error("Valid request should be allowed, got:", res.StatusCode) | ||||
|   } | ||||
|  | ||||
|   // Should pass through user | ||||
|   users := res.Header["X-Forwarded-User"]; | ||||
|   if len(users) != 1 { | ||||
|     t.Error("Valid request missing X-Forwarded-User header") | ||||
|   } else if users[0] != "test@example.com" { | ||||
|     t.Error("X-Forwarded-User should match user, got: ", users) | ||||
|   } | ||||
| } | ||||
|  | ||||
| func TestCallback(t *testing.T) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Thom Seddon
					Thom Seddon