Hydra middleware for golang web frameworks. Inspired by gin-hydra, it current has support for gin, echo, and goa. More framework support is planned.
go get -u github.com/otraore/gatekeeper
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()
}
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"))
}
Example coming soon
MIT