session

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 17 Imported by: 0

README

Session

Overview

The Session repository is designed to handle the management of user sessions, including authorization, storage, and expiration. It provides a framework for manageing sessions across different databases and supports multiple login types.

Features

  • Session Management: Efficient handling of user session creation, storage, and expiration.
  • Database Support: Seamless integration with multiple databases.
    • PostgreSQL
    • Google Cloud Spanner
  • Login Types: Supports multiple authentication methods.
    • Azure OIDC
    • Username/Password
Created and maintained by the CCC team.

Documentation

Overview

Package session provides session handlers for various authentication implementations. Curretnly supported are: 1) Azure OIDC Authorization Code Flow with PKCE 2) Preauth: Allows you to implement your own authentication, but still use session handlers 3) Username/Password: Implements user storage and password management

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseSessionOption added in v0.6.0

type BaseSessionOption func(*basesession.BaseSession)

BaseSessionOption defines a function signature for setting session options.

func WithLogHandler added in v0.6.0

func WithLogHandler(l LogHandler) BaseSessionOption

WithLogHandler sets the LogHandler. (default: httpio.Log)

func WithSessionTimeout added in v0.6.0

func WithSessionTimeout(d time.Duration) BaseSessionOption

WithSessionTimeout sets the session timeout. (default: 10m)

type CookieOption added in v0.5.8

type CookieOption func(*cookie.CookieClient)

CookieOption defines a function signature for setting cookie client options.

func WithCookieDomain added in v0.5.8

func WithCookieDomain(domain string) CookieOption

WithCookieDomain sets the domain for the session cookie.

func WithCookieName added in v0.5.8

func WithCookieName(name string) CookieOption

WithCookieName sets the cookie name for the session cookie.

type DisabledUserRoleManager added in v0.6.0

type DisabledUserRoleManager struct{}

DisabledUserRoleManager implements the UserManager interface but disables all user management functions.

func DisableUserRoleManagement added in v0.6.0

func DisableUserRoleManagement() DisabledUserRoleManager

DisableUserRoleManagement returns a DisabledUserRoleManager instance.

func (DisabledUserRoleManager) AddUserRoles added in v0.6.0

AddUserRoles does nothing and returns nil.

func (DisabledUserRoleManager) DeleteUserRoles added in v0.6.0

DeleteUserRoles does nothing and returns nil.

func (DisabledUserRoleManager) Domains added in v0.6.0

Domains returns a default global domain.

func (DisabledUserRoleManager) RoleExists added in v0.6.0

RoleExists always returns true, indicating that any role exists.

func (DisabledUserRoleManager) UserRoles added in v0.6.0

UserRoles always returns an empty RoleCollection.

type LogHandler

type LogHandler = basesession.LogHandler

LogHandler defines the handler signature required for handling logs.

type OIDCAzure added in v0.6.0

type OIDCAzure struct {
	*basesession.BaseSession
	// contains filtered or unexported fields
}

OIDCAzure implements the OIDCAzureHandlers interface for handling OIDC authentication with Azure.

func NewOIDCAzure

func NewOIDCAzure(
	storage sessionstorage.OIDCAzure, userRoleManager UserRoleManager,
	secureCookie *securecookie.SecureCookie,
	issuerURL, clientID, clientSecret, redirectURL string,
	options ...OIDCAzureOption,
) *OIDCAzure

NewOIDCAzure creates a new OIDCAzure.

func (*OIDCAzure) CallbackOIDC added in v0.6.0

func (o *OIDCAzure) CallbackOIDC() http.HandlerFunc

CallbackOIDC is the handler for the callback from the OIDC auth provider

func (*OIDCAzure) FrontChannelLogout added in v0.6.0

func (o *OIDCAzure) FrontChannelLogout() http.HandlerFunc

FrontChannelLogout is a handler which destroys the current session for a logout request initiated by the OIDC provider

func (*OIDCAzure) Login added in v0.6.0

func (o *OIDCAzure) Login() http.HandlerFunc

Login initiates the OIDC login flow by redirecting the user to the authorization URL.

type OIDCAzureHandlers

type OIDCAzureHandlers interface {
	CallbackOIDC() http.HandlerFunc
	FrontChannelLogout() http.HandlerFunc
	Login() http.HandlerFunc
	basesession.Handlers
}

OIDCAzureHandlers defines the interface for OIDC Azure session handlers.

type OIDCAzureOption added in v0.5.8

type OIDCAzureOption interface {
	// contains filtered or unexported methods
}

OIDCAzureOption defines the interface for functional options used when creating a new OIDCAzure.

