From aa5fd309549e84fde4eca7ad120dbc3b59d33673 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Fri, 22 Oct 2021 08:28:31 +0200 Subject: Enable login screen with mocked JWT server --- jwt_mock.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 jwt_mock.go (limited to 'jwt_mock.go') diff --git a/jwt_mock.go b/jwt_mock.go new file mode 100644 index 0000000..e4a46f5 --- /dev/null +++ b/jwt_mock.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS, POST, PUT") + w.Header().Set("Access-Control-Allow-Headers", "Authorization") + + if r.Method == "OPTIONS" { + w.WriteHeader(http.StatusNoContent) + return + } + + auth := r.Header.Get("Authorization") + if auth != "Basic dXNyOnB3ZA==" { // btoa("usr:pwd") + w.WriteHeader(http.StatusUnauthorized) + return + } + + fmt.Fprint(w, "{\"access_token\": \"JWT_TOKEN_PLACEHOLDER\"}") + }) + + log.Fatal(http.ListenAndServe(":8080", nil)) +} -- cgit v1.1