func verifyTOTPHandler(w rest.ResponseWriter, req *rest.Request) { type verifyTOTPRequest struct { Token string `json:"token"` Secret string `json:"secret"` } body := verifyTOTPRequest{} if err := req.DecodeJsonPayload(&body); err != nil { rest.Error(w, err.Error(), http.StatusInternalServerError) return } isValid := VerifyTOTP(body.Token, body.Secret) w.WriteJson(map[string]interface{}{"isValid": isValid}) }
func generateTOTPAuthURLHandler(w rest.ResponseWriter, req *rest.Request) { type generateTOTPAuthURLRequest struct { Issuer string `json:"issuer"` AccountName string `json:"accountName"` Secret string `json:"secret"` } body := generateTOTPAuthURLRequest{} if err := req.DecodeJsonPayload(&body); err != nil { rest.Error(w, err.Error(), http.StatusInternalServerError) return } authURL := GenerateTOTPAuthURL(body.Issuer, body.AccountName, body.Secret) w.WriteJson(map[string]interface{}{"authURL": authURL}) }