diff options
| author | Ernst Widerberg <ernstwi@kth.se> | 2021-10-22 08:28:31 +0200 |
|---|---|---|
| committer | Ernst Widerberg <ernstwi@kth.se> | 2021-10-22 08:28:31 +0200 |
| commit | aa5fd309549e84fde4eca7ad120dbc3b59d33673 (patch) | |
| tree | d9d22aec1757d1820c2772cc1deafba0b14ede4c /jwt_mock.go | |
| parent | 4fdefd6752854c0c5fcfe848f8770aa444fd2750 (diff) | |
Enable login screen with mocked JWT server
Diffstat (limited to 'jwt_mock.go')
| -rw-r--r-- | jwt_mock.go | 30 |
1 files changed, 30 insertions, 0 deletions
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)) +} |
