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

oidclogin

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: LGPL-2.1 Imports: 10 Imported by: 0

README

oidclogin

OpenID Connect Login SDK written in Go for Gin.

The following environment variables are expected to be set:

OIDC_CLIENT_ID=<client id>
OIDC_CLIENT_SECRET=<client secret>
OIDC_ISSUE=<issuer url>

If these env vars are not present, then depending on configuration, stubs will be used for the endpoints or the program will crash

Usage

package main

import (
	"os"

	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/memstore"
	"github.com/gin-gonic/gin"
	"github.com/janishutz/oidclogin"
)

func main() {
	r := gin.Default()

	// TODO: Better secret
	store := memstore.NewStore([]byte("secret"))
	r.Use(sessions.Sessions("jhid", store))

	oidclogin.Configure(r, os.Getenv("APP_BASE_URL"), "/account", false)
	r.LoadHTMLGlob("public/*")

	r.GET("/account", oidclogin.EnsureLogin(false), func(ctx *gin.Context) {
		ctx.HTML(200, "main.tmpl", gin.H{})
	})

	r.Run()
}

This example further needs the environment variable APP_BASE_URL set to something like https://app.example.org. Further, you should create a template file called main.tmpl and also copy over the template files in the public directory here and edit them.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configure

func Configure(r *gin.Engine, app_url string, default_redirect string, stubs_on_unconfigured bool, check_middleware func(c *gin.Context), production bool)

Configure and set up the login SDK The check middleware may be nil, in which case a default is used. Otherwise should be a valid gin middleware, calling c.Next() if okay to proceed.

func ConfigureFull added in v1.3.1

func ConfigureFull(
	r *gin.Engine,
	app_url string,
	default_redirect string,
	user_function UserFunc,
	stubs_on_unconfigured bool,
	check_middleware func(c *gin.Context),
	production bool,
)

Wraps the normal configure function, but also gives you access to change the User Function, which is called upon login. It is used to create or update a user. The check middleware may be nil, in which case a default is used. Otherwise should be a valid gin middleware, calling c.Next() if okay to proceed.

func EnsureLogin

func EnsureLogin(redirectFail bool) func(c *gin.Context)

Ensure that a user is currently logged in. If redirectFail is set, then if not, the user is redirected.

func ErrorHandler added in v0.2.0

func ErrorHandler() gin.HandlerFunc

Types

type UserFunc added in v1.3.0

type UserFunc func(userid string, name string, email string, c *gin.Context)

Jump to

Keyboard shortcuts

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