lestrrat-go / jwx
Showing 4 of 9 files from the diff.

@@ -0,0 +1,147 @@
Loading
1 +
// This file is auto-generated by jwt/internal/cmd/gentoken/main.go. DO NOT EDIT
2 +
3 +
package openid
4 +
5 +
import (
6 +
	"time"
7 +
8 +
	"github.com/pkg/errors"
9 +
)
10 +
11 +
// Builder is a convenience wrapper around the New() constructor
12 +
// and the Set() methods to assign values to Token claims.
13 +
// Users can successively call Claim() on the Builder, and have it
14 +
// construct the Token when Build() is called. This alleviates the
15 +
// need for the user to check for the return value of every single
16 +
// Set() method call.
17 +
// Note that each call to Claim() overwrites the value set from the
18 +
// previous call.
19 +
type Builder struct {
20 +
	claims []*ClaimPair
21 +
}
22 +
23 +
func NewBuilder() *Builder {
24 +
	return &Builder{}
25 +
}
26 +
27 +
func (b *Builder) Claim(name string, value interface{}) *Builder {
28 +
	b.claims = append(b.claims, &ClaimPair{Key: name, Value: value})
29 +
	return b
30 +
}
31 +
32 +
func (b *Builder) Address(v *AddressClaim) *Builder {
33 +
	return b.Claim(AddressKey, v)
34 +
}
35 +
36 +
func (b *Builder) Audience(v []string) *Builder {
37 +
	return b.Claim(AudienceKey, v)
38 +
}
39 +
40 +
func (b *Builder) Birthdate(v *BirthdateClaim) *Builder {
41 +
	return b.Claim(BirthdateKey, v)
42 +
}
43 +
44 +
func (b *Builder) Email(v string) *Builder {
45 +
	return b.Claim(EmailKey, v)
46 +
}
47 +
48 +
func (b *Builder) EmailVerified(v bool) *Builder {
49 +
	return b.Claim(EmailVerifiedKey, v)
50 +
}
51 +
52 +
func (b *Builder) Expiration(v time.Time) *Builder {
53 +
	return b.Claim(ExpirationKey, v)
54 +
}
55 +
56 +
func (b *Builder) FamilyName(v string) *Builder {
57 +
	return b.Claim(FamilyNameKey, v)
58 +
}
59 +
60 +
func (b *Builder) Gender(v string) *Builder {
61 +
	return b.Claim(GenderKey, v)
62 +
}
63 +
64 +
func (b *Builder) GivenName(v string) *Builder {
65 +
	return b.Claim(GivenNameKey, v)
66 +
}
67 +
68 +
func (b *Builder) IssuedAt(v time.Time) *Builder {
69 +
	return b.Claim(IssuedAtKey, v)
70 +
}
71 +
72 +
func (b *Builder) Issuer(v string) *Builder {
73 +
	return b.Claim(IssuerKey, v)
74 +
}
75 +
76 +
func (b *Builder) JwtID(v string) *Builder {
77 +
	return b.Claim(JwtIDKey, v)
78 +
}
79 +
80 +
func (b *Builder) Locale(v string) *Builder {
81 +
	return b.Claim(LocaleKey, v)
82 +
}
83 +
84 +
func (b *Builder) MiddleName(v string) *Builder {
85 +
	return b.Claim(MiddleNameKey, v)
86 +
}
87 +
88 +
func (b *Builder) Name(v string) *Builder {
89 +
	return b.Claim(NameKey, v)
90 +
}
91 +
92 +
func (b *Builder) Nickname(v string) *Builder {
93 +
	return b.Claim(NicknameKey, v)
94 +
}
95 +
96 +
func (b *Builder) NotBefore(v time.Time) *Builder {
97 +
	return b.Claim(NotBeforeKey, v)
98 +
}
99 +
100 +
func (b *Builder) PhoneNumber(v string) *Builder {
101 +
	return b.Claim(PhoneNumberKey, v)
102 +
}
103 +
104 +
func (b *Builder) PhoneNumberVerified(v bool) *Builder {
105 +
	return b.Claim(PhoneNumberVerifiedKey, v)
106 +
}
107 +
108 +
func (b *Builder) Picture(v string) *Builder {
109 +
	return b.Claim(PictureKey, v)
110 +
}
111 +
112 +
func (b *Builder) PreferredUsername(v string) *Builder {
113 +
	return b.Claim(PreferredUsernameKey, v)
114 +
}
115 +
116 +
func (b *Builder) Profile(v string) *Builder {
117 +
	return b.Claim(ProfileKey, v)
118 +
}
119 +
120 +
func (b *Builder) Subject(v string) *Builder {
121 +
	return b.Claim(SubjectKey, v)
122 +
}
123 +
124 +
func (b *Builder) UpdatedAt(v time.Time) *Builder {
125 +
	return b.Claim(UpdatedAtKey, v)
126 +
}
127 +
128 +
func (b *Builder) Website(v string) *Builder {
129 +
	return b.Claim(WebsiteKey, v)
130 +
}
131 +
132 +
func (b *Builder) Zoneinfo(v string) *Builder {
133 +
	return b.Claim(ZoneinfoKey, v)
134 +
}
135 +
136 +
// Build creates a new token based on the claims that the builder has received
137 +
// so far. If a claim cannot be set, then the method returns a nil Token with
138 +
// a en error as a second return value
139 +
func (b *Builder) Build() (Token, error) {
140 +
	tok := New()
141 +
	for _, claim := range b.claims {
142 +
		if err := tok.Set(claim.Key.(string), claim.Value); err != nil {
143 +
			return nil, errors.Wrapf(err, `failed to set claim %q`, claim.Key.(string))
144 +
		}
145 +
	}
146 +
	return tok, nil
147 +
}

