예제 #1
0
파일: totp.go 프로젝트: skyjia/go-otpserver
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})
}
예제 #2
0
파일: totp.go 프로젝트: skyjia/go-otpserver
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})
}