an attempt at verifing the login token

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-24 05:46:37 +00:00
parent 7274c5c3c3
commit 0e7cb059d4
1 changed files with 45 additions and 2 deletions

View File

@ -22,6 +22,43 @@ type network struct {
Subdomain string `json:"subdomain"`
}
func checkLogin(token string) bool {
var networks []network
req, err := http.NewRequest("GET", API + "me", nil)
if err != nil {
log.Println("can't make new req")
return false
}
req.Header.Set("X-Wit-Auth", token)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Println("Can't exec the req to list networks: %s", err)
return false
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("can't read resp")
return false
}
log.Printf("RESPONSE =", body)
if body == nil {
log.Println("RESPONSE is nil")
return false
} else {
len := len(body)
err = json.Unmarshal(body, &networks)
if err != nil {
log.Println("body = ", body)
log.Println("body len = ", len)
log.Println("can't unmarshal resp for list networks: %s", err)
return false
}
}
spew.Dump(networks)
return true
}
func fetchNetworks(token string) []network {
var networks []network
req, err := http.NewRequest("GET", API + "clusters", nil)
@ -135,11 +172,12 @@ func processLoginEvent(ge *pb.Event) *pb.Event {
log.Println("processLoginEvent() START")
log.Println("processLoginEvent() ge.Token =", ge.Token)
e := pb.Event{}
log.Println("processLoginEvent() NEED TO LOGIN HERE OR CHECK TOKEN WORKS")
checkLogin(ge.Token)
log.Println("processLoginEvent() END")
e := pb.Event{}
return &e
}
@ -177,6 +215,11 @@ func sendProtobuf(conn *websocket.Conn, msg *pb.Event) {
func eventHandler(w http.ResponseWriter, r *http.Request) {
log.Println("echoHandler() START")
log.Println("echoHandler() ATTEMPT r.Header.Get", r.Header.Get("User-Agent"))
log.Println("echoHandler() ATTEMPT r.Header", r.Header)
for key, value := range r.Header {
log.Println("echoHandler() HEADER key, value =", key, value)
}
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {