auth

package
v0.0.0-...-c292efc Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 12 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

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("credentials not found")

Functions

func Clear

func Clear() error

Clear removes stored credentials and sidecar files.

func LooksLikeCookie

func LooksLikeCookie(s string) bool

LooksLikeCookie reports whether s looks like a Cookie header (vs API key).

func Path

func Path() (string, error)

Path returns the credentials.json path.

func ReadFileContent

func ReadFileContent(path string) (string, error)

ReadFileContent reads a whole file and trims whitespace (for cookie/UA files).

func Save

func Save(c *Credentials) error

Save writes:

  • cookie → cookie.txt
  • user-agent → user-agent.txt
  • api key / username → credentials.json (no cookie/ua fields)

Types

type BrowserResult

type BrowserResult struct {
	Cookie    string
	UserAgent string
}

BrowserResult is captured after the user passes Cloudflare in a real browser.

func CaptureViaBrowser

func CaptureViaBrowser(ctx context.Context, onStatus func(string)) (*BrowserResult, error)

CaptureViaBrowser opens a visible Chrome/Chromium window on linux.do, waits until cf_clearance (or a non-challenge page) appears, then returns Cookie header + User-Agent.

cf_clearance is HttpOnly — only CDP/browser automation can read it, not page JS.

type Credentials

type Credentials struct {
	UserAPIKey      string `json:"user_api_key,omitempty"`
	UserAPIClientID string `json:"user_api_client_id,omitempty"`
	Username        string `json:"username,omitempty"`

	// Cookie / UserAgent live only in sidecar .txt files on disk.
	// JSON tags are kept for one-time migration of older configs.
	Cookie    string `json:"cookie,omitempty"`
	UserAgent string `json:"user_agent,omitempty"`
}

Credentials is the in-memory session material.

On disk layout (no field duplication):

cookie.txt       — Cookie only (hand-edit / browser login)
user-agent.txt   — User-Agent only
credentials.json — API key + username only (optional)

func Load

func Load() (*Credentials, error)

Load reads:

  1. credentials.json → API key / username only
  2. cookie.txt / user-agent.txt → Cookie / UA (source of truth)
  3. one-time migrate legacy cookie/ua from JSON into .txt if txt empty
  4. env LDO_* overrides

func (*Credentials) Empty

func (c *Credentials) Empty() bool

Empty reports whether no usable secrets are stored.

type EnsureResult

type EnsureResult struct {
	Dir            string
	CreatedDir     bool
	CreatedFiles   []string // basenames only
	AlreadyPresent []string
}

EnsureResult describes what was created on first run.

func EnsureFiles

func EnsureFiles() (*EnsureResult, error)

EnsureFiles creates ~/.config/ldo-tui and template config files if missing. Existing files are never overwritten.

Layout (no field duplication):

  • cookie.txt — Cookie only
  • user-agent.txt — User-Agent only
  • credentials.json — optional API key / username only
  • README.txt — short guide

Jump to

Keyboard shortcuts

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