gin_oidc

package module
v0.0.0-...-1ff0c6f Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2019 License: MIT Imports: 12 Imported by: 0

README

gin-oidc

gin middleware - an OIDC client for a relying party web server

example usage

  //middleware params
 	initParams := gin_oidc.InitParams{
 		Router:       router,
 		ClientId:     "xx-xxx-xxx",
 		ClientSecret: "xx-xxx-xxx",
 		Issuer:       "https://accounts.google.com/", //add '.well-known/openid-configuration' to see it's a good link
 		ClientUrl:    "http://example.domain/", //your website's url
 		Scopes:       ["openid"],
 		ErrorHandler: func(c *gin.Context) {
 			//gin_oidc pushes a new error before any "ErrorHandler" invocation
 			message := c.Errors.Last().Error()
 			//redirect to ErrorEndpoint with error message
 			redirectToErrorPage(c, "http://example2.domain/error", message)
 			//when "ErrorHandler" ends "c.Abort()" is invoked - no further handlers will be invoked
 		},
 		PostLogoutUrl: "http://example2.domain/",
 	}
  
 	//protect all endpoint below this line
 	router.Use(gin_oidc.Init(initParams))
  //or protect a single endpoint
  protectMiddleware := gin_oidc.Init(initParams)
  router.GET("/protectedEndpoint", protectMiddleware, protectedEndpointHandler)
  

If you have any questions feel free to open an issue.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(i InitParams) gin.HandlerFunc

Init function initializes the oidc middleware

func RandomString

func RandomString(n int) string

Types

type InitParams

type InitParams struct {
	Router        *gin.Engine     // Router has the gin engine3
	ClientId      string          // ClientId contains the client ID
	ClientSecret  string          // ClientSecret contains the client secret
	Issuer        url.URL         // Issuer contains the Issuer URL that signs the JWT token
	ClientUrl     url.URL         // ClientURL describes the base url for the application
	Scopes        []string        // Scopes describe the defined OAuth scopes that get requested
	ErrorHandler  gin.HandlerFunc // ErrorHandler describes the function that handles the errors
	PostLogoutUrl url.URL         // PostLogoutUrl describes the URL that the user is redirected to after he logs out
}

Jump to

Keyboard shortcuts

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