diff --git a/appsTransport.go b/appsTransport.go index be59c84..4e52fde 100644 --- a/appsTransport.go +++ b/appsTransport.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - jwt "github.com/dgrijalva/jwt-go/v4" + jwt "github.com/dgrijalva/jwt-go" ) // AppsTransport provides a http.RoundTripper by wrapping an existing @@ -64,14 +64,7 @@ func NewAppsTransportFromPrivateKey(tr http.RoundTripper, appID int64, key *rsa. // RoundTrip implements http.RoundTripper interface. func (t *AppsTransport) RoundTrip(req *http.Request) (*http.Response, error) { - claims := &jwt.StandardClaims{ - IssuedAt: jwt.Now(), - ExpiresAt: jwt.At(time.Now().Add(time.Minute)), - Issuer: strconv.FormatInt(t.appID, 10), - } - bearer := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) - - ss, err := bearer.SignedString(t.key) + ss, err := t.Token() if err != nil { return nil, fmt.Errorf("could not sign jwt: %s", err) } @@ -82,3 +75,15 @@ func (t *AppsTransport) RoundTrip(req *http.Request) (*http.Response, error) { resp, err := t.tr.RoundTrip(req) return resp, err } + +// Token returns the complete, signed Github app JWT token +func (t *AppsTransport) Token() (string, error) { + claims := &jwt.StandardClaims{ + IssuedAt: time.Now().Unix(), + ExpiresAt: time.Now().Add(time.Minute).Unix(), + Issuer: strconv.FormatInt(t.appID, 10), + } + bearer := jwt.NewWithClaims(jwt.SigningMethodRS256, claims) + + return bearer.SignedString(t.key) +} diff --git a/go.mod b/go.mod index efcad42..05f170d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bradleyfalzon/ghinstallation go 1.13 require ( - github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 + github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/google/go-cmp v0.4.0 github.com/google/go-github/v30 v30.0.0 ) diff --git a/go.sum b/go.sum index 541aca2..afa4c48 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU= -github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1/go.mod h1:+hnT3ywWDTAFrW5aE+u2Sa/wT555ZqwoCS+pk3p6ry4= +github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=