Exemplo n.º 1
0
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})
}
Exemplo n.º 2
0
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})
}