auth

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package auth implements OIDC multi-provider authentication and session management

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

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

Auth is the auth service it manages OIDC authentication and sessions

func New

func New(cfg Config, i18n *i18n.I18n, rd *redis.Client, logger *logf.Logger) (*Auth, error)

New creates an Auth service with configured OIDC providers

func (*Auth) DestroySession

func (a *Auth) DestroySession(r *fastglue.Request) error

DestroySession destroys session

func (*Auth) ExchangeOIDCToken

func (a *Auth) ExchangeOIDCToken(ctx context.Context, providerID int, code string) (string, OIDCclaim, error)

ExchangeOIDCToken takes an OIDC authorization code, validates it, and returns an OIDC token for subsequent auth.

func (*Auth) GetSessionValue

func (a *Auth) GetSessionValue(r *fastglue.Request, key string) (any, error)

GetSessionValue returns the value for the given key from the session.

func (*Auth) LoginURL

func (a *Auth) LoginURL(providerID int, state string) (string, error)

LoginURL returns the login URL for the given provider.

func (*Auth) Reload

func (a *Auth) Reload(cfg Config) error

Reload reloads the auth configuration.

func (*Auth) SaveSession

func (a *Auth) SaveSession(user amodels.User, r *fastglue.Request) error

SaveSession creates and sets a session (post successful login/auth).

func (*Auth) SetCSRFCookie

func (a *Auth) SetCSRFCookie(r *fastglue.Request) error

SetCSRFCookie sets the CSRF token in the response cookie if not already set.

func (*Auth) SetSessionValues

func (a *Auth) SetSessionValues(r *fastglue.Request, values map[string]interface{}) error

SetSessionValues sets passed values in the session.

func (*Auth) TestProvider

func (a *Auth) TestProvider(url string) error

TestProvider tests the OIDC provider url by doing a discovery on it.

func (*Auth) ValidateSession

func (a *Auth) ValidateSession(r *fastglue.Request) (models.User, error)

ValidateSession validates the session and returns the user.

type Config

type Config struct {
	Providers     []Provider
	SecureCookies bool
}

Config holds OIDC providers and cookies security settings

type OIDCclaim

type OIDCclaim struct {
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	Sub           string `json:"sub"`
	Picture       string `json:"picture"`
}

OIDCclaim holds OIDC token claims data

type Provider

type Provider struct {
	ID           int
	Provider     string
	ProviderURL  string
	RedirectURL  string
	ClientID     string
	ClientSecret string
}

Provider defines an OIDC provider configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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