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