Documentation
¶
Overview ¶
Package authflow implements the OAuth Loopback flow used by `mp2rss auth login`.
Lifecycle:
- Caller calls New() with the resolved Web origin and asks for an open port.
- Caller composes the authorize URL using AuthorizeURL().
- Caller invokes Wait(ctx) to block until the browser POSTs the Feed Key to /cli/callback, or 120s elapses.
- Server shuts itself down after the first successful callback.
Security:
- Listens on 127.0.0.1 only.
- Single route: /cli/callback (POST).
- Validates Origin against an allow-list.
- Validates state nonce against CSRF.
- Never prints the Feed Key to the terminal.
Index ¶
Constants ¶
View Source
const DefaultTimeout = 120 * time.Second
DefaultTimeout is how long we wait for the browser to POST back.
Variables ¶
View Source
var AllowedOrigins = []string{
"https://mp2rss.bugcode.dev",
"http://localhost:3000",
"http://[::1]:3000",
}
AllowedOrigins are the only Origin headers we'll accept.
Web 端 vite dev 默认起在 :3000(apps/web vite.config 已固定),生产是 https://mp2rss.bugcode.dev。同一台机器同时通过 IPv4 / IPv6 解析 localhost 时 浏览器可能发出 http://[::1]:3000,所以两条都列上。
Functions ¶
This section is empty.
Types ¶
type CallbackResult ¶
type CallbackResult struct {
FeedKey string `json:"feed_key"`
State string `json:"state"`
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
}
CallbackResult is what the browser POSTs to /cli/callback.
type Flow ¶
type Flow struct {
State string // 32-byte hex CSRF nonce
Port int // TCP port we bound to
WebOrigin string // e.g. https://mp2rss.bugcode.dev
Timeout time.Duration // override DefaultTimeout for tests
// AllowedOrigins overrides the package default — useful for tests.
AllowedOrigins []string
// contains filtered or unexported fields
}
Flow is a single-shot loopback server.
func (*Flow) AuthorizeURL ¶
AuthorizeURL composes the URL the user opens in their browser.
func (*Flow) CallbackURL ¶
CallbackURL returns the loopback URL the browser POSTs to.
Click to show internal directories.
Click to hide internal directories.