Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

A middleware for validating JWT tokens made by an OpenID Connect compliant provider

License

Notifications You must be signed in to change notification settings

oslokommune/go-oidc-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-oidc-middleware

A middleware for validating JWT tokens made by an OpenID Connect compliant provider

How it works

By fetching information from the discovery URL (.well-known) it can validate a JWT token sent with an Authentication header.

Middlewares

General

Relevant middleware function

  • NewAuthenticationMiddleware(discoveryURL url.URL) *jwtmiddleware.JWTMiddleware

Gin

Relevant middleware function

  • NewGinAuthenticationMiddleware(discoveryURL url.URL) *gin.HandlerFunc

Usage

import github.com/oslokommune/go-oidc-middleware/pkg/v1/middleware"

func NewRouter() *gin.Engine {
	router := gin.Default()

	discoveryURL, err := url.Parse("https://auth-provider.url/.well-known/openid-configuration")
	if err != nil {
		panic(err)
	}

	router.Use(middleware.NewGinAuthenticationMiddleware(*discoveryURL))

	return router
}