gobetterauth

package module
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

README

Project Logo

A comprehensive, framework-agnostic authentication and authorization library for Go.


Table of Contents

  1. Introduction
  2. Features
  3. Docs
  4. Contributing

Introduction

✨ Overview

GoBetterAuth is a comprehensive, authentication and authorization library/framework for Go applications. It provides secure email/password authentication, session management, email verification, password reset, and more, all built with clean architecture.

💭 Why GoBetterAuth?

GoBetterAuth is designed to be a comprehensive authentication and authorization solution for Go applications. It simplifies the implementation of common security features while providing a clean and modular architecture. This way developers can focus on building their applications without worrying about the complexities of authentication and the time it takes to implement these features.


Features

  • 🔑 Email & Password – Secure, production-ready authentication with argon2 password hashing. Includes Email Verification, Password Reset and Change Email flows.
  • 🌐 Social OAuth Providers – Google, GitHub, Discord and more coming soon.
  • 💾 Multiple Database Support – SQLite, PostgreSQL, MySQL adapters and more coming soon, with migration scripts included.
  • 🗄️ Secondary Storage – Supports in-memory/database storage and a custom interface to implement Redis and other key-value stores. Use secondary storage to manage session data, rate limiting counters, and other high-frequency records. This enables offloading intensive data to high-performance storage solutions or RAM for optimal scalability and speed.
  • 📦 Minimal Dependencies – Standard library first, production-ready, and framework-agnostic.
  • 🧩 Comprehensive Configuration – Flexible, type-safe config with sensible defaults and environment variable support.
  • 🛡️ Enhanced Security – CSRF protection.
  • Rate Limiting – Configurable rate limiting with secondary storage.
  • 📨 Event Bus – Built-in event bus enables event-driven architecture, allowing you to publish and subscribe to authentication and authorization events for seamless integration with external systems and custom workflows.
  • 🔌 Plugin System – Extensible plugin architecture for custom business logic and routes. Including flexible plugin interface to implement all kinds of plugins.

Docs

For more info and a full guide on how to use this library, check out the Docs.


Contributing

Your contributions are welcome! Here's how you can get involved:


Support & Community


Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Config *models.Config

	Api *models.Api

	EventBus models.EventBus
	// contains filtered or unexported fields
}

func New

func New(config *models.Config) *Auth

func (*Auth) AuthMiddleware

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

func (*Auth) CSRFMiddleware added in v1.0.4

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

func (*Auth) ClosePlugins added in v1.3.0

func (auth *Auth) ClosePlugins() error

ClosePlugins calls Close for all registered plugins

func (*Auth) CorsAuthMiddleware added in v1.0.0

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

func (*Auth) DropMigrations added in v1.0.0

func (auth *Auth) DropMigrations()

func (*Auth) EndpointHooksMiddleware added in v1.0.6

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

func (*Auth) GetUserIDFromContext added in v1.1.1

func (auth *Auth) GetUserIDFromContext(ctx context.Context) (string, bool)

func (*Auth) GetUserIDFromRequest added in v1.1.1

func (auth *Auth) GetUserIDFromRequest(req *http.Request) (string, bool)

func (*Auth) Handler

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

Handler sets up all routes and returns the final http.Handler

func (*Auth) OptionalAuthMiddleware

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

func (*Auth) RateLimitMiddleware added in v1.0.4

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

func (*Auth) RegisterRoute added in v1.0.10

func (auth *Auth) RegisterRoute(route models.CustomRoute)

func (*Auth) RunMigrations

func (auth *Auth) RunMigrations()

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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