Skip to content

Commit

Permalink
Added a field to the user JWT that disables nonce verification when s…
Browse files Browse the repository at this point in the history
…et. (#62)

* Added a field to the user JWT that disables nonce verification when set.

* moved BearerToken to be inside of the "nats" configuration
  • Loading branch information
aricart committed Jan 14, 2020
1 parent 0c3fc7a commit 0b6d1dc
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion account_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestAccountImports(t *testing.T) {
func TestNewNilAccountClaim(t *testing.T) {
v := NewAccountClaims("")
if v != nil {
t.Fatal(fmt.Sprintf("expected nil account claim"))
t.Fatal("expected nil account claim")
}
}

Expand Down
2 changes: 1 addition & 1 deletion activation_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestPublicIsNotValid(t *testing.T) {
func TestNilActivationClaim(t *testing.T) {
v := NewActivationClaims("")
if v != nil {
t.Fatal(fmt.Sprintf("expected nil user claim"))
t.Fatal("expected nil user claim")
}
}

Expand Down
2 changes: 1 addition & 1 deletion cluster_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestClusterSubjects(t *testing.T) {
func TestNewNilClusterClaims(t *testing.T) {
v := NewClusterClaims("")
if v != nil {
t.Fatal(fmt.Sprintf("expected nil user claim"))
t.Fatal("expected nil user claim")
}
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/nats-io/jwt

require github.com/nats-io/nkeys v0.1.3

go 1.13
2 changes: 1 addition & 1 deletion operator_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestInvalidOperatorClaimIssuer(t *testing.T) {
func TestNewNilOperatorClaims(t *testing.T) {
v := NewOperatorClaims("")
if v != nil {
t.Fatal(fmt.Sprintf("expected nil user claim"))
t.Fatal("expected nil user claim")
}
}

Expand Down
2 changes: 1 addition & 1 deletion server_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestServerSubjects(t *testing.T) {
func TestNewNilServerClaims(t *testing.T) {
v := NewServerClaims("")
if v != nil {
t.Fatal(fmt.Sprintf("expected nil user claim"))
t.Fatal("expected nil user claim")
}
}

Expand Down
7 changes: 7 additions & 0 deletions user_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import (
type User struct {
Permissions
Limits
BearerToken bool `json:"bearer_token,omitempty"`
}

// Validate checks the permissions and limits in a User jwt
func (u *User) Validate(vr *ValidationResults) {
u.Permissions.Validate(vr)
u.Limits.Validate(vr)
// When BearerToken is true server will ignore any nonce-signing verification
}

// UserClaims defines a user JWT
Expand Down Expand Up @@ -97,3 +99,8 @@ func (u *UserClaims) Payload() interface{} {
func (u *UserClaims) String() string {
return u.ClaimsData.String(u)
}

// IsBearerToken returns true if nonce-signing requirements should be skipped
func (u *UserClaims) IsBearerToken() bool {
return u.BearerToken
}
2 changes: 1 addition & 1 deletion user_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestUserSubjects(t *testing.T) {
func TestNewNilUserClaim(t *testing.T) {
v := NewUserClaims("")
if v != nil {
t.Fatal(fmt.Sprintf("expected nil user claim"))
t.Fatal("expected nil user claim")
}
}

Expand Down

0 comments on commit 0b6d1dc

Please sign in to comment.