@@ -13,6 +13,17 @@
Loading
13 13
14 14
type Option = option.Interface
15 15
16 +
type ConstructorOption interface {
17 +
	Option
18 +
	constructorOption()
19 +
}
20 +
21 +
type constructorOption struct {
22 +
	Option
23 +
}
24 +
25 +
func (*constructorOption) constructorOption() {}
26 +
16 27
// GlobalOption describes an Option that can be passed to `Settings()`.
17 28
type GlobalOption interface {
18 29
	Option
@@ -109,6 +120,7 @@
Loading
109 120
func (*validateOption) validateOption() {}
110 121
111 122
type identAcceptableSkew struct{}
123 +
type identConstructorClaim struct{}
112 124
type identClock struct{}
113 125
type identContext struct{}
114 126
type identDecrypt struct{}
@@ -266,7 +278,7 @@
Loading
266 278
	return WithValidator(ClaimContainsString(AudienceKey, s))
267 279
}
268 280
269 -
// WithClaimValue specifies that expected any claim value.
281 +
// WithClaimValue specifies the expected value for a given claim
270 282
func WithClaimValue(name string, v interface{}) ValidateOption {
271 283
	return WithValidator(ClaimValueIs(name, v))
272 284
}
@@ -300,7 +312,7 @@
Loading
300 312
	return &globalOption{option.New(identFlattenAudience{}, v)}
