1 // Package openid provides a specialized token that provides utilities 2 // to work with OpenID JWT tokens. 3 // 4 // In order to use OpenID claims, you specify the token to use in the 5 // jwt.Parse method 6 // 7 // jwt.Parse(data, jwt.WithToken(openid.New()) 8 package openid 9 10 import ( 11 "github.com/lestrrat-go/jwx/internal/json" 12 "github.com/lestrrat-go/jwx/jwt" 13 "github.com/pkg/errors" 14 ) 15 16 var registry = json.NewRegistry() 17 18 func (t *stdToken) Clone() (jwt.Token, error) { 19 var dst jwt.Token = New() 20 21 for _, pair := range t.makePairs() { 22 //nolint:forcetypeassert 23 key := pair.Key.(string) 24 if err := dst.Set(key, pair.Value); err != nil { 25 return nil, errors.Wrapf(err, `failed to set %s`, key) 26 } 27 } 28 return dst, nil 29 } 30 31 // RegisterCustomField allows users to specify that a private field 32 // be decoded as an instance of the specified type. This option has 33 // a global effect. 34 // 35 // For example, suppose you have a custom field `x-birthday`, which 36 // you want to represent as a string formatted in RFC3339 in JSON, 37 // but want it back as `time.Time`. 38 // 39 // In that case you would register a custom field as follows 40 // 41 // jwt.RegisterCustomField(`x-birthday`, timeT) 42 // 43 // Then `token.Get("x-birthday")` will still return an `interface{}`, 44 // but you can convert its type to `time.Time` 45 // 46 // bdayif, _ := token.Get(`x-birthday`) 47 // bday := bdayif.(time.Time) 48 // 49 func RegisterCustomField(name string, object interface{}) { 50 registry.Register(name, object) 51 } 52