Skip to main content

Introduction

GoAuth is a Go authentication library modeled on Auth.js. If you have used NextAuth or @auth/core, the same mental model applies: providers, callbacks, adapters, JWT or database sessions, and a fixed HTTP route table under /auth.

import "github.com/izetmolla/goauth" // module path: goauth

Developer documentation (start here)

I want to…Read
Pick a full goauth.Config for my appConfiguration scenarios
Every config field explainedConfig reference
Control user creation & OAuthResolveUser callback
Send & verify OTP / magic linksOTP & verification guide
All callbacks with examplesCallbacks overview
Production integration walkthroughDeveloper cookbook
Everything the package implementsFeature map
Fiber v3 + middleware & examplesFiberV3 implementation

Why GoAuth?

Auth.jsgoauth
Auth(request, config)goauth.New(cfg)http.Handler
providers/*goauth/providers/* subpackages
@auth/*-adaptergoauth.Adapter + goauth/adapters/*
Encrypted JWE sessionsgoauth/jwt (wire-compatible dir + A256CBC-HS512)
Experimental passkeysproviders/passkey + stdlib goauth/webauthn

Design principles

  • Standard library only in the core module — no third-party deps in goauth itself.
  • Mirror Auth.js names and flows so documentation and patterns transfer directly.
  • Runtime-agnostic — works with net/http, Fiber (via fiberauth), or any framework that can mount an http.Handler.

Three kinds of “OTP” (don’t mix them up)

MechanismYou implementVerify at
Magic linkemail.SendVerificationRequestGET /callback/email
Login email codeotp.SendCodePOST /callback/otp
MFA after passwordMFA.SendCodePOST /mfa/verify

Details: OTP & verification guide.

Minimal example

package main

import (
"log"
"net/http"

"github.com/izetmolla/goauth"
"github.com/izetmolla/goauth/providers/github"
)

func main() {
auth, err := goauth.New(goauth.Config{
Secret: []string{"change-me-to-a-32-byte-or-longer-secret"},
TrustHost: true,
Providers: []goauth.Provider{
github.New("CLIENT_ID", "CLIENT_SECRET"),
},
})
if err != nil {
log.Fatal(err)
}

mux := http.NewServeMux()
mux.Handle("/auth/", auth)
log.Fatal(http.ListenAndServe(":3000", mux))
}

Documentation sections

  • Configuration — reference + 9 real-world scenarios
  • Callbacks & events — SignIn, ResolveUser, JWT, Session, Redirect
  • Developer guides — OTP flows, user creation, cookbook, feature map
  • Providers — OAuth, credentials, email, passkey, Azure AD
  • Security — MFA, CSRF
  • API clients — bearer tokens, browser callback, goauth.js
  • Adapters — SQL, authenticators
  • Reference — routes, errors

:::tip Run docs locally cd docs && pnpm install && pnpm starthttp://localhost:3000 :::