type OIDCOption added in v0.6.0

type OIDCOption func(*azureoidc.OIDC)

OIDCOption defines a function signature for setting OIDC options.

func WithLoginURL added in v0.6.0

func WithLoginURL(l string) OIDCOption

WithLoginURL sets the LoginURL for the SPA. (default: /login)

type Preauth added in v0.6.0

type Preauth struct {
	*basesession.BaseSession
	// contains filtered or unexported fields
}

Preauth handles session management for pre-authentication scenarios.

func NewPreauth added in v0.4.0

func NewPreauth(storage sessionstorage.Preauth, secureCookie *securecookie.SecureCookie, options ...PreauthOption) *Preauth

NewPreauth creates a new PreauthSession instance.

func (*Preauth) NewSession added in v0.6.0

func (p *Preauth) NewSession(ctx context.Context, w http.ResponseWriter, r *http.Request, username string) (ccc.UUID, error)

NewSession creates a new session for a pre-authenticated user.

type PreauthHandlers added in v0.6.0

type PreauthHandlers interface {
	basesession.Handlers
	NewSession(ctx context.Context, w http.ResponseWriter, r *http.Request, username string) (ccc.UUID, error)
}

PreauthHandlers defines the interface for pre-authentication session handlers.

type PreauthOption added in v0.6.0

type PreauthOption interface {
	// contains filtered or unexported methods
}

PreauthOption defines the functional option type for configuring PreauthSession.

type UserRoleManager added in v0.6.0

type UserRoleManager interface {
	Domains(ctx context.Context) ([]accesstypes.Domain, error)
	UserRoles(ctx context.Context, user accesstypes.User, domains ...accesstypes.Domain) (accesstypes.RoleCollection, error)
	RoleExists(ctx context.Context, domain accesstypes.Domain, role accesstypes.Role) bool
	AddUserRoles(ctx context.Context, domain accesstypes.Domain, user accesstypes.User, roles ...accesstypes.Role) error
	DeleteUserRoles(ctx context.Context, domain accesstypes.Domain, user accesstypes.User, roles ...accesstypes.Role) error
}

UserRoleManager defines an interface for managing user roles.

Directories

Path Synopsis
internal
azureoidc
Package azureoidc implements a client for Azure OIDC Authorization Code Flow with PKCE (Proof Key for Code Exchange).
Package azureoidc implements a client for Azure OIDC Authorization Code Flow with PKCE (Proof Key for Code Exchange).
azureoidc/loader
Package loader contains interfaces for safely accessing an OIDC Provider.
Package loader contains interfaces for safely accessing an OIDC Provider.
basesession
Package basesession implements the session management for the application.
Package basesession implements the session management for the application.
cookie
Package cookie implements all cookie handling for the session package
Package cookie implements all cookie handling for the session package
types
Package types defines common types and constants used across the session package.
Package types defines common types and constants used across the session package.
util
Package util is used for general utility function such as generic sorting/filtering and more.
Package util is used for general utility function such as generic sorting/filtering and more.
Package mock is used to generate mock files for testing.
Package mock is used to generate mock files for testing.
mock_azureoidc
Package mock_azureoidc is a generated GoMock package.
Package mock_azureoidc is a generated GoMock package.
mock_azureoidc/mock_loader
Package mock_loader is a generated GoMock package.
Package mock_loader is a generated GoMock package.
mock_basesession
Package mock_basesession is a generated GoMock package.
Package mock_basesession is a generated GoMock package.
mock_cookie
Package mock_cookie is a generated GoMock package.
Package mock_cookie is a generated GoMock package.
mock_postgres
Package mock_postgres is a generated GoMock package.
Package mock_postgres is a generated GoMock package.
mock_session
Package mock_session is a generated GoMock package.
Package mock_session is a generated GoMock package.
Package sessioninfo handles session information.
Package sessioninfo handles session information.
Package sessionstorage implements database storage for session data.
Package sessionstorage implements database storage for session data.
internal/dbtype
Package dbtype contains types used by the database driver packages for session storage.
Package dbtype contains types used by the database driver packages for session storage.
internal/postgres
Package postgres implements the session storage driver for PostgreSQL.
Package postgres implements the session storage driver for PostgreSQL.
internal/spanner
Package spanner provides the session storage driver for Spanner.
Package spanner provides the session storage driver for Spanner.
mock/mock_sessionstorage
Package mock_sessionstorage is a generated GoMock package.
Package mock_sessionstorage is a generated GoMock package.

Jump to

Keyboard shortcuts

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