func GetKontrolKey(token *jwt.Token) (interface{}, error) {
	return (&Extractor{}).Extract(token)
}
GetKontrolKey is used as key getter func for jwt.Parse() function.
package kitekey
import (
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"os/user"
	"path/filepath"
	"strings"
	"github.com/dgrijalva/jwt-go"
)
const (
	kiteDirName     = ".kite"
	kiteKeyFileName = "kite.key"
)
type KiteClaims struct {
	jwt.StandardClaims
	KontrolKey string `json:"kontrolKey,omitempty"`
	KontrolURL string `json:"kontrolURL,omitempty"`
}
func KiteHome() (string, error) {
	kiteHome := os.Getenv("KITE_HOME")
	if kiteHome != "" {
		return kiteHome, nil
	}
	usr, err := user.Current()
	if err != nil {
		return "", err
	}
	return filepath.Join(usr.HomeDir, kiteDirName), nil
}
func kiteKeyPath() (string, error) {
	kiteHome, err := KiteHome()
	if err != nil {
		return "", err
	}
	return filepath.Join(kiteHome, kiteKeyFileName), nil
}
func Read() (string, error) {
	keyPath, err := kiteKeyPath()
	if err != nil {
		return "", err
	}
	data, err := ioutil.ReadFile(keyPath)
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(string(data)), nil
}
func Write(kiteKey string) error {
	keyPath, err := kiteKeyPath()
	if err != nil {
		return err
	}
	err = os.MkdirAll(filepath.Dir(keyPath), 0700)
	if err != nil {
		return err
	}
	os.Remove(keyPath)
	return ioutil.WriteFile(keyPath, []byte(kiteKey), 0400)
}
func Parse() (*jwt.Token, error) {
	kiteKey, err := Read()
	if err != nil {
		return nil, err
	}
	return jwt.ParseWithClaims(kiteKey, &KiteClaims{}, GetKontrolKey)
}
func ParseFile(file string) (*jwt.Token, error) {
	kiteKey, err := ioutil.ReadFile(file)
	if err != nil {
		return nil, err
	}
	return jwt.ParseWithClaims(string(bytes.TrimSpace(kiteKey)), &KiteClaims{}, GetKontrolKey)
}
type Extractor struct {
	Token  *jwt.Token
	Claims *KiteClaims
}
func (e *Extractor) Extract(token *jwt.Token) (interface{}, error) {
	e.Token = token
	if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
		return nil, errors.New("invalid signing method")
	}
	claims, ok := token.Claims.(*KiteClaims)
	if !ok {
		return nil, fmt.Errorf("no kontrol key found")
	}
	e.Claims = claims
	return jwt.ParseRSAPublicKeyFromPEM([]byte(claims.KontrolKey))
}