github.com/lestrrat-go/jwx/v2@v2.0.21/jwt/options_gen.go (about)

     1  // Code generated by tools/cmd/genoptions/main.go. DO NOT EDIT.
     2  
     3  package jwt
     4  
     5  import (
     6  	"context"
     7  	"io/fs"
     8  	"time"
     9  
    10  	"github.com/lestrrat-go/jwx/v2/jwe"
    11  	"github.com/lestrrat-go/jwx/v2/jws"
    12  	"github.com/lestrrat-go/option"
    13  )
    14  
    15  type Option = option.Interface
    16  
    17  // EncryptOption describes an Option that can be passed to (jwt.Serializer).Encrypt
    18  type EncryptOption interface {
    19  	Option
    20  	encryptOption()
    21  }
    22  
    23  type encryptOption struct {
    24  	Option
    25  }
    26  
    27  func (*encryptOption) encryptOption() {}
    28  
    29  // GlobalOption describes an Option that can be passed to `Settings()`.
    30  type GlobalOption interface {
    31  	Option
    32  	globalOption()
    33  }
    34  
    35  type globalOption struct {
    36  	Option
    37  }
    38  
    39  func (*globalOption) globalOption() {}
    40  
    41  // ParseOption describes an Option that can be passed to `jwt.Parse()`.
    42  // ParseOption also implements ReadFileOption, therefore it may be
    43  // safely pass them to `jwt.ReadFile()`
    44  type ParseOption interface {
    45  	Option
    46  	parseOption()
    47  	readFileOption()
    48  }
    49  
    50  type parseOption struct {
    51  	Option
    52  }
    53  
    54  func (*parseOption) parseOption() {}
    55  
    56  func (*parseOption) readFileOption() {}
    57  
    58  // ReadFileOption is a type of `Option` that can be passed to `jws.ReadFile`
    59  type ReadFileOption interface {
    60  	Option
    61  	readFileOption()
    62  }
    63  
    64  type readFileOption struct {
    65  	Option
    66  }
    67  
    68  func (*readFileOption) readFileOption() {}
    69  
    70  // SignEncryptParseOption describes an Option that can be passed to both `jwt.Sign()` or
    71  // `jwt.Parse()`
    72  type SignEncryptParseOption interface {
    73  	Option
    74  	parseOption()
    75  	encryptOption()
    76  	readFileOption()
    77  	signOption()
    78  }
    79  
    80  type signEncryptParseOption struct {
    81  	Option
    82  }
    83  
    84  func (*signEncryptParseOption) parseOption() {}
    85  
    86  func (*signEncryptParseOption) encryptOption() {}
    87  
    88  func (*signEncryptParseOption) readFileOption() {}
    89  
    90  func (*signEncryptParseOption) signOption() {}
    91  
    92  // SignOption describes an Option that can be passed to `jwt.Sign()` or
    93  // (jwt.Serializer).Sign
    94  type SignOption interface {
    95  	Option
    96  	signOption()
    97  }
    98  
    99  type signOption struct {
   100  	Option
   101  }
   102  
   103  func (*signOption) signOption() {}
   104  
   105  // ValidateOption describes an Option that can be passed to Validate().
   106  // ValidateOption also implements ParseOption, therefore it may be
   107  // safely passed to `Parse()` (and thus `jwt.ReadFile()`)
   108  type ValidateOption interface {
   109  	Option
   110  	parseOption()
   111  	readFileOption()
   112  	validateOption()
   113  }
   114  
   115  type validateOption struct {
   116  	Option
   117  }
   118  
   119  func (*validateOption) parseOption() {}
   120  
   121  func (*validateOption) readFileOption() {}
   122  
   123  func (*validateOption) validateOption() {}
   124  
   125  type identAcceptableSkew struct{}
   126  type identClock struct{}
   127  type identCompactOnly struct{}
   128  type identContext struct{}
   129  type identEncryptOption struct{}
   130  type identFS struct{}
   131  type identFlattenAudience struct{}
   132  type identFormKey struct{}
   133  type identHeaderKey struct{}
   134  type identKeyProvider struct{}
   135  type identNumericDateFormatPrecision struct{}
   136  type identNumericDateParsePedantic struct{}
   137  type identNumericDateParsePrecision struct{}
   138  type identPedantic struct{}
   139  type identSignOption struct{}
   140  type identToken struct{}
   141  type identTruncation struct{}
   142  type identValidate struct{}
   143  type identValidator struct{}
   144  type identVerify struct{}
   145  
   146  func (identAcceptableSkew) String() string {
   147  	return "WithAcceptableSkew"
   148  }
   149  
   150  func (identClock) String() string {
   151  	return "WithClock"
   152  }
   153  
   154  func (identCompactOnly) String() string {
   155  	return "WithCompactOnly"
   156  }
   157  
   158  func (identContext) String() string {
   159  	return "WithContext"
   160  }
   161  
   162  func (identEncryptOption) String() string {
   163  	return "WithEncryptOption"
   164  }
   165  
   166  func (identFS) String() string {
   167  	return "WithFS"
   168  }
   169  
   170  func (identFlattenAudience) String() string {
   171  	return "WithFlattenAudience"
   172  }
   173  
   174  func (identFormKey) String() string {
   175  	return "WithFormKey"
   176  }
   177  
   178  func (identHeaderKey) String() string {
   179  	return "WithHeaderKey"
   180  }
   181  
   182  func (identKeyProvider) String() string {
   183  	return "WithKeyProvider"
   184  }
   185  
   186  func (identNumericDateFormatPrecision) String() string {
   187  	return "WithNumericDateFormatPrecision"
   188  }
   189  
   190  func (identNumericDateParsePedantic) String() string {
   191  	return "WithNumericDateParsePedantic"
   192  }
   193  
   194  func (identNumericDateParsePrecision) String() string {
   195  	return "WithNumericDateParsePrecision"
   196  }
   197  
   198  func (identPedantic) String() string {
   199  	return "WithPedantic"
   200  }
   201  
   202  func (identSignOption) String() string {
   203  	return "WithSignOption"
   204  }
   205  
   206  func (identToken) String() string {
   207  	return "WithToken"
   208  }
   209  
   210  func (identTruncation) String() string {
   211  	return "WithTruncation"
   212  }
   213  
   214  func (identValidate) String() string {
   215  	return "WithValidate"
   216  }
   217  
   218  func (identValidator) String() string {
   219  	return "WithValidator"
   220  }
   221  
   222  func (identVerify) String() string {
   223  	return "WithVerify"
   224  }
   225  
   226  // WithAcceptableSkew specifies the duration in which exp and nbf
   227  // claims may differ by. This value should be positive
   228  func WithAcceptableSkew(v time.Duration) ValidateOption {
   229  	return &validateOption{option.New(identAcceptableSkew{}, v)}
   230  }
   231  
   232  // WithClock specifies the `Clock` to be used when verifying
   233  // exp and nbf claims.
   234  func WithClock(v Clock) ValidateOption {
   235  	return &validateOption{option.New(identClock{}, v)}
   236  }
   237  
   238  // WithCompactOnly option controls whether jwt.Parse should accept only tokens
   239  // that are in compact serialization format. RFC7519 specifies that JWTs
   240  // should be serialized in JWS compact form only, but historically this library
   241  // allowed for deserialization of JWTs in JWS's JSON serialization format.
   242  // Specifying this option will disable this behavior, and will report
   243  // errots if the token is not in compact serialization format.
   244  func WithCompactOnly(v bool) GlobalOption {
   245  	return &globalOption{option.New(identCompactOnly{}, v)}
   246  }
   247  
   248  // WithContext allows you to specify a context.Context object to be used
   249  // with `jwt.Validate()` option.
   250  //
   251  // Please be aware that in the next major release of this library,
   252  // `jwt.Validate()`'s signature will change to include an explicit
   253  // `context.Context` object.
   254  func WithContext(v context.Context) ValidateOption {
   255  	return &validateOption{option.New(identContext{}, v)}
   256  }
   257  
   258  // WithEncryptOption provides an escape hatch for cases where extra options to
   259  // `(jws.Serializer).Encrypt()` must be specified when usng `jwt.Sign()`. Normally you do not
   260  // need to use this.
   261  func WithEncryptOption(v jwe.EncryptOption) EncryptOption {
   262  	return &encryptOption{option.New(identEncryptOption{}, v)}
   263  }
   264  
   265  // WithFS specifies the source `fs.FS` object to read the file from.
   266  func WithFS(v fs.FS) ReadFileOption {
   267  	return &readFileOption{option.New(identFS{}, v)}
   268  }
   269  
   270  // WithFlattenAudience specifies the the `jwt.FlattenAudience` option on
   271  // every token defaults to enabled. You can still disable this on a per-object
   272  // basis using the `jwt.Options().Disable(jwt.FlattenAudience)` method call.
   273  //
   274  // See the documentation for `jwt.TokenOptionSet`, `(jwt.Token).Options`, and
   275  // `jwt.FlattenAudience` for more details
   276  func WithFlattenAudience(v bool) GlobalOption {
   277  	return &globalOption{option.New(identFlattenAudience{}, v)}
   278  }
   279  
   280  // WithFormKey is used to specify header keys to search for tokens.
   281  //
   282  // While the type system allows this option to be passed to jwt.Parse() directly,
   283  // doing so will have no effect. Only use it for HTTP request parsing functions
   284  func WithFormKey(v string) ParseOption {
   285  	return &parseOption{option.New(identFormKey{}, v)}
   286  }
   287  
   288  // WithHeaderKey is used to specify header keys to search for tokens.
   289  //
   290  // While the type system allows this option to be passed to `jwt.Parse()` directly,
   291  // doing so will have no effect. Only use it for HTTP request parsing functions
   292  func WithHeaderKey(v string) ParseOption {
   293  	return &parseOption{option.New(identHeaderKey{}, v)}
   294  }
   295  
   296  // WithKeyProvider allows users to specify an object to provide keys to
   297  // sign/verify tokens using arbitrary code. Please read the documentation
   298  // for `jws.KeyProvider` in the `jws` package for details on how this works.
   299  func WithKeyProvider(v jws.KeyProvider) ParseOption {
   300  	return &parseOption{option.New(identKeyProvider{}, v)}
   301  }
   302  
   303  // WithNumericDateFormatPrecision sets the precision up to which the
   304  // library uses to format fractional dates found in the numeric date
   305  // fields. Default is 0 (second, no fractionals), max is 9 (nanosecond)
   306  func WithNumericDateFormatPrecision(v int) GlobalOption {
   307  	return &globalOption{option.New(identNumericDateFormatPrecision{}, v)}
   308  }
   309  
   310  // WithNumericDateParsePedantic specifies if the parser should behave
   311  // in a pedantic manner when parsing numeric dates. Normally this library
   312  // attempts to interpret timestamps as a numeric value representing
   313  // number of seconds (with an optional fractional part), but if that fails
   314  // it tries to parse using a RFC3339 parser. This allows us to parse
   315  // payloads from non-comforming servers.
   316  //
   317  // However, when you set WithNumericDateParePedantic to `true`, the
   318  // RFC3339 parser is not tried, and we expect a numeric value strictly
   319  func WithNumericDateParsePedantic(v bool) GlobalOption {
   320  	return &globalOption{option.New(identNumericDateParsePedantic{}, v)}
   321  }
   322  
   323  // WithNumericDateParsePrecision sets the precision up to which the
   324  // library uses to parse fractional dates found in the numeric date
   325  // fields. Default is 0 (second, no fractionals), max is 9 (nanosecond)
   326  func WithNumericDateParsePrecision(v int) GlobalOption {
   327  	return &globalOption{option.New(identNumericDateParsePrecision{}, v)}
   328  }
   329  
   330  // WithPedantic enables pedantic mode for parsing JWTs. Currently this only
   331  // applies to checking for the correct `typ` and/or `cty` when necessary.
   332  func WithPedantic(v bool) ParseOption {
   333  	return &parseOption{option.New(identPedantic{}, v)}
   334  }
   335  
   336  // WithSignOption provides an escape hatch for cases where extra options to
   337  // `jws.Sign()` must be specified when usng `jwt.Sign()`. Normally you do not
   338  // need to use this.
   339  func WithSignOption(v jws.SignOption) SignOption {
   340  	return &signOption{option.New(identSignOption{}, v)}
   341  }
   342  
   343  // WithToken specifies the token instance where the result JWT is stored
   344  // when parsing JWT tokensthat is used when parsing
   345  func WithToken(v Token) ParseOption {
   346  	return &parseOption{option.New(identToken{}, v)}
   347  }
   348  
   349  // WithTruncation speficies the amount that should be used when
   350  // truncating time values used during time-based validation routines.
   351  // By default time values are truncated down to second accuracy.
   352  // If you want to use sub-second accuracy, you will need to set
   353  // this value to 0.
   354  func WithTruncation(v time.Duration) ValidateOption {
   355  	return &validateOption{option.New(identTruncation{}, v)}
   356  }
   357  
   358  // WithValidate is passed to `Parse()` method to denote that the
   359  // validation of the JWT token should be performed (or not) after
   360  // a successful parsing of the incoming payload.
   361  //
   362  // This option is enabled by default.
   363  //
   364  // If you would like disable validation,
   365  // you must use `jwt.WithValidate(false)` or use `jwt.ParseInsecure()`
   366  func WithValidate(v bool) ParseOption {
   367  	return &parseOption{option.New(identValidate{}, v)}
   368  }
   369  
   370  // WithValidator validates the token with the given Validator.
   371  //
   372  // For example, in order to validate tokens that are only valid during August, you would write
   373  //
   374  //	validator := jwt.ValidatorFunc(func(_ context.Context, t jwt.Token) error {
   375  //		if time.Now().Month() != 8 {
   376  //			return fmt.Errorf(`tokens are only valid during August!`)
   377  //		}
   378  //		return nil
   379  //	})
   380  //	err := jwt.Validate(token, jwt.WithValidator(validator))
   381  func WithValidator(v Validator) ValidateOption {
   382  	return &validateOption{option.New(identValidator{}, v)}
   383  }
   384  
   385  // WithVerify is passed to `Parse()` method to denote that the
   386  // signature verification should be performed after a successful
   387  // deserialization of the incoming payload.
   388  //
   389  // This option is enabled by default.
   390  //
   391  // If you do not provide any verification key sources, `jwt.Parse()`
   392  // would return an error.
   393  //
   394  // If you would like to only parse the JWT payload and not verify it,
   395  // you must use `jwt.WithVerify(false)` or use `jwt.ParseInsecure()`
   396  func WithVerify(v bool) ParseOption {
   397  	return &parseOption{option.New(identVerify{}, v)}
   398  }