#jwt #oauth2 #oidc #tower-middleware #authorizer #resources #claim

tower-oauth2-resource-server

Tower middleware that provides JWT authorization against an OpenID Connect (OIDC) Provider

10 releases

new 0.1.9 Feb 14, 2025
0.1.8 Jan 27, 2025
0.1.5 Dec 10, 2024
0.1.4 Nov 25, 2024

#346 in Authentication

Download history 283/week @ 2024-11-03 49/week @ 2024-11-10 148/week @ 2024-11-17 177/week @ 2024-11-24 45/week @ 2024-12-01 151/week @ 2024-12-08 11/week @ 2024-12-15 159/week @ 2024-12-29 72/week @ 2025-01-05 137/week @ 2025-01-12 44/week @ 2025-01-19 124/week @ 2025-01-26 13/week @ 2025-02-02 97/week @ 2025-02-09

286 downloads per month

MIT license

54KB
1.5K SLoC

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.

Dependencies

~7–22MB
~335K SLoC