Skip to main content

Mounting & auth API

Mount goauth once on a wildcard route. Fiber forwards every /auth/... request to the core handler.

app.All("/auth/*", fiberauth.Handler(auth))

Handler uses Fiber’s adaptor to bridge fiber.Ctxnet/http.

Routes available through Fiber

Same table as core goauth — see Routes reference.

MethodPathUse from Fiber / SPA
GET/auth/sessionCurrent user JSON
GET/auth/csrfCSRF token (cookie flows)
GET/auth/providersProvider metadata
POST/auth/signin/:providerStart email/OTP sign-in
GET/POST/auth/callback/:providerOAuth redirect or credentials POST
POST/auth/signoutLog out
POST/auth/tokenRefresh bearer tokens
POST/auth/mfa/verifyComplete MFA
GET/auth/mfa/deviceCheck trusted device
GET/auth/sessionsList sessions (DB strategy)

Calling auth from Fiber handlers

Option A — middleware (preferred)

app.Use(fiberauth.SessionLoader(auth)) // optional global loader

app.Get("/api/me", fiberauth.Protect(auth), meHandler)

Option B — explicit per request

func meHandler(c fiber.Ctx) error {
session, err := fiberauth.GetSession(auth, c)
if err != nil {
return c.Status(500).JSON(fiber.Map{"error": err.Error()})
}
if session == nil {
return c.Status(401).JSON(fiber.Map{"error": "unauthorized"})
}
return c.JSON(session.User)
}

GetSession copies any Set-Cookie headers from goauth onto the Fiber response.

Bearer tokens (SPA / mobile)

Enable tokens in config:

Tokens: goauth.TokensConfig{
Enabled: true,
AlwaysReturn: true, // optional: always JSON, no cookies
},

Client sends:

Authorization: Bearer eyJhbGc...

Protect / GetSession accept bearer auth automatically when Tokens.Enabled is true.

Testing with app.Test

req, _ := http.NewRequest(http.MethodGet, "/auth/session", nil)
req.Header.Set("Authorization", "Bearer "+accessToken)
resp, err := app.Test(req)

See Sign in (credentials) for obtaining a token in tests.