parser_option.go raw

   1  package jwt
   2  
   3  // ParserOption is used to implement functional-style options that modify the behavior of the parser. To add
   4  // new options, just create a function (ideally beginning with With or Without) that returns an anonymous function that
   5  // takes a *Parser type as input and manipulates its configuration accordingly.
   6  type ParserOption func(*Parser)
   7  
   8  // WithValidMethods is an option to supply algorithm methods that the parser will check. Only those methods will be considered valid.
   9  // It is heavily encouraged to use this option in order to prevent attacks such as https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/.
  10  func WithValidMethods(methods []string) ParserOption {
  11  	return func(p *Parser) {
  12  		p.ValidMethods = methods
  13  	}
  14  }
  15  
  16  // WithJSONNumber is an option to configure the underlying JSON parser with UseNumber
  17  func WithJSONNumber() ParserOption {
  18  	return func(p *Parser) {
  19  		p.UseJSONNumber = true
  20  	}
  21  }
  22  
  23  // WithoutClaimsValidation is an option to disable claims validation. This option should only be used if you exactly know
  24  // what you are doing.
  25  func WithoutClaimsValidation() ParserOption {
  26  	return func(p *Parser) {
  27  		p.SkipClaimsValidation = true
  28  	}
  29  }
  30