https://github.com/lestrrat-go/echo-middleware-jwx
Echo (labstack/echo) middleware for using github.com/lestrrat-go/jwx
https://github.com/lestrrat-go/echo-middleware-jwx
Last synced: about 2 months ago
JSON representation
Echo (labstack/echo) middleware for using github.com/lestrrat-go/jwx
- Host: GitHub
- URL: https://github.com/lestrrat-go/echo-middleware-jwx
- Owner: lestrrat-go
- License: mit
- Created: 2021-05-24T11:47:55.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-21T15:15:15.000Z (over 1 year ago)
- Last Synced: 2024-06-20T05:08:17.459Z (about 1 year ago)
- Language: Go
- Size: 15.6 KB
- Stars: 9
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# echo-middleware-jwx
JWT middleware for github.com/labstack/echo using github.com/lestrrat-go/jwx
WARNING: As of this writing, this is a proof of concept. The author does not usually develop web applications using github.com/labstack/echo. This library is provided in hopes that it will help you, but there may be bugs lurking. Contributions are welcome.
# DESCRIPTION
This is pretty much a straight port of `"github.com/labstack/echo/v4/middleware".JWT`.
The difference is this module uses `github.com/lestrrat-go/jwx` instead of `github.com/dgrijalva/jwt-go` to handle the JWT tokens.Please note that there _are_ a few differences. You are advised to read the code before using it.
# SYNOPSIS
```go
func main() {
const googleCerts = `https://www.googleapis.com/oauth2/v3/certs`ctx, cancel := context.WithCancel(context.Background())
defer cancel()e := echo.New()
ar := jwk.NewAutoRefresh(ctx)
ar.Configure(`https://www.googleapis.com/oauth2/v3/certs`, jwk.WithMinRefreshInterval(15*time.Minute))
ks, err := ar.Refresh(ctx, googleCerts)
if err != nil {
panic(fmt.Sprintf("failed to refresh google JWKS: %s\n", err))
}e.Use(jwx.JWX(ks))
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})e.Start(":8000")
}
```