blob: e4a46f5740157356e41e0bf97c0bb7054d148905 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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))
}
|