func (secret *ServicePrincipalCertificateSecret) SignJwt(spt *ServicePrincipalToken) (string, error) {
	hasher := sha1.New()
	_, err := hasher.Write(secret.Certificate.Raw)
	if err != nil {
		return "", err
	}
	thumbprint := base64.URLEncoding.EncodeToString(hasher.Sum(nil))
	jti := make([]byte, 20)
	_, err = rand.Read(jti)
	if err != nil {
		return "", err
	}
	token := jwt.New(jwt.SigningMethodRS256)
	token.Header["x5t"] = thumbprint
	x5c := []string{base64.StdEncoding.EncodeToString(secret.Certificate.Raw)}
	token.Header["x5c"] = x5c
	token.Claims = jwt.MapClaims{
		"aud": spt.inner.OauthConfig.TokenEndpoint.String(),
		"iss": spt.inner.ClientID,
		"sub": spt.inner.ClientID,
		"jti": base64.URLEncoding.EncodeToString(jti),
		"nbf": time.Now().Unix(),
		"exp": time.Now().Add(24 * time.Hour).Unix(),
	}
	signedString, err := token.SignedString(secret.PrivateKey)
	return signedString, err
}
SignJwt returns the JWT signed with the certificate's private key.
package adal
import (
	"context"
	"crypto/rand"
	"crypto/rsa"
	"crypto/sha1"
	"crypto/x509"
	"encoding/base64"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"math"
	"net/http"
	"net/url"
	"os"
	"strings"
	"sync"
	"time"
	"github.com/Azure/go-autorest/autorest/date"
	"github.com/form3tech-oss/jwt-go"
)
const (
	defaultRefresh = 5 * time.Minute
	OAuthGrantTypeDeviceCode = "device_code"
	OAuthGrantTypeClientCredentials = "client_credentials"
	OAuthGrantTypeUserPass = "password"
	OAuthGrantTypeRefreshToken = "refresh_token"
	OAuthGrantTypeAuthorizationCode = "authorization_code"
	metadataHeader = "Metadata"
	msiEndpoint = "http://169.254.169.254/metadata/identity/oauth2/token"
	msiAPIVersion = "2018-02-01"
	defaultMaxMSIRefreshAttempts = 5
	asMSIEndpointEnv = "MSI_ENDPOINT"
	asMSISecretEnv = "MSI_SECRET"
	appServiceAPIVersion = "2017-09-01"
)
type OAuthTokenProvider interface {
	OAuthToken() string
}
type MultitenantOAuthTokenProvider interface {
	PrimaryOAuthToken() string
	AuxiliaryOAuthTokens() []string
}
type TokenRefreshError interface {
	error
	Response() *http.Response
}
type Refresher interface {
	Refresh() error
	RefreshExchange(resource string) error
	EnsureFresh() error
}
type RefresherWithContext interface {
	RefreshWithContext(ctx context.Context) error
	RefreshExchangeWithContext(ctx context.Context, resource string) error
	EnsureFreshWithContext(ctx context.Context) error
}
type TokenRefreshCallback func(Token) error
type TokenRefresh func(ctx context.Context, resource string) (*Token, error)
type Token struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn json.Number `json:"expires_in"`
	ExpiresOn json.Number `json:"expires_on"`
	NotBefore json.Number `json:"not_before"`
	Resource string `json:"resource"`
	Type     string `json:"token_type"`
}
func newToken() Token {
	return Token{
		ExpiresIn: "0",
		ExpiresOn: "0",
		NotBefore: "0",
	}
}
func (t Token) IsZero() bool {
	return t == Token{}
}
func (t Token) Expires() time.Time {
	s, err := t.ExpiresOn.Float64()
	if err != nil {
		s = -3600
	}
	expiration := date.NewUnixTimeFromSeconds(s)
	return time.Time(expiration).UTC()
}
func (t Token) IsExpired() bool {
	return t.WillExpireIn(0)
}
func (t Token) WillExpireIn(d time.Duration) bool {
	return !t.Expires().After(time.Now().Add(d))
}
func (t *Token) OAuthToken() string {
	return t.AccessToken
}
type ServicePrincipalSecret interface {
	SetAuthenticationValues(spt *ServicePrincipalToken, values *url.Values) error
}
type ServicePrincipalNoSecret struct {
}
func (noSecret *ServicePrincipalNoSecret) SetAuthenticationValues(spt *ServicePrincipalToken, v *url.Values) error {
	return fmt.Errorf("Manually created ServicePrincipalToken does not contain secret material to retrieve a new access token")
}
func (noSecret ServicePrincipalNoSecret) MarshalJSON() ([]byte, error) {
	type tokenType struct {
		Type string `json:"type"`
	}
	return json.Marshal(tokenType{
		Type: "ServicePrincipalNoSecret",
	})
}
type ServicePrincipalTokenSecret struct {
	ClientSecret string `json:"value"`
}
func (tokenSecret *ServicePrincipalTokenSecret) SetAuthenticationValues(spt *ServicePrincipalToken, v *url.Values) error {
	v.Set("client_secret", tokenSecret.ClientSecret)
	return nil
}
func (tokenSecret ServicePrincipalTokenSecret) MarshalJSON() ([]byte, error) {
	type tokenType struct {
		Type  string `json:"type"`
		Value string `json:"value"`
	}
	return json.Marshal(tokenType{
		Type:  "ServicePrincipalTokenSecret",
		Value: tokenSecret.ClientSecret,
	})
}
type ServicePrincipalCertificateSecret struct {
	Certificate *x509.Certificate
	PrivateKey  *rsa.PrivateKey
}