Documentation
ΒΆ
Overview ΒΆ
Package authingo provides a lightweight, secure, and developer-first authentication framework for Go applications.
Unlike heavy identity providers, AuthInGo focuses on keeping authentication within your infrastructure using opaque tokens and database-backed sessions. It is designed to work seamlessly with modern frontend frameworks (like React/Next.js) via its companion npm package, @authingo/react.
Key Features:
- Opaque Token Sessions: High security by keeping JWTs/session data out of the browser.
- Refresh Token Rotation: Built-in short-lived access tokens (15 minutes) and long-lived refresh tokens (30 days) for silent, secure session renewals.
- Secure Defaults: Automatically handles HttpOnly, Secure, and SameSite cookie configurations.
- Pluggable Storage: Bring your own database via the Store interface (e.g., adapters/postgres).
- Middleware Protection: Built-in HTTP middleware to strictly secure your private routes.
For complete guides and frontend integration instructions, visit the repository: https://github.com/binit2-1/authingo
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 core engine. It holds the database adapter and the HTTP router.
type Options ΒΆ
type Options struct {
// Store is the database adapter (Required).
Store Store
// Plugins is an optional list of extensions.
Plugins []Plugin
}
Options holds the configuration for initializing AuthInGo.
type Plugin ΒΆ
type Plugin interface {
ID() string
// InjectRoutes allows the plugin to add custom endpoints (e.g., /api/auth/2fa)
InjectRoutes(mux *http.ServeMux)
}
Plugin defines an extension that can modify the core AuthInGo behavior.
type Session ΒΆ
type Session struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Token string `json:"-"`
RefreshToken string `json:"-"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
RefreshExpiresAt time.Time `json:"refresh_expires_at"`
}
Session represents an active login instance.
type Store ΒΆ
type Store interface {
// CreateUser inserts a new user into the database.
// We pass a pointer (*User) so the adapter can populate the generated ID.
CreateUser(ctx context.Context, user *User) error
// GetUserByEmail fetches a user for login validation.
GetUserByEmail(ctx context.Context, email string) (*User, error)
// CreateSession stores a newly generated opaque token.
CreateSession(ctx context.Context, session *Session) error
// GetSession fetches the session and its associated user from the database.
GetSession(ctx context.Context, token string) (*Session, *User, error)
// DeleteSession removes the session (used for logging out).
DeleteSession(ctx context.Context, token string) error
//RefreshSession updates the session's expiration time (used for "remember me" functionality).
RefreshSession(ctx context.Context, oldRefreshToken string) (*Session, *User, error)
//CleanupExpiredSessions removes sessions that have passed their expiration time.
CleanupExpiredSessions(ctx context.Context) error
}
Store defines the exact database operations required by AuthInGo. Any database (Postgres, MySQL, SQLite) can be used as long as it implements these exact methods.
type User ΒΆ
type User struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
PasswordHash string `json:"-"`
EmailVerified bool `json:"email_verified"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
User represents a registered account in the system.