authlier

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 28 Imported by: ? 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.

README

Authlier

Authlier is a composable authentication library for Go applications. It brings passwords, sessions, email verification and recovery, MFA, passkeys, Google authentication, OIDC, and SAML into your Go server through one configurable HTTP handler.

Authlier verifies identities and manages authentication records. Your application keeps control of profiles, roles, permissions, and other product data.

New passwords use Argon2id by default. Applications can select bcrypt when a legacy credential system requires temporary write compatibility; verification continues to recognize both formats for staged migration.

Installation

go get github.com/Rahmannugar/authlier

How it works

  1. Connect one of the official PostgreSQL, MySQL, MongoDB, or Redis adapters.
  2. Enable the authentication methods your application needs.
  3. Mount auth.Handler() in your Go server.
  4. Call auth.ResolveSession(request) from application routes that require an authenticated user.

With a connected pgxpool.Pool, a PostgreSQL setup looks like this:

database, err := postgres.New(pool, postgres.Config{})
if err != nil {
	return err
}
if err := database.Migrate(ctx); err != nil {
	return err
}

auth, err := authlier.New(authlier.Config{
	AppName:  "Acme",
	BaseURL:  "https://server.example.com",
	Database: database,
	EmailAndPassword: authlier.EmailAndPasswordConfig{
		Enabled: true,
	},
})
if err != nil {
	return err
}

http.Handle("/api/auth/", auth.Handler())

The complete Getting started guide builds a working server and explains each part of this setup.

Documentation

  • Basic usage connects a browser client to Authlier's routes.
  • Configuration covers route prefixes, browser origins, session modes, and authentication methods.
  • Bearer tokens covers web, mobile, CLI, and API clients that choose access and refresh tokens.
  • Storage explains the official database adapters and custom storage contracts.
  • Authentication guides begin with email and password, then cover verification, recovery, Google, TOTP, and passkeys.
  • Single sign-on explains the shared OIDC and SAML identity boundary.
  • HTTP routes lists the request and response contract for the configured handler.
  • Security explains secure deployment and the controls that remain the application's responsibility.
  • Architecture describes the internal package boundaries.

Security

Security reports should be submitted privately according to SECURITY.md.

Contributing

See CONTRIBUTING.md to report an issue, propose a change, or open a pull request.

License

Authlier is licensed under the Apache License 2.0.

Documentation

Overview

Package authlier provides configurable authentication for Go applications.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfig = errors.New("invalid Authlier configuration")

Functions

This section is empty.

Types

type AccessSession

type AccessSession struct {
	ID        string
	SubjectID string
	CreatedAt time.Time
	ExpiresAt time.Time
	RevokedAt *time.Time
}

type AccessSessionStore

type AccessSessionStore interface {
	accesstoken.SessionResolver
	CreateSession(ctx context.Context, session AccessSession, refreshToken refreshtoken.Record) error
	ListBySubject(ctx context.Context, subjectID string) ([]AccessSession, error)
	Revoke(ctx context.Context, sessionID string, revokedAt time.Time) error
	RevokeAll(ctx context.Context, subjectID string, revokedAt time.Time) error
}

type Auth

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

func New

func New(config Config) (*Auth, error)

func (*Auth) Handler

func (auth *Auth) Handler() http.Handler

func (*Auth) ResolveSession

func (auth *Auth) ResolveSession(r *http.Request) (Session, error)

type BearerSessionConfig

type BearerSessionConfig struct {
	Issuer               string
	Audience             string
	AccessTokenLifetime  time.Duration
	RefreshTokenLifetime time.Duration
	KeyID                string
	PrivateKey           ed25519.PrivateKey
	PublicKeys           map[string]ed25519.PublicKey
	Leeway               time.Duration
}

type Config

type Config struct {
	AppName           string
	BaseURL           string
	BasePath          string
	Database          Database
	TrustedOrigins    []string
	TrustedProxies    []string
	EmailAndPassword  EmailAndPasswordConfig
	EmailVerification EmailVerificationConfig
	PasswordReset     PasswordResetConfig
	Session           SessionConfig
	TOTP              TOTPConfig
	Passkeys          PasskeyConfig
	Google            GoogleConfig
	OIDC              OIDCConfig
	SAML              SAMLConfig
}

type CookieConfig

type CookieConfig struct {
	Name     string
	Domain   string
	Path     string
	SameSite http.SameSite
}

type Database

type Database interface {
	Migrate(ctx context.Context) error
	Stores() Stores
}

type EmailAndPasswordConfig

type EmailAndPasswordConfig struct {
	Enabled                  bool
	RequireEmailVerification bool
	PasswordHashAlgorithm    password.Algorithm
	ValidatePassword         emailpassword.PasswordValidator
	AttemptGuard             emailpassword.AttemptGuard
	SecurityEvents           emailpassword.SecurityEventSink
}

type EmailPasswordStore

type EmailPasswordStore interface {
	emailpassword.Store
	emailpassword.CredentialStore
}

type EmailVerificationConfig

type EmailVerificationConfig struct {
	Enabled                     bool
	Lifetime                    time.Duration
	VerificationURL             string
	Sender                      emailverification.Sender
	SendOnSignUp                bool
	SendOnSignIn                bool
	AutoSignInAfterVerification bool
	AttemptGuard                emailverification.AttemptGuard
	SecurityEvents              emailverification.SecurityEventSink
}

type GoogleConfig

