use gofmt to update styling
This commit is contained in:
parent
6ccd1c6dfc
commit
afd8878188
@ -1,19 +1,18 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
"errors"
|
|
||||||
"strings"
|
|
||||||
"strconv"
|
|
||||||
"net/url"
|
|
||||||
"net/http"
|
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/json"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Forward Auth
|
// Forward Auth
|
||||||
@ -109,7 +108,6 @@ func (f *ForwardAuth) ValidateEmail(email string) bool {
|
|||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// OAuth Methods
|
// OAuth Methods
|
||||||
|
|
||||||
// Get login url
|
// Get login url
|
||||||
@ -147,7 +145,6 @@ func (f *ForwardAuth) ExchangeCode(r *http.Request, code string) (string, error)
|
|||||||
form.Set("redirect_uri", f.redirectUri(r))
|
form.Set("redirect_uri", f.redirectUri(r))
|
||||||
form.Set("code", code)
|
form.Set("code", code)
|
||||||
|
|
||||||
|
|
||||||
res, err := http.PostForm(fw.TokenURL.String(), form)
|
res, err := http.PostForm(fw.TokenURL.String(), form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "fmt"
|
// "fmt"
|
||||||
"time"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"net/url"
|
"time"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateCookie(t *testing.T) {
|
func TestValidateCookie(t *testing.T) {
|
||||||
@ -144,7 +143,6 @@ func TestGetLoginURL(t *testing.T) {
|
|||||||
qsDiff(expectedQs, qs)
|
qsDiff(expectedQs, qs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// With Auth URL but no matching cookie domain
|
// With Auth URL but no matching cookie domain
|
||||||
// - will not use auth host
|
// - will not use auth host
|
||||||
@ -306,7 +304,7 @@ func TestMakeCSRFCookie(t *testing.T) {
|
|||||||
|
|
||||||
// With cookie domain but no auth url
|
// With cookie domain but no auth url
|
||||||
cookieDomain := NewCookieDomain("example.com")
|
cookieDomain := NewCookieDomain("example.com")
|
||||||
fw = &ForwardAuth{CookieDomains: []CookieDomain{*cookieDomain},}
|
fw = &ForwardAuth{CookieDomains: []CookieDomain{*cookieDomain}}
|
||||||
c = fw.MakeCSRFCookie(r, "12345678901234567890123456789012")
|
c = fw.MakeCSRFCookie(r, "12345678901234567890123456789012")
|
||||||
if c.Domain != "app.example.com" {
|
if c.Domain != "app.example.com" {
|
||||||
t.Error("Cookie Domain should match request domain, got:", c.Domain)
|
t.Error("Cookie Domain should match request domain, got:", c.Domain)
|
||||||
|
11
main.go
11
main.go
@ -1,19 +1,18 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
"strings"
|
|
||||||
"net/url"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/namsral/flag"
|
"github.com/namsral/flag"
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Vars
|
// Vars
|
||||||
var fw *ForwardAuth;
|
var fw *ForwardAuth
|
||||||
var log = logging.MustGetLogger("traefik-forward-auth")
|
var log = logging.MustGetLogger("traefik-forward-auth")
|
||||||
|
|
||||||
// Primary handler
|
// Primary handler
|
||||||
@ -74,7 +73,6 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Authenticate user after they have come back from google
|
// Authenticate user after they have come back from google
|
||||||
func handleCallback(w http.ResponseWriter, r *http.Request, qs url.Values) {
|
func handleCallback(w http.ResponseWriter, r *http.Request, qs url.Values) {
|
||||||
// Check for CSRF cookie
|
// Check for CSRF cookie
|
||||||
@ -120,7 +118,6 @@ func handleCallback(w http.ResponseWriter, r *http.Request, qs url.Values) {
|
|||||||
http.Redirect(w, r, redirect, http.StatusTemporaryRedirect)
|
http.Redirect(w, r, redirect, http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
func main() {
|
func main() {
|
||||||
// Parse options
|
// Parse options
|
||||||
|
13
main_test.go
13
main_test.go
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
// "reflect"
|
// "reflect"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"net/url"
|
|
||||||
"net/http"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http/httptest"
|
|
||||||
|
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
)
|
)
|
||||||
@ -20,11 +19,13 @@ import (
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
type TokenServerHandler struct{}
|
type TokenServerHandler struct{}
|
||||||
|
|
||||||
func (t *TokenServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (t *TokenServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprint(w, `{"access_token":"123456789"}`)
|
fmt.Fprint(w, `{"access_token":"123456789"}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserServerHandler struct{}
|
type UserServerHandler struct{}
|
||||||
|
|
||||||
func (t *UserServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (t *UserServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprint(w, `{
|
fmt.Fprint(w, `{
|
||||||
"id":"1",
|
"id":"1",
|
||||||
@ -147,7 +148,7 @@ func TestHandler(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should pass through user
|
// Should pass through user
|
||||||
users := res.Header["X-Forwarded-User"];
|
users := res.Header["X-Forwarded-User"]
|
||||||
if len(users) != 1 {
|
if len(users) != 1 {
|
||||||
t.Error("Valid request missing X-Forwarded-User header")
|
t.Error("Valid request missing X-Forwarded-User header")
|
||||||
} else if users[0] != "test@example.com" {
|
} else if users[0] != "test@example.com" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user