hydra

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2016 License: Apache-2.0 Imports: 6 Imported by: 0

README

hydra

Hydra middleware for Echo framework. It uses Hydra's API to extract and validate auth token.

Example

import (
    "github.com/webx-top/echo"
    "github.com/webx-top/echo/engine/standard"
    "github.com/ory-am/hydra/firewall"
    hydraMW "github.com/webx-top/echo/middleware/hydra"
)

func handler(c echo.Context) error {
	ctx := c.Get("hydra").(*firewall.Context) // or hydraMW.GetContext(c)
	// Now you can access ctx.Subject etc.
	return nil
}

func main(){
	// Initialize Hydra
	hc, err := hydraMW.Connect(hydraMW.Options{
		ClientID     : "...",
		ClientSecret : "...",
		ClusterURL   : "",
	})
	if err != nil {
		panic(err)
	}

	// Use the middleware
 	e := echo.New()
	e.Get("/", handler, hydraMW.ScopesRequired(hc, nil, "scope1", "scope2"))
	e.Run(standard.New(":4444"))
}

Jump to

Keyboard shortcuts

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