tower-oauth2-resource-server

Crates.iotower-oauth2-resource-server
lib.rstower-oauth2-resource-server
version
sourcesrc
created_at2024-11-07 20:44:52.713795
updated_at2024-12-10 16:36:40.755548
descriptionTower middleware that provides JWT authorization against an OpenID Connect (OIDC) Provider
homepagehttps://github.com/Dunklas/tower-oauth2-resource-server
repositoryhttps://github.com/Dunklas/tower-oauth2-resource-server
max_upload_size
id1440162
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Dunklas (Dunklas)

documentation

README

tower-oauth2-resource-server

Tower middleware that provides JWT authorization against an OpenID Connect (OIDC) Provider. This is useful when an application has delegated authentication and/or authorization to an external authorization service (e.g. Auth0, Microsoft Entra, etc).

Main inspiration for this middleware (both in naming and functionality) is Spring Security OAuth 2.0 Resource Server.

The middleware will attempt to process each request by:

  • Read JWT from Authorization header (with Bearer prefix)
  • Validate the JWT's signature against a public key obtained from jwks_url
  • Validate iss, exp, aud and possibly nbf scopes of the JWT

If validation fails, a HTTP 401 is returned. Otherwise next service in the middleware chain will be called. Claims of the JWT are made available as a Request extension. This enables you to write further application logic based on the claims, e.g. rejecting request that lack a certain scope.

Configuration

See docs for OAuth2ResourceServerBuilder.

Example usage

Check the examples.

Commit count: 44

cargo fmt