access

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: GPL-3.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package access signs users in through an OpenID Connect provider and keeps their sessions in encrypted cookies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Access

type Access struct {
	// contains filtered or unexported fields
}

Access discovers the provider and handles sign-in, sign-out, and sessions.

func New

func New(ctx context.Context, opts Options) (*Access, error)

New discovers the provider at opts.Issuer and returns access control that uses it.

func (*Access) Callback

func (a *Access) Callback(c *gin.Context)

Callback completes sign-in and starts a session for an allowed user.

func (*Access) CurrentUser

func (a *Access) CurrentUser(c *gin.Context) (*User, bool)

CurrentUser returns the signed-in user for a request. A missing, expired, or invalid session counts as no user.

func (*Access) Login

func (a *Access) Login(c *gin.Context)

Login sends the browser to the provider to start sign-in.

func (*Access) Logout

func (a *Access) Logout(c *gin.Context)

Logout clears the session and sends the user back to sign-in.

type Options

type Options struct {
	BaseURL       string
	Issuer        string
	ClientID      string
	ClientSecret  string
	CookieKey     []byte
	AdminGroup    string
	CustomerGroup string
	GroupsClaim   string
}

Options holds the settings the access component needs.

func (*Options) Validate

func (o *Options) Validate() error

Validate reports a missing or invalid setting and applies the group and claim defaults.

type Role

type Role string

Role is a signed-in user's access level.

const (
	// Admin identifies a user in the configured admin group.
	Admin Role = "admin"
	// Customer identifies a user in the configured customer group.
	Customer Role = "customer"
)

type User

type User struct {
	Email   string
	Role    Role
	Expires time.Time
}

User is the current user of the web app.

Jump to

Keyboard shortcuts

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