Skip to content

otraore/gatekeeper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gatekeeper

GoDoc Go Report Card License

Hydra middleware for golang web frameworks. Inspired by gin-hydra, it current has support for gin, echo, and goa. More framework support is planned.

Install

go get -u github.com/otraore/gatekeeper

Gin

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

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

Releases

No releases published

Packages

No packages published

Languages