301 313
}
302 314
303 -
type typedClaimPair struct {
315 +
type claimPair struct {
304 316
	Name  string
305 317
	Value interface{}
306 318
}
@@ -329,7 +341,7 @@
Loading
329 341
// `openid.New()` will respect this option, if you provide your own custom
330 342
// token type, it will need to implement the TokenWithDecodeCtx interface.
331 343
func WithTypedClaim(name string, object interface{}) ParseOption {
332 -
	return newParseOption(identTypedClaim{}, typedClaimPair{Name: name, Value: object})
344 +
	return newParseOption(identTypedClaim{}, claimPair{Name: name, Value: object})
333 345
}
334 346
335 347
// WithRequiredClaim specifies that the claim identified the given name
@@ -478,3 +490,7 @@
Loading
478 490
func WithContext(ctx context.Context) ValidateOption {
479 491
	return newValidateOption(identContext{}, ctx)
480 492
}
493 +
494 +
func WithClaim(name string, v interface{}) ConstructorOption {
495 +
	return &constructorOption{option.New(identConstructorClaim{}, &claimPair{Name: name, Value: v})}
496 +
}

@@ -133,7 +133,7 @@
Loading
133 133
		case identValidate{}:
134 134
			ctx.validate = o.Value().(bool)
135 135
		case identTypedClaim{}:
136 -
			pair := o.Value().(typedClaimPair)
136 +
			pair := o.Value().(claimPair)
137 137
			if ctx.localReg == nil {
138 138
				ctx.localReg = json.NewRegistry()
139 139
			}

@@ -0,0 +1,71 @@
Loading
1 +
// This file is auto-generated by jwt/internal/cmd/gentoken/main.go. DO NOT EDIT
2 +
3 +
package jwt
4 +
5 +
import (
6 +
	"time"
7 +
8 +
	"github.com/pkg/errors"
9 +
)
10 +
11 +
// Builder is a convenience wrapper around the New() constructor
12 +
// and the Set() methods to assign values to Token claims.
13 +
// Users can successively call Claim() on the Builder, and have it
14 +
// construct the Token when Build() is called. This alleviates the
15 +
// need for the user to check for the return value of every single
16 +
// Set() method call.
17 +
// Note that each call to Claim() overwrites the value set from the
18 +
// previous call.
19 +
type Builder struct {
20 +
	claims []*ClaimPair
21 +
}
22 +
23 +
func NewBuilder() *Builder {
24 +
	return &Builder{}
25 +
}
26 +
27 +
func (b *Builder) Claim(name string, value interface{}) *Builder {
28 +
	b.claims = append(b.claims, &ClaimPair{Key: name, Value: value})
29 +
	return b
30 +
}
31 +
32 +
func (b *Builder) Audience(v []string) *Builder {
33 +
	return b.Claim(AudienceKey, v)
34 +
}
35 +
36 +
func (b *Builder) Expiration(v time.Time) *Builder {
37 +
	return b.Claim(ExpirationKey, v)
38 +
}
39 +
40 +
func (b *Builder) IssuedAt(v time.Time) *Builder {
41 +
	return b.Claim(IssuedAtKey, v)
42 +
}
43 +
44 +
func (b *Builder) Issuer(v string) *Builder {
45 +
	return b.Claim(IssuerKey, v)
46 +
}
47 +
48 +
func (b *Builder) JwtID(v string) *Builder {
49 +
	return b.Claim(JwtIDKey, v)
50 +
}
51 +
52 +
func (b *Builder) NotBefore(v time.Time) *Builder {
53 +
	return b.Claim(NotBeforeKey, v)
54 +
}
55 +
56 +
func (b *Builder) Subject(v string) *Builder {
57 +
	return b.Claim(SubjectKey, v)
58 +
}
59 +
60 +
// Build creates a new token based on the claims that the builder has received
61 +
// so far. If a claim cannot be set, then the method returns a nil Token with
62 +
// a en error as a second return value
63 +
func (b *Builder) Build() (Token, error) {
64 +
	tok := New()
65 +
	for _, claim := range b.claims {
66 +
		if err := tok.Set(claim.Key.(string), claim.Value); err != nil {
67 +
			return nil, errors.Wrapf(err, `failed to set claim %q`, claim.Key.(string))
68 +
		}
69 +
	}
70 +
	return tok, nil
71 +
}
Files Coverage
internal 80.92%
jwa 100.00%
jwe 64.22%
jwk 72.79%
jws 75.51%
jwt 74.28%
cmd/jwx/jwx.go 100.00%
format.go 84.62%
formatkind_string_gen.go 100.00%
options.go 66.67%
x25519/x25519.go 82.35%
Project Totals (82 files) 72.41%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading