func IsValidTokenFormat(tkn string) bool {
	if tkn == "" {
		return false
	}
	splitTkn := strings.Split(tkn, " ")
	if len(splitTkn) <= 1 {
		return false
	}
	tknType := splitTkn[0]
	tknValue := splitTkn[1]
	if strings.Compare(tknType, "Bearer") != 0 {
		logger.Infof("Token %s is not a Bearer token", tknType)
		return false
	}
	if tknValue == "" {
		return false
	}
	return true
}
IsValidTokenFormat checks if a token is a well formatted Bearer token
package session
import (
	"bytes"
	"crypto/rsa"
	"encoding/base64"
	"encoding/binary"
	"encoding/json"
	"errors"
	"fmt"
	"math/big"
	"strings"
	"github.com/dgrijalva/jwt-go"
	"github.com/krane/krane/internal/logger"
)
type Claims struct {
	Phrase string `json:"phrase"`
	jwt.StandardClaims
}
type CustomClaims struct {
	Data interface{} `json:"data"`
	jwt.StandardClaims
}
func DecodeJWTToken(signKey string, tknStr string) (jwt.Token, error) {
	tkn, err := jwt.ParseWithClaims(tknStr, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) {
		return []byte(signKey), nil
	})
	if err != nil {
		return jwt.Token{}, err
	}
	if !tkn.Valid {
		return jwt.Token{}, errors.New("token is not valid")
	}
	return *tkn, nil
}
func DecodeJWTWithPubKey(pubKey string, tknStr string) (claims jwt.Claims, err error) {
	rsaPubKey, err := DecodePublicKey(pubKey)
	if err != nil {
		return
	}
	tkn, err := jwt.ParseWithClaims(
		tknStr,
		&Claims{},
		func(token *jwt.Token) (interface{}, error) {
			return rsaPubKey, nil
		},
	)
	if err != nil {
		return
	}
	if !tkn.Valid {
		return nil, fmt.Errorf("token not valid %v", tkn.Claims.Valid())
	}
	return tkn.Claims, nil
}
func VerifyAuthTokenWithAuthorizedKeys(keys []string, tkn string) (claims *Claims) {
	for _, key := range keys {
		c, err := DecodeJWTWithPubKey(key, tkn)
		if err != nil {
			logger.Debugf("unable to decode JWT token with server private key %s", err.Error())
			continue
		}
		claims, _ = c.(*Claims)
		break
	}
	return
}
func DecodePublicKey(str string) (*rsa.PublicKey, error) {
	tokens := strings.Split(str, " ")
	if len(tokens) < 2 {
		return nil, fmt.Errorf("Invalid key format; must contain at least two fields (keytype data [comment])")
	}
	keyType := tokens[0]
	data, err := base64.StdEncoding.DecodeString(tokens[1])
	if err != nil {
		return nil, err
	}
	format, e, n, err := getRsaValues(data)
	if format != keyType {
		return nil, fmt.Errorf("Key type said %s, but encoded format said %s.  These should match", keyType, format)
	}
	pubKey := &rsa.PublicKey{
		N: n,
		E: int(e.Int64()),
	}
	return pubKey, nil
}
func ParseTokenTypeAndValue(tkn string) (tokenType string, tokenValue string) {
	if tkn == "" {
		logger.Error(errors.New("No token provided"))
		return "", ""
	}
	splitTkn := strings.Split(tkn, " ")
	return splitTkn[0], splitTkn[1]
}
func ParseSessionTokenFromJWTClaims(tkn jwt.Token) (Token, error) {
	claims, ok := tkn.Claims.(*CustomClaims)
	if !ok {
		return Token{}, errors.New("unable to parse the claims for the provided token")
	}
	var sessionTkn Token
	bytes, _ := json.Marshal(claims.Data)
	_ = json.Unmarshal(bytes, &sessionTkn)
	return sessionTkn, nil
}