aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnirudh Oppiliappan <x@icyphox.sh>2021-11-10 16:39:29 +0530
committerAnirudh Oppiliappan <x@icyphox.sh>2021-11-10 16:39:29 +0530
commitffa051e58ce93755452e18655f74be200bceae0f (patch)
tree1b10c288356f527688d4ae8443fd59a3699167e9
parent96aeb8fa8fc95959f40f1a841e88b04e057ef211 (diff)
downloadfsrv-ffa051e58ce93755452e18655f74be200bceae0f.tar.gz
Implement bearer authentication
-rw-r--r--main.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/main.go b/main.go
index f48b6bf..007a083 100644
--- a/main.go
+++ b/main.go
@@ -31,10 +31,20 @@ func randName(n int) string {
31 return string(b) 31 return string(b)
32} 32}
33 33
34func getKey(r *http.Request) string {
35 var key string
36 header := r.Header.Get("Authorization")
37 key = strings.Split(header, " ")[1]
38 if key == "" {
39 key = r.FormValue("key")
40 }
41 return key
42}
43
34func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) { 44func (s *settings) uploadFile(w http.ResponseWriter, r *http.Request) {
35 switch r.Method { 45 switch r.Method {
36 case "POST": 46 case "POST":
37 key := r.FormValue("key") 47 key := getKey(r)
38 useragent := r.Header.Get("User-Agent") 48 useragent := r.Header.Get("User-Agent")
39 if key != s.key { 49 if key != s.key {
40 fmt.Fprintf(w, "incorrect key") 50 fmt.Fprintf(w, "incorrect key")