demokit

package
v0.0.76 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package demokit provides an interactive step-through framework for OneAuth examples. Each example defines a sequence of steps (with mermaid diagram arrows) and optional sections (explanatory text). The same definitions drive both the interactive CLI and the generated README.

Single source of truth: step titles, arrows, and notes are defined in Go code. The README's mermaid diagram and step documentation are generated from these definitions — never maintained by hand.

Usage:

demo := demokit.New("01: Client Credentials Flow").
    Description("Non-UI | No infrastructure needed").
    Actors(
        demokit.Actor("App", "Client App"),
        demokit.Actor("AS", "Auth Server"),
    )
demo.Step("Register a client").
    Arrow("App", "AS", "POST /apps/register").
    Arrow("AS", "App", "{client_id, client_secret}").
    Note("The client gets credentials for later use.").
    Run(func() { fmt.Println("registered!") })
demo.Execute()

Index

Constants

This section is empty.

Variables

View Source
var (
	RFC6749                   = Ref{"RFC 6749 — OAuth 2.0", "https://www.rfc-editor.org/rfc/rfc6749"}
	RFC6749_ClientCredentials = Ref{"RFC 6749 §4.4 — Client Credentials Grant", "https://www.rfc-editor.org/rfc/rfc6749#section-4.4"}
	RFC6749_AuthorizationCode = Ref{"RFC 6749 §4.1 — Authorization Code Grant", "https://www.rfc-editor.org/rfc/rfc6749#section-4.1"}
	RFC6750                   = Ref{"RFC 6750 — Bearer Token Usage", "https://www.rfc-editor.org/rfc/rfc6750"}
)

OAuth 2.0

View Source
var (
	RFC7515 = Ref{"RFC 7515 — JSON Web Signature (JWS)", "https://www.rfc-editor.org/rfc/rfc7515"}
	RFC7517 = Ref{"RFC 7517 — JSON Web Key (JWK)", "https://www.rfc-editor.org/rfc/rfc7517"}
	RFC7519 = Ref{"RFC 7519 — JSON Web Token (JWT)", "https://www.rfc-editor.org/rfc/rfc7519"}
	RFC7638 = Ref{"RFC 7638 — JWK Thumbprint (kid)", "https://www.rfc-editor.org/rfc/rfc7638"}
)

JWT / JWS / JWK

View Source
var (
	RFC7591 = Ref{"RFC 7591 — Dynamic Client Registration", "https://www.rfc-editor.org/rfc/rfc7591"}
	RFC7636 = Ref{"RFC 7636 — PKCE", "https://www.rfc-editor.org/rfc/rfc7636"}
	RFC7662 = Ref{"RFC 7662 — Token Introspection", "https://www.rfc-editor.org/rfc/rfc7662"}
	RFC8414 = Ref{"RFC 8414 — AS Metadata Discovery", "https://www.rfc-editor.org/rfc/rfc8414"}
)

Token management

View Source
var (
	RFC9728 = Ref{"RFC 9728 — Protected Resource Metadata", "https://www.rfc-editor.org/rfc/rfc9728"}

	CVE_2015_9235 = Ref{"CVE-2015-9235 — JWT Algorithm Confusion", "https://nvd.nist.gov/vuln/detail/CVE-2015-9235"}
)

Security

View Source
var (
	RFC9396 = Ref{"RFC 9396 — Rich Authorization Requests", "https://www.rfc-editor.org/rfc/rfc9396"}
)

Rich Authorization Requests

Functions

This section is empty.

Types

type ActorDef

type ActorDef struct {
	ID    string // Short identifier used in arrows (e.g., "AS")
	Label string // Display label (e.g., "Auth Server")
}

ActorDef defines a participant in the sequence diagram.

func Actor

func Actor(id, label string) ActorDef

Actor creates an ActorDef.

type Demo

type Demo struct {
	// contains filtered or unexported fields
}

Demo is the top-level container for an interactive example.

func New

func New(title string) *Demo

New creates a new Demo with the given title.

func (*Demo) Actors

func (d *Demo) Actors(actors ...ActorDef) *Demo

Actors sets the sequence diagram participants.

func (*Demo) Description

func (d *Demo) Description(desc string) *Demo

Description sets the one-line description shown in the CLI header.

func (*Demo) Dir

func (d *Demo) Dir(name string) *Demo

Dir sets the directory name used in generated README run commands. e.g., Dir("01-client-credentials") produces "go run ./examples/01-client-credentials/"

func (*Demo) Execute

func (d *Demo) Execute()

Execute runs the demo interactively — pausing between steps for Enter. If --non-interactive is passed (or stdin is not a terminal), runs without pausing.

func (*Demo) Markdown

func (d *Demo) Markdown() string

Markdown generates the full README content from the demo definition. This is the single source of truth — run with --readme to regenerate.

func (*Demo) Section

func (d *Demo) Section(title string, lines ...string) *Demo

Section adds a non-executable explanatory block. Lines are joined with newlines, so you can write multi-paragraph markdown naturally:

demo.Section("How it works",
    "The auth server signs tokens with HS256.",
    "",
    "**Key insight:** Both servers share the same KeyStore.",
)

func (*Demo) Step

func (d *Demo) Step(title string) *StepDef

Step adds an executable step to the demo. Returns the StepDef for chaining.

type Ref

type Ref struct {
	Name string // e.g., "RFC 7519 (JWT)" or "CVE-2015-9235"
	URL  string // e.g., "https://www.rfc-editor.org/rfc/rfc7519"
}

Ref is a named reference (RFC, CVE, blog post, spec section, etc.).

type SectionDef

type SectionDef struct {
	// contains filtered or unexported fields
}

SectionDef is a non-executable block of explanatory content.

type StepDef

type StepDef struct {
	// contains filtered or unexported fields
}

StepDef defines one executable step in the demo.

func (*StepDef) Arrow

func (s *StepDef) Arrow(from, to, label string) *StepDef

Arrow adds a solid arrow (request) to the step's sequence diagram.

func (*StepDef) DashedArrow

func (s *StepDef) DashedArrow(from, to, label string) *StepDef

DashedArrow adds a dashed arrow (response) to the step's sequence diagram.

func (*StepDef) Note

func (s *StepDef) Note(text string) *StepDef

Note adds explanatory text shown in both CLI and README.

func (*StepDef) Ref

func (s *StepDef) Ref(ref Ref) *StepDef

Ref adds a reference (RFC, CVE, spec section, blog post, etc.) to this step. Use pre-defined constants from refs.go: demokit.RFC7519, demokit.CVE_2015_9235, etc.

func (*StepDef) Run

func (s *StepDef) Run(fn func()) *StepDef

Run sets the function to execute for this step.

Jump to

Keyboard shortcuts

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