api_authknight_callback

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultHTTPTimeout       = 10 * time.Second
	DefaultTempKeyExpiration = 1 * time.Hour
	TokenGamma               = "BCDFGHJKLMNPQRSTVXYZ"
	TokenLength              = 32
	AuthKnightWhoEndpoint    = "/api/who"
	AuthKnightDefaultBaseURL = "https://authknight.com"
)

Variables

This section is empty.

Functions

func ApiAuthKnightCallback

func ApiAuthKnightCallback(w http.ResponseWriter, r *http.Request, deps Dependencies)

ApiAuthKnightCallback handles the AuthKnight callback redirect. It extracts the "once" parameter, verifies it with AuthKnight's API, and either creates a session (existing user) or redirects to the register page (new user).

func ApiAuthKnightCallbackWithAuth

func ApiAuthKnightCallbackWithAuth(w http.ResponseWriter, r *http.Request, a types.AuthAuthKnightInterface)

ApiAuthKnightCallbackWithAuth is a convenience wrapper that allows callers to pass a types.AuthAuthKnightInterface instead of manually wiring Dependencies.

Types

type Dependencies

type Dependencies struct {
	// BaseURL is the AuthKnight base URL (e.g. "https://authknight.com").
	BaseURL string

	// HTTPTimeout for calls to the AuthKnight API. Defaults to 10 seconds.
	HTTPTimeout time.Duration

	// UserFindByEmail finds a user by email and returns their ID.
	UserFindByEmail func(ctx context.Context, email string, options types.UserAuthOptions) (userID string, err error)

	// UserStoreAuthToken stores the auth token for a user.
	UserStoreAuthToken func(ctx context.Context, token, userID string, options types.UserAuthOptions) error

	// TemporaryKeySet stores a temporary key-value pair with expiration.
	TemporaryKeySet func(key string, value string, expiresSeconds int) error

	// TemporaryKeyGet retrieves a temporary value by key.
	TemporaryKeyGet func(key string) (string, error)

	// RedirectURL calculates the redirect URL after successful auth.
	// If nil, falls back to UrlRedirectOnSuccess.
	RedirectURL func(ctx context.Context, userID string) string

	// UrlRedirectOnSuccess is the default redirect URL.
	UrlRedirectOnSuccess string

	// RegisterURL is the URL of the register page (with ?ak_key= appended).
	RegisterURL string

	// UseCookies controls whether the auth token should be written as a cookie.
	UseCookies bool

	// SetAuthCookie writes the auth cookie.
	SetAuthCookie func(w http.ResponseWriter, r *http.Request, token string)

	// Logger is used to log internal errors. If nil, slog.Default() is used.
	Logger *slog.Logger
}

Dependencies defines the dependencies required for the AuthKnight callback handler.

Jump to

Keyboard shortcuts

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