Documentation
¶
Index ¶
- func AddProvider(check func(*types.AuthCheckingContext) *types.AuthenticatedUser)
- func AuthFromHttpReq(req *http.Request, cfg *types.Config) *types.AuthenticatedUser
- func UserFromSystem(cfg *authpublic.Config, username string) *authpublic.AuthenticatedUser
- func UserGuest(cfg *authpublic.Config) *authpublic.AuthenticatedUser
- type AuthShimContext
- func (ctx *AuthShimContext) AddProvider(check func(*authpublic.AuthCheckingContext) *authpublic.AuthenticatedUser)
- func (ctx *AuthShimContext) AuthFromHeaders(headers http.Header) *authpublic.AuthenticatedUser
- func (ctx *AuthShimContext) AuthFromHeadersWithError(headers http.Header) (*authpublic.AuthenticatedUser, error)
- func (ctx *AuthShimContext) AuthFromHttpReq(req *http.Request) *authpublic.AuthenticatedUser
- func (ctx *AuthShimContext) AuthFromHttpReqWithError(req *http.Request) (*authpublic.AuthenticatedUser, error)
- func (ctx *AuthShimContext) ClearProviders()
- func (ctx *AuthShimContext) DeleteUserSession(provider string, sid string)
- func (ctx *AuthShimContext) GetProviders() []func(*authpublic.AuthCheckingContext) *authpublic.AuthenticatedUser
- func (ctx *AuthShimContext) GetUserSession(provider string, sid string) *sessions.UserSession
- func (ctx *AuthShimContext) InsertProvider(index int, ...)
- func (ctx *AuthShimContext) OnAuthenticated(fn EnrichUserFunc)
- func (ctx *AuthShimContext) RegisterUserSession(provider string, sid string, username string, usergroup ...string)
- func (ctx *AuthShimContext) RemoveProviderByIndex(index int) error
- func (ctx *AuthShimContext) Shutdown() error
- func (ctx *AuthShimContext) UserFromSystem(username string) *authpublic.AuthenticatedUser
- func (ctx *AuthShimContext) UserGuest() *authpublic.AuthenticatedUser
- type EnrichUserFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddProvider ¶
func AddProvider(check func(*types.AuthCheckingContext) *types.AuthenticatedUser)
AddProvider adds a provider to the global auth chain. DEPRECATED: Use AuthShimContext.AddProvider instead for per-context chains. This function is kept for backward compatibility but modifies a global chain that is shared across all contexts, which may cause unexpected behavior.
func AuthFromHttpReq ¶
func UserFromSystem ¶
func UserFromSystem(cfg *authpublic.Config, username string) *authpublic.AuthenticatedUser
func UserGuest ¶
func UserGuest(cfg *authpublic.Config) *authpublic.AuthenticatedUser
Types ¶
type AuthShimContext ¶
type AuthShimContext struct {
Config *authpublic.Config
Sessions *sessions.SessionStorage
// contains filtered or unexported fields
}
AuthShimContext contains the configuration and session storage for authentication. This is the main entry point for users of the library.
IMPORTANT: The Config should not be mutated after AuthShimContext creation. Mutating the config after context creation can lead to inconsistent behavior and is not thread-safe. If you need to change configuration, create a new AuthShimContext with the updated config.
CLEANUP: You MUST call Shutdown() when the AuthShimContext is no longer needed to prevent resource leaks (goroutines, file handles, etc.). This is especially important in long-running applications. Consider using defer or ensuring Shutdown is called in your application's cleanup logic (e.g., signal handlers).
func NewAuthShimContext ¶
func NewAuthShimContext(cfg *authpublic.Config, sessionStorage *sessions.SessionStorage) (*AuthShimContext, error)
NewAuthShimContext creates a new AuthShimContext with the provided config and session storage. It loads existing sessions from disk. It validates the configuration and returns an error if validation fails. Callers must explicitly provide a SessionStorage implementation.
func (*AuthShimContext) AddProvider ¶
func (ctx *AuthShimContext) AddProvider(check func(*authpublic.AuthCheckingContext) *authpublic.AuthenticatedUser)
AddProvider adds a custom authentication provider to this context's auth chain. This allows users to extend the authentication chain with custom providers. The provider is added to this specific context instance, not a global chain.
func (*AuthShimContext) AuthFromHeaders ¶
func (ctx *AuthShimContext) AuthFromHeaders(headers http.Header) *authpublic.AuthenticatedUser
AuthFromHeaders authenticates a user from HTTP headers only. Useful when you have headers without a full request (e.g. gRPC metadata, proxies). Cookie-based providers work if a Cookie header is present. If no user is authenticated, it returns a guest user.
func (*AuthShimContext) AuthFromHeadersWithError ¶
func (ctx *AuthShimContext) AuthFromHeadersWithError(headers http.Header) (*authpublic.AuthenticatedUser, error)
AuthFromHeadersWithError authenticates a user from HTTP headers only. If no user is authenticated, it returns a guest user and nil error.
func (*AuthShimContext) AuthFromHttpReq ¶
func (ctx *AuthShimContext) AuthFromHttpReq(req *http.Request) *authpublic.AuthenticatedUser
AuthFromHttpReq authenticates a user from an HTTP request. It runs through the authentication chain and returns an AuthenticatedUser. If no user is authenticated, it returns a guest user. For error handling, use AuthFromHttpReqWithError instead.
func (*AuthShimContext) AuthFromHttpReqWithError ¶
func (ctx *AuthShimContext) AuthFromHttpReqWithError(req *http.Request) (*authpublic.AuthenticatedUser, error)
AuthFromHttpReqWithError authenticates a user from an HTTP request. It runs through the authentication chain and returns an AuthenticatedUser and any error encountered. If no user is authenticated, it returns a guest user and nil error.
func (*AuthShimContext) ClearProviders ¶
func (ctx *AuthShimContext) ClearProviders()
ClearProviders removes all providers from the auth chain.
func (*AuthShimContext) DeleteUserSession ¶
func (ctx *AuthShimContext) DeleteUserSession(provider string, sid string)
DeleteUserSession deletes a user session
func (*AuthShimContext) GetProviders ¶
func (ctx *AuthShimContext) GetProviders() []func(*authpublic.AuthCheckingContext) *authpublic.AuthenticatedUser
GetProviders returns a copy of the current provider chain. Useful for debugging or inspection.
func (*AuthShimContext) GetUserSession ¶
func (ctx *AuthShimContext) GetUserSession(provider string, sid string) *sessions.UserSession
GetUserSession retrieves a user session
func (*AuthShimContext) InsertProvider ¶
func (ctx *AuthShimContext) InsertProvider(index int, check func(*authpublic.AuthCheckingContext) *authpublic.AuthenticatedUser)
InsertProvider inserts a provider at a specific index in the auth chain. If index is out of bounds, the provider is appended to the end.
func (*AuthShimContext) OnAuthenticated ¶
func (ctx *AuthShimContext) OnAuthenticated(fn EnrichUserFunc)
OnAuthenticated registers a post-auth hook called after BuildUserAcls, including for guest users. Multiple hooks may be registered; they run in registration order.
func (*AuthShimContext) RegisterUserSession ¶
func (ctx *AuthShimContext) RegisterUserSession(provider string, sid string, username string, usergroup ...string)
RegisterUserSession registers a new user session
func (*AuthShimContext) RemoveProviderByIndex ¶
func (ctx *AuthShimContext) RemoveProviderByIndex(index int) error
RemoveProviderByIndex removes a provider from the auth chain by index. Returns an error if the index is out of bounds.
func (*AuthShimContext) Shutdown ¶
func (ctx *AuthShimContext) Shutdown() error
Shutdown performs cleanup operations, including: - Final session storage write - Stopping background goroutines This MUST be called when the context is no longer needed to prevent resource leaks. It is safe to call Shutdown multiple times; subsequent calls are no-ops.
func (*AuthShimContext) UserFromSystem ¶
func (ctx *AuthShimContext) UserFromSystem(username string) *authpublic.AuthenticatedUser
UserFromSystem returns a system user with the given username
func (*AuthShimContext) UserGuest ¶
func (ctx *AuthShimContext) UserGuest() *authpublic.AuthenticatedUser
UserGuest returns a guest user with appropriate ACLs
type EnrichUserFunc ¶
type EnrichUserFunc func(user *authpublic.AuthenticatedUser, cfg *authpublic.Config)
EnrichUserFunc is called after authentication and BuildUserAcls (including for guest users).