Commit Graph

6 Commits

Author SHA1 Message Date
Christian Banse 28dc52370e
More consistent way of handling validation errors (#274) 2023-02-21 08:54:35 +01:00
Christian Banse 4e6e1ba2bb More documentation cleanup 2023-02-20 23:16:31 +01:00
Christian Banse 1e16f55059 Inlining application-specific validation 2023-02-19 19:56:30 +01:00
Christian Banse 66e2e01a4f Unexported some functions and types 2023-02-19 16:22:09 +01:00
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