auth

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package auth handles inbound caller authentication for codex-app-gateway.

Phase 1 uses an HMAC-signed token of the form

<workspace_id>.<thread_id>.<hex-hmac-sha256>

where the HMAC covers `<workspace_id>\0<thread_id>` keyed by a deployment-shared secret. This matches the wstoken / internal-API pattern used elsewhere in agentserver and avoids pulling a JWT lib just for phase 1. Phase 2 can swap in a JWT impl behind the same `Authenticator` interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractBearer

func ExtractBearer(r *http.Request) (string, bool)

ExtractBearer pulls the token out of `Authorization: Bearer <tok>`.

Types

type Authenticator

type Authenticator interface {
	Verify(token string) (Identity, error)
}

Authenticator is the seam for inbound auth. Phase-1 impl is HMAC.

type HMAC

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

HMAC is the phase-1 Authenticator.

func NewHMAC

func NewHMAC(secret []byte) *HMAC

NewHMAC returns a phase-1 Authenticator. The secret must be non-empty for tokens to verify; an empty secret will still mint and verify against itself but represents a deployment misconfiguration.

func (*HMAC) Mint

func (a *HMAC) Mint(workspaceID, threadID string) string

Mint produces a token for `(workspaceID, threadID)`. Useful for tests and CLI tools; production callers receive tokens from agentserver.

func (*HMAC) Verify

func (a *HMAC) Verify(token string) (Identity, error)

Verify parses and HMAC-verifies a token.

Token format: <workspace_id>.<thread_id>.<hex-hmac>

The sig is always the last dot-separated field. The workspace_id is always the first dot-separated field in the prefix (everything before the sig); the thread_id is everything between the first and last dots. This means thread_id may contain dots but workspace_id may not.

Last dot separates the sig from the (workspace_id, thread_id, ...) prefix. We split into "head" and "sig" instead of 3 fixed parts so thread ids that themselves contain dots verify correctly.

type Identity

type Identity struct {
	WorkspaceID string
	ThreadID    string
}

Identity is what a verified token decodes to.

Jump to

Keyboard shortcuts

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