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 ¶
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.
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
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
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 ¶
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 ¶
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 ¶
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).