Skip to content

Commit

Permalink
update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
theganyo committed Jun 18, 2020
1 parent 6b04dd7 commit d3080e6
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 43 deletions.
11 changes: 3 additions & 8 deletions cmd/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,11 @@ func (t *token) inspectToken(in io.Reader, printf shared.FormatFn) error {
if err != nil {
return errors.Wrap(err, "parsing jwt token")
}
jsonBytes, err := token.MarshalJSON()
buf, err := json.MarshalIndent(token, "", "\t")
if err != nil {
return errors.Wrap(err, "printing jwt token")
}
var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, jsonBytes, "", "\t")
if err != nil {
return errors.Wrap(err, "printing jwt token")
}
printf(prettyJSON.String())
printf("%s", buf)

// verify JWT
printf("\nverifying...")
Expand All @@ -258,7 +253,7 @@ func (t *token) inspectToken(in io.Reader, printf shared.FormatFn) error {
if _, err = jws.VerifyWithJWKSet(jwtBytes, jwkSet, nil); err != nil {
return errors.Wrap(err, "verifying cert")
}
if err := token.Verify(jwt.WithAcceptableSkew(time.Minute)); err != nil {
if err := jwt.Verify(token, jwt.WithAcceptableSkew(time.Minute)); err != nil {
printf("invalid token: %s", err)
return nil
}
Expand Down
15 changes: 13 additions & 2 deletions cmd/token/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,21 @@ func TestTokenInspect(t *testing.T) {
if err != nil {
t.Fatalf("error: %v", err)
}
key.Set(jwk.KeyIDKey, "kid")
key.Set(jwk.AlgorithmKey, jwa.RS256)

jwksBuf, err := json.MarshalIndent(key, "", "")
if err != nil {
t.Fatalf("error: %v", err)
}
t.Logf("jwks: %s", jwksBuf)

ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(key)
_, err := w.Write(jwksBuf)
if err != nil {
t.Fatalf("error: %v", err)
}
}))
defer ts.Close()

Expand Down Expand Up @@ -124,7 +135,7 @@ func generateJWT(privateKey *rsa.PrivateKey) (string, error) {
token.Set("application_name", "/appname/")
token.Set("scope", "scope1 scope2")
token.Set("api_product_list", []string{"/product/"})
payload, err := token.Sign(jwa.RS256, privateKey)
payload, err := jwt.Sign(token, jwa.RS256, privateKey)

return string(payload), err
}
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ go 1.13
// replace github.com/apigee/apigee-remote-service-envoy => ../apigee-remote-service-envoy

require (
github.com/apigee/apigee-remote-service-envoy v1.0.0-beta.3
github.com/apigee/apigee-remote-service-golib v1.0.0-beta.3
github.com/apigee/apigee-remote-service-envoy v1.0.0-beta.3.0.20200618203739-37ac2b14898d
github.com/apigee/apigee-remote-service-golib v1.0.0-beta.3.0.20200618203547-765ca9c46796
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d
github.com/google/go-querystring v1.0.0
github.com/lestrrat-go/jwx v0.9.1
github.com/lestrrat-go/jwx v1.0.2
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.0.0
go.uber.org/multierr v1.5.0
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
)
Loading

0 comments on commit d3080e6

Please sign in to comment.