SHA256
more db stuff
This commit is contained in:
@@ -14,6 +14,7 @@ require (
|
|||||||
github.com/go-webauthn/x v0.1.9 // indirect
|
github.com/go-webauthn/x v0.1.9 // indirect
|
||||||
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
|
||||||
github.com/google/go-tpm v0.9.0 // indirect
|
github.com/google/go-tpm v0.9.0 // indirect
|
||||||
|
github.com/joho/godotenv v1.5.1 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/x448/float16 v0.8.4 // indirect
|
github.com/x448/float16 v0.8.4 // indirect
|
||||||
golang.org/x/crypto v0.21.0 // indirect
|
golang.org/x/crypto v0.21.0 // indirect
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ github.com/google/go-tpm v0.9.0 h1:sQF6YqWMi+SCXpsmS3fd21oPy/vSddwZry4JnmltHVk=
|
|||||||
github.com/google/go-tpm v0.9.0/go.mod h1:FkNVkc6C+IsvDI9Jw1OveJmxGZUUaKxtrpOS47QWKfU=
|
github.com/google/go-tpm v0.9.0/go.mod h1:FkNVkc6C+IsvDI9Jw1OveJmxGZUUaKxtrpOS47QWKfU=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"github.com/go-webauthn/webauthn/webauthn"
|
"github.com/go-webauthn/webauthn/webauthn"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -42,10 +43,15 @@ type PasskeyStore interface {
|
|||||||
func main() {
|
func main() {
|
||||||
l = log.Default()
|
l = log.Default()
|
||||||
|
|
||||||
|
godotenv.Load()
|
||||||
|
|
||||||
proto := getEnv("PROTO", "http")
|
proto := getEnv("PROTO", "http")
|
||||||
host := getEnv("HOST", "localhost")
|
host := getEnv("HOST", "localhost")
|
||||||
port := getEnv("PORT", ":8080")
|
port := ":" + getEnv("PORT", "8080")
|
||||||
origin := fmt.Sprintf("%s://%s%s", proto, host, port)
|
origin := fmt.Sprintf("%s://%s%s", proto, host, port)
|
||||||
|
dbUser := getEnv("DB_USER")
|
||||||
|
dbPassword := getEnv("DB_PASSWORD")
|
||||||
|
dbName := getEnv("DB_NAME")
|
||||||
|
|
||||||
l.Printf("[INFO] make webauthn config")
|
l.Printf("[INFO] make webauthn config")
|
||||||
wconfig := &webauthn.Config{
|
wconfig := &webauthn.Config{
|
||||||
@@ -56,10 +62,19 @@ func main() {
|
|||||||
|
|
||||||
l.Printf("[INFO] create webauthn")
|
l.Printf("[INFO] create webauthn")
|
||||||
if webAuthn, err = webauthn.New(wconfig); err != nil {
|
if webAuthn, err = webauthn.New(wconfig); err != nil {
|
||||||
fmt.Printf("[FATA] %s", err.Error())
|
fmt.Printf("[FATAL] %s", err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db, err := sql.Open("mysql", dbUser + ":" + dbPassword + "@/")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
// See "Important settings" section.
|
||||||
|
db.SetConnMaxLifetime(time.Minute * 3)
|
||||||
|
db.SetMaxOpenConns(10)
|
||||||
|
db.SetMaxIdleConns(10)
|
||||||
|
|
||||||
l.Printf("[INFO] create datastore")
|
l.Printf("[INFO] create datastore")
|
||||||
datastore = NewInMem(l)
|
datastore = NewInMem(l)
|
||||||
|
|
||||||
@@ -67,7 +82,7 @@ func main() {
|
|||||||
// Serve the web files
|
// Serve the web files
|
||||||
http.Handle("/", http.FileServer(http.Dir("./web")))
|
http.Handle("/", http.FileServer(http.Dir("./web")))
|
||||||
|
|
||||||
// Add auth the routes
|
// Add auth routes
|
||||||
http.HandleFunc("/api/passkey/registerStart", BeginRegistration)
|
http.HandleFunc("/api/passkey/registerStart", BeginRegistration)
|
||||||
http.HandleFunc("/api/passkey/registerFinish", FinishRegistration)
|
http.HandleFunc("/api/passkey/registerFinish", FinishRegistration)
|
||||||
http.HandleFunc("/api/passkey/loginStart", BeginLogin)
|
http.HandleFunc("/api/passkey/loginStart", BeginLogin)
|
||||||
@@ -154,7 +169,6 @@ func FinishRegistration(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
l.Printf(msg)
|
l.Printf(msg)
|
||||||
JSONResponse(w, msg, http.StatusBadRequest)
|
JSONResponse(w, msg, http.StatusBadRequest)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user