Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions appsTransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down