Commit Graph

17 Commits

Author SHA1 Message Date
Christian Banse 3a9ee81ba3
Cleanup and documentation of verification functions (#262)
This PR adds further documentation to the validator and does an additional cleanup to make the VerifyXXX functions more managable.
2023-02-09 21:06:03 +01:00
Christian Banse 1ef0fe8cd4 New validation API (#236)
* New Validation API

Some guidelines in designing the new validation API

* Previously, the `Valid` method was placed on the claim, which was always not entirely semantically correct, since the validity is concerning the token, not the claims. Although the validity of the token is based on the processing of the claims (such as `exp`). Therefore, the function `Valid` was removed from the `Claims` interface and the single canonical way to retrieve the validity of the token is to retrieve the `Valid` property of the `Token` struct.
* The previous fact was enhanced by the fact that most claims implementations had additional exported `VerifyXXX` functions, which are now removed
* All validation errors should be comparable with `errors.Is` to determine, why a particular validation has failed
* Developers want to adjust validation options. Popular options include:
  * Leeway when processing exp, nbf, iat
  * Not verifying `iat`, since this is actually just an informational claim. When purely looking at the standard, this should probably the default
  * Verifying `aud` by default, which actually the standard sort of demands. We need to see how strong we want to enforce this
* Developers want to create their own claim types, mostly by embedding one of the existing types such as `RegisteredClaims`.
  * Sometimes there is the need to further tweak the validation of a token by checking the value of a custom claim. Previously, this was possibly by overriding `Valid`. However, this was error-prone, e.g., if the original `Valid` was not called. Therefore, we should provide an easy way for *additional* checks, without by-passing the necessary validations

This leads to the following two major changes:

* The `Claims` interface now represents a set of functions that return the mandatory claims represented in a token, rather than just a `Valid` function. This is also more semantically correct.
* All validation tasks are offloaded to a new (optional) `validator`, which can also be configured with appropriate options. If no custom validator was supplied, a default one is used.

Co-authored-by: Micah Parks <66095735+MicahParks@users.noreply.github.com>
2022-12-09 18:47:09 +01:00
Christian Banse 78a18c0808
Implementing `Is(err) bool` to support Go 1.13 style error checking (#136) 2022-01-19 22:55:19 +01:00
Kevin de Berk 823c014036
Unwrap for ValidationError (#125) 2021-11-15 09:25:32 -05:00
Michael Fridman 2ebb50f957
Adds go module support /v4 (#41)
Additionally, added `staticcheck` for basic static code analysis (#44)

Co-authored-by: Christian Banse <oxisto@aybaze.com>
2021-08-03 15:51:01 +02:00
Kevin Burke e58d3b7548
Remove unreachable code
`go vet` on Go 1.8 errors because this line of code is unreachable. Adds
a check that new code passes go vet, and adds Go 1.7 to travisci.
2016-11-01 09:59:08 -07:00
Dave Grijalva 5fbf45924d errors only have an exposed Inner property if the error was generated by another library 2016-06-15 16:42:50 -07:00
Dave Grijalva 6fd0370e43 Merge branch 'master' of https://github.com/martinlindhe/jwt-go into patch_109 2016-06-07 10:34:06 -07:00
Dave Grijalva 317b82a681 Merge remote-tracking branch 'origin/master' into release_3_0_0 2016-06-06 18:20:35 -07:00
Dave Grijalva 9249eabf87 expose inner error within ValidationError 2016-04-12 17:31:30 -07:00
Dave Grijalva 070a4bdd00 moved request related error int request subpackage 2016-04-08 13:58:29 -07:00
Emanoel Xavier 517905c5bd Adding inner error in the ValidationError type 2015-12-31 07:48:39 -08:00
Martin Lindhe f7288992d2 split ErrInvalidKey into ErrInvalidType and ErrInvalidKey 2015-12-29 22:51:54 +01:00
Jamie Stackhouse 3eddded2f3 Adding additional bits to mask for various validation errors. 2015-07-17 16:40:52 -03:00
Jamie Stackhouse 44718f8a89 Structured Claims object!
Only verify claim if it isn't a default value.

The alternative here would be to use pointers in the Claims structure then we
would know which were nil, or if they were explicitly set to zero in the
claim section

Updated MapClaim implementation to check for existance of keys before
using them.

If they don't exists, validation functions simply return true.
2015-07-17 15:13:59 -03:00
Jamie Stackhouse fa9a0b8c45 Add validation error bit for generic validation error. 2015-07-14 14:31:32 -03:00
Dave Grijalva 3dd0a21a31 move error types and constants out to separate file 2015-04-09 13:20:10 -07:00