Skip to content

janekolszak/gin-hydra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gin-hydra

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

Install

go get github.com/janekolszak/gin-hydra

Example

import (
    "github.com/gin-gonic/gin"
    "github.com/ory-am/hydra/firewall"
  	hydra "github.com/ory-am/hydra/sdk"

    gh "go get github.com/janekolszak/gin-hydra"

)

func handler(c *gin.Context) {
	ctx := c.Get("hydra").(*firewall.Context)
	// Now you can access ctx.Subject etc.
}

func main(){
	// Initialize Hydra and gin-hydra
	hc, err := hydra.Connect(
		hydra.ClientID("..."),
		hydra.ClientSecret("..."),
		hydra.ClusterURL("..."),
	)

	if err != nil {
		panic(err)
	}

	gh.Init(hc)

	// Use the middleware
 	router := gin.Default()
	router.GET("/", gh.ScopesRequired("scope1", "scope2"), handler)
	router.Run()
}

About

Hydra middleware for Gin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages