authflow

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package authflow is the browser login flow shared by `memcode login` (cobra) and the TUI's /login slash command. A local HTTP server on 127.0.0.1:19090 receives the token from the web app's /api/cli/auth callback redirect; the caller persists it via WriteGlobalEnvToken so the existing LoadDotEnv → provider path picks it up.

Index

Constants

View Source
const DefaultGatewayURL = provider.DefaultAPIURL

DefaultGatewayURL is the production memcode gateway. The web app's /api/cli/auth may override this by returning api_url in the callback, but this default lets login work even when the callback doesn't include it.

View Source
const DefaultWebAppURL = "https://www.memcode.ai"

DefaultWebAppURL is where the browser opens to authenticate. Use the www host directly: the apex (memcode.ai) 308-redirects to www, and that extra cross-host hop on the /api/cli/auth?port=&state= URL is needless churn on a load-bearing flow. Point straight at the canonical host.

Variables

This section is empty.

Functions

func OpenBrowser added in v0.16.0

func OpenBrowser(url string) error

OpenBrowser opens url in the user's default browser. Best-effort — callers always print the URL too, so a headless session still works.

func SetGlobalEnv added in v0.10.0

func SetGlobalEnv(kv map[string]string) error

SetGlobalEnv writes key=value pairs into the global env file (~/.config/memcode/.env), replacing any existing lines for those keys and leaving everything else intact. The wizard uses it to persist a credential choice (a selected subscription source, an own key, an endpoint). Values are written verbatim; callers pass already-trimmed values.

func StripGlobalEnvToken

func StripGlobalEnvToken() (bool, error)

StripGlobalEnvToken removes the token/url lines from the global env file (logout). Returns whether anything was removed; a missing file is a no-op. The token stays valid server-side until revoked from the web app (a /api/cli/revoke endpoint is a follow-up).

func WriteGlobalEnvToken

func WriteGlobalEnvToken(token, apiURL string) error

WriteGlobalEnvToken writes MEMCODE_API_TOKEN and MEMCODE_API_URL into the global env file (~/.config/memcode/.env), creating it if needed and replacing any existing values for those keys (no-override is for LoadDotEnv; login is the explicit user action that SHOULD overwrite).

Types

type Result

type Result struct {
	Token      string
	GatewayURL string
	Email      string // the signed-in account email, when the web app supplies it
}

Result is a successful login: the minted org key and the gateway to use it against.

func Run

func Run(ctx context.Context, status func(string)) (Result, error)

Run executes the browser login flow: starts the local callback server, opens the browser, and waits for the redirect. status (nil-safe) receives progress lines for display. Cancel ctx to abort (the TUI's Esc); an internal 2-minute timeout applies regardless. Run does NOT persist anything — callers decide (WriteGlobalEnvToken).

Jump to

Keyboard shortcuts

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