type GoogleConfig struct {
	Enabled            bool
	ClientID           string
	ClientSecret       string
	RedirectURL        string
	SuccessRedirectURL string
	StateLifetime      time.Duration
	HTTPClient         *http.Client
	Provider           googleoauth.Provider
	SecurityEvents     googleoauth.SecurityEventSink
}

type GoogleStore

type GoogleStore interface {
	googleoauth.Store
	googleoauth.IdentityStore
}

type OIDCConfig

type OIDCConfig struct {
	Enabled            bool
	Connections        oidc.ConnectionSource
	ResolveIdentity    OIDCIdentityResolver
	StateLifetime      time.Duration
	HTTPClient         *http.Client
	SuccessRedirectURL string
	AttemptGuard       oidc.AttemptGuard
	SecurityEvents     oidc.SecurityEventSink
}

type OIDCIdentityResolver

type OIDCIdentityResolver func(context.Context, oidc.Identity) (string, error)

type PasskeyConfig

type PasskeyConfig struct {
	Enabled          bool
	RelyingPartyID   string
	RelyingPartyName string
	Origins          []string
	CeremonyLifetime time.Duration
	AttemptGuard     passkey.AttemptGuard
	SecurityEvents   passkey.SecurityEventSink
}

type PasswordResetConfig

type PasswordResetConfig struct {
	Enabled                bool
	Lifetime               time.Duration
	ResetURL               string
	Sender                 passwordreset.Sender
	KeepSessionsAfterReset bool
	AttemptGuard           passwordreset.AttemptGuard
	SecurityEvents         passwordreset.SecurityEventSink
}

type SAMLConfig

type SAMLConfig struct {
	Enabled            bool
	Connections        saml.ConnectionSource
	ResolveIdentity    SAMLIdentityResolver
	RequestLifetime    time.Duration
	SuccessRedirectURL string
	AttemptGuard       saml.AttemptGuard
	SecurityEvents     saml.SecurityEventSink
}

type SAMLIdentityResolver

type SAMLIdentityResolver func(context.Context, saml.Identity) (string, error)

type Session

type Session struct {
	ID        string
	SubjectID string
	CreatedAt time.Time
	ExpiresAt time.Time
}

type SessionConfig

type SessionConfig struct {
	Mode      SessionMode
	Lifetime  time.Duration
	FreshAge  time.Duration
	Cache     sessiontoken.Cache
	CacheTTL  time.Duration
	Extension *sessiontoken.ExtensionConfig
	Cookie    CookieConfig
	Bearer    BearerSessionConfig
}

type SessionMode

type SessionMode string
const (
	SessionModeCookie SessionMode = "cookie"
	SessionModeBearer SessionMode = "bearer"
)

type Stores

type Stores struct {
	EmailPassword     EmailPasswordStore
	EmailVerification emailverification.Store
	Google            GoogleStore
	OIDC              oidc.Store
	Passkeys          passkey.Store
	PasswordReset     passwordreset.Store
	RefreshTokens     refreshtoken.Store
	SAML              saml.Store
	Sessions          sessiontoken.Store
	TOTP              totp.Store
	AccessSessions    AccessSessionStore
}

type TOTPConfig

type TOTPConfig struct {
	Enabled            bool
	EnrollmentLifetime time.Duration
	ChallengeLifetime  time.Duration
	RecoveryCodeCount  int
	AttemptGuard       totp.AttemptGuard
	SecurityEvents     totp.SecurityEventSink
}

Directories

Path Synopsis
Package accesstoken issues and verifies short-lived JWT access tokens.
Package accesstoken issues and verifies short-lived JWT access tokens.
Package emailaddress normalizes email identities.
Package emailaddress normalizes email identities.
Package emailpassword orchestrates email and password authentication.
Package emailpassword orchestrates email and password authentication.
Package emailverification manages email ownership verification.
Package emailverification manages email ownership verification.
Package googleoauth provides Google Authorization Code flow orchestration.
Package googleoauth provides Google Authorization Code flow orchestration.
internal
Package oidc provides OpenID Connect authentication orchestration.
Package oidc provides OpenID Connect authentication orchestration.
Package passkey manages WebAuthn passkey registration and authentication.
Package passkey manages WebAuthn passkey registration and authentication.
Package passwordreset manages password recovery with emailed tokens.
Package passwordreset manages password recovery with emailed tokens.
Package refreshtoken manages opaque tokens that renew JWT access tokens.
Package refreshtoken manages opaque tokens that renew JWT access tokens.
Package saml provides SAML Web SSO orchestration for service providers.
Package saml provides SAML Web SSO orchestration for service providers.
Package sessiontoken manages opaque server-side sessions.
Package sessiontoken manages opaque server-side sessions.
storage
mongodb
Package mongodb provides Authlier storage backed by MongoDB.
Package mongodb provides Authlier storage backed by MongoDB.
mysql
Package mysql provides Authlier storage backed by MySQL.
Package mysql provides Authlier storage backed by MySQL.
postgres
Package postgres provides Authlier storage backed by PostgreSQL.
Package postgres provides Authlier storage backed by PostgreSQL.
redis
Package redis provides Authlier storage and optional session caching backed by Redis.
Package redis provides Authlier storage and optional session caching backed by Redis.
Package token generates and hashes opaque bearer credentials.
Package token generates and hashes opaque bearer credentials.
Package totp manages authenticator-app MFA and recovery codes.
Package totp manages authenticator-app MFA and recovery codes.

Jump to

Keyboard shortcuts

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