Help us shape the future of Go! Take the 2026 Go Developer Survey

ginhydra

package module
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2016 License: MIT Imports: 2 Imported by: 0

README

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()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(hydraClient *hydra.Client)

func ScopesRequired

func ScopesRequired(scopes ...string) gin.HandlerFunc

Types

This section is empty.

Jump to

Keyboard shortcuts

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