gatekeeper

package module
v0.0.0-...-82e891a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2016 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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

Documentation

Overview

Package gatekeeper is a multi-framework Hydra middleware library for golang It currently support gin, echo, and goa.

Directories

Path Synopsis
Package gatekeeper is a multi-framework Hydra middleware library for golang This package implements support for the Echo web framework
Package gatekeeper is a multi-framework Hydra middleware library for golang This package implements support for the Echo web framework
Package gatekeeper is a multi-framework Hydra middleware library for golang This package implements support for the Gin web framework
Package gatekeeper is a multi-framework Hydra middleware library for golang This package implements support for the Gin web framework
Package gatekeeper is a multi-framework Hydra middleware library for golang This package implements support for the Goa web framework
Package gatekeeper is a multi-framework Hydra middleware library for golang This package implements support for the Goa web framework

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL