authflow

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: MIT Imports: 17 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 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 Identity added in v0.38.0

type Identity struct {
	Email       string `json:"email"`
	DisplayName string `json:"display_name"`
	Username    string `json:"username"`
	Org         struct {
		ID   string `json:"id"`
		Name string `json:"name"`
		Slug string `json:"slug"`
		Plan string `json:"plan"`
	} `json:"org"`
}

Identity is the signed-in account, from GET {webAppURL}/api/cli/whoami.

func Whoami added in v0.38.0

func Whoami(ctx context.Context, token string) (Identity, error)

Whoami asks the web app who a memcode_ bearer token belongs to. Network-bound; pass a bounded context.

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