https://github.com/otraore/gatekeeper
Hydra middleware for golang web frameworks
https://github.com/otraore/gatekeeper
echo gatekeeper gin go goa hydra middleware
Last synced: about 1 year ago
JSON representation
Hydra middleware for golang web frameworks
- Host: GitHub
- URL: https://github.com/otraore/gatekeeper
- Owner: otraore
- License: mit
- Created: 2016-08-26T00:20:29.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-12-16T08:02:43.000Z (over 6 years ago)
- Last Synced: 2025-03-28T03:02:35.487Z (over 1 year ago)
- Topics: echo, gatekeeper, gin, go, goa, hydra, middleware
- Language: Go
- Size: 21.5 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gatekeeper
[](https://godoc.org/github.com/otraore/gatekeeper)
[](https://goreportcard.com/report/github.com/otraore/gatekeeper)

[Hydra](https://github.com/ory-am/hydra) middleware for golang web frameworks. Inspired by [gin-hydra](https://github.com/janekolszak/gin-hydra), it current has support for [gin](https://github.com/gin-gonic/gin), [echo](https://github.com/labstack/echo), and [goa](https://github.com/goadesign/goa). More framework support is planned.
## Install
``` bash
go get -u github.com/otraore/gatekeeper
```
## Gin
``` go
import (
"github.com/gin-gonic/gin"
"github.com/ory-am/hydra/firewall"
hydra "github.com/ory-am/hydra/sdk"
"github.com/otraore/gatekeeper/gin"
)
func handler(c *gin.Context) {
ctx := c.Get("hydra").(*firewall.Context)
// Now you can access ctx.Subject etc.
}
func main(){
// Initialize Hydra
hc, err := hydra.Connect(
hydra.ClientID("..."),
hydra.ClientSecret("..."),
hydra.ClusterURL("..."),
)
if err != nil {
panic(err)
}
// Create a gatekeeper instance for Gin
gk := gatekeeper.New(hc)
r := gin.Default()
r.GET("/protected", gk.ScopesRequired("scope1", "scope2"), handler)
r.Run()
}
```
## Echo
``` go
import (
"github.com/labstack/echo"
"github.com/labstack/echo/engine/standard"
"github.com/ory-am/hydra/firewall"
hydra "github.com/ory-am/hydra/sdk"
"github.com/otraore/gatekeeper/echo"
)
func handler(c echo.Context) {
ctx := c.Get("hydra").(*firewall.Context)
// Now you can access ctx.Subject etc.
}
func main(){
// Initialize Hydra
hc, err := hydra.Connect(
hydra.ClientID("..."),
hydra.ClientSecret("..."),
hydra.ClusterURL("..."),
)
if err != nil {
panic(err)
}
// Create a gatekeeper instance for Echo
gk := gatekeeper.New(hc)
e := echo.Default()
e.GET("/protected", handler, gk.ScopesRequired("scope1", "scope2"),)
e.Run(standard.New(":8080"))
}
```
## Goa
Example coming soon
## License
MIT