golazy.dev golazy.dev / pg / pgauth Index | Files

package pgauth

import "golazy.dev/pg/pgauth"

Package pgauth provides a PostgreSQL-backed lazyauth.Authenticator.

Applications own their pgx pool and pass it to New. Include Migrations() in the app's PostgreSQL migration sources before authenticating users.

Functions

func HashPassword

HashPassword hashes password with the same PBKDF2 format as fileauth.

func HashPassword(password string) (string, error)

func VerifyPassword

VerifyPassword verifies a password hash produced by HashPassword.

func VerifyPassword(encoded string, password string) bool

Types

type Provider

Provider authenticates lazyauth password credentials from PostgreSQL.

type Provider struct {
	// contains filtered or unexported fields
}
func New

New creates a PostgreSQL-backed lazyauth provider.

func New(pool *pgxpool.Pool) *Provider
func (p *Provider) Authenticate

Authenticate implements lazyauth.Authenticator.

func (p *Provider) Authenticate(ctx context.Context, credential lazyauth.Credential) (lazyauth.User, error)
func (p *Provider) UpsertUser

UpsertUser creates or updates one password-authenticated user.

func (p *Provider) UpsertUser(ctx context.Context, params UserParams) (lazyauth.User, error)

type UserParams

UserParams describes a user to create or update in lazy_auth_users.

type UserParams struct {
	ID		string
	Email		string
	Password	string
	PasswordHash	string
	Data		map[string]any
}