-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoVNC.go
37 lines (30 loc) · 889 Bytes
/
noVNC.go
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
31
32
33
34
35
36
37
package main
import (
"fmt"
"log"
"net/http"
"github.com/SUASecLab/workadventure_admin_extensions/extensions"
)
func noVNCPasswordHandler(w http.ResponseWriter, r *http.Request) {
//Send HTTP headers for CORS and enable JSON encoding
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "text/plain")
// Get token
token := r.URL.Query().Get("token")
// Authorize
noVNCDecision, err := extensions.GetAuthDecision("http://" + sidecarUrl +
"/auth?token=" + token + "&service=noVNC")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fmt.Fprintf(w, "Error while authorizing")
log.Println("Could not authorize user:", err)
return
}
if !noVNCDecision.Allowed {
w.WriteHeader(http.StatusForbidden)
fmt.Fprintln(w, "The provided token is invalid")
return
}
// Print password
fmt.Fprintln(w, string(noVNCPassword))
}