user

package module
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 1 Imported by: 0

README

tinywasm/user

Stable identity value contract for the TinyWasm ecosystem. Authentication, sessions, concrete providers, and authorization live in sibling libraries github.com/tinywasm/auth and github.com/tinywasm/rbac.

Package Structure

Package Purpose
github.com/tinywasm/user WASM-safe root package defining SubjectID and Subject
github.com/tinywasm/auth Authentication, sessions, credential modes, OAuth2, providers, auth/local
github.com/tinywasm/rbac Roles, permissions, assignments, Can

Dependency direction: auth and rbac import user; neither imports the other. Only the application composition root imports both.

flowchart TD
    U[user] --> A[auth]
    U --> R[rbac]
    A --> C[app]
    R --> C

Documentation

Usage

import (
    "github.com/tinywasm/user"
    "github.com/tinywasm/auth/authority"
    "github.com/tinywasm/auth/oauth2"
    "github.com/tinywasm/auth/oauth2/provider/google"
    "github.com/tinywasm/rbac"
    "github.com/tinywasm/orm"
    "github.com/tinywasm/sqlite"
    "github.com/tinywasm/unixid"
)

ids, _ := unixid.NewUnixID()
conn, _ := sqlite.Open("app.db")
db := orm.New(conn)

// auth owns subjects and sessions
mod, _ := authority.New(db, auth.Config{IDs: ids})
gProv := &google.GoogleProvider{
    ClientID:     "client-id",
    ClientSecret: "secret",
    RedirectURL:  "https://example.com" + auth.PathOAuthCallback(google.ProviderName),
}
mod.Enable(oauth2.New(mod, mod, mod, []auth.OAuthProvider{gProv}))

// rbac owns assignments by SubjectID
rb, _ := rbac.New(db)

// composition root wires them: sessions from auth, authorization from rbac
// middleware: mod.Authenticate() sets ctx.UserID to string(user.SubjectID)
// authorize: rb.Can(ctx.UserID(), resource, action)

Local development: build a local authenticator with explicit scenarios and mount it in the development composition root. Production builds use only the Google provider and never register local. See github.com/tinywasm/auth/local.

Status

Stable SubjectID/Subject contract. See docs/ARCHITECTURE.md for dependency rules.

Documentation

Overview

Package user defines the stable identity value shared by TinyWasm libraries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Subject added in v0.3.11

type Subject struct {
	ID     SubjectID
	Email  string
	Name   string
	Avatar string
}

Subject is the safe display identity returned by an authentication service. Roles and permissions deliberately do not belong here; rbac owns them.

func (*Subject) DecodeFields added in v0.3.11

func (s *Subject) DecodeFields(r model.FieldReader)

func (Subject) EncodeFields added in v0.3.11

func (s Subject) EncodeFields(w model.FieldWriter)

func (Subject) IsNil added in v0.3.11

func (s Subject) IsNil() bool

type SubjectID added in v0.3.11

type SubjectID string

SubjectID identifies a person independently of authentication and policy.

Jump to

Keyboard shortcuts

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