From 5699ad0bf975388f688e67a4d97c8c4a2c8dc34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 28 Nov 2020 15:22:04 +0100 Subject: [PATCH] allow login using Query. --- internal/session/auth.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/internal/session/auth.go b/internal/session/auth.go index 9ccfa4ea..49c5fd68 100644 --- a/internal/session/auth.go +++ b/internal/session/auth.go @@ -8,7 +8,7 @@ import ( ) func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session, error) { - id, secret, ok := r.BasicAuth() + id, secret, ok := getAuthData(r) if !ok { return nil, fmt.Errorf("no authentication provided") } @@ -24,3 +24,19 @@ func (manager *SessionManagerCtx) Authenticate(r *http.Request) (types.Session, return session, nil } + +func getAuthData(r *http.Request) (string, string, bool) { + id, secret, ok := r.BasicAuth() + if ok { + return id, secret, true + } + + id = r.URL.Query().Get("id") + secret = r.URL.Query().Get("secret") + + if id != "" && secret != "" { + return id, secret, true + } + + return "", "", false +} \ No newline at end of file