-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (49 loc) · 1.36 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"github.com/go-webauthn/webauthn/webauthn"
)
var (
webAuthn *webauthn.WebAuthn
err error
)
type Params struct {
Username string
}
type FIDO2Response struct {
Status string `json:"status"`
ErrorMessage string `json:"errorMessage"`
}
func jsonResponse(w http.ResponseWriter, d interface{}, c int) {
dj, err := json.Marshal(d)
if err != nil {
http.Error(w, "Error creating JSON response", http.StatusInternalServerError)
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(c)
fmt.Fprintf(w, "%s", dj)
}
func main() {
wconfig := &webauthn.Config{
RPDisplayName: "Go WebAuthn",
RPID: "localhost",
RPOrigin: "http://localhost:8080",
}
if webAuthn, err = webauthn.New(wconfig); err != nil {
log.Fatal(err)
}
http.HandleFunc("/attestation/options", AttestationOptions)
http.HandleFunc("/attestation/result", AttestationResult)
http.HandleFunc("/assertion/options", AssertionOptions)
http.HandleFunc("/assertion/result", AssertionResult)
http.Handle("/", http.FileServer(http.Dir("./templates")))
http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "templates/login.html")
})
serverAddr := "localhost:8080"
log.Println("Listening on http://" + serverAddr)
log.Fatal(http.ListenAndServe(serverAddr, nil))
}