Documentation
¶
Overview ¶
Package forge holds provider-agnostic helpers shared by forge providers - Gitea/Forgejo today, GitHub Enterprise and self-managed GitLab in future: host parsing, same-origin checks, and OAuth PKCE/Link primitives. Everything here is pure and stateless; each provider keeps its own endpoints, token store, and auth flow.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NextLink ¶
NextLink returns the rel="next" URL from an RFC 8288 Link header, or "" when none. Forges that paginate with the standard Link header expose the authoritative "more pages" signal here, rather than guessing from a full page.
func NormalizeHost ¶
NormalizeHost parses a forge host given as a bare name (codeberg.org), a host:port, or a full URL (https://git.example.com/), returning the lowercased host[:port]. ok is false when the value is empty or carries userinfo, a path, query, or fragment - anything that is not a plain network authority - so a marker-controlled host cannot smuggle a path or credentials.
func PATHost ¶
PATHost returns the single host a host-independent personal access token may be sent to. A PAT is attached to whichever host a marker names, so a marker-controlled host= could otherwise redirect the token to an attacker; the PAT is bound to one host - the hostEnv override (normalized) when set, else defaultHost. When pinned (a test transport), ambient env is ignored and defaultHost is returned, keeping a test hermetic and its auth path deterministic.
func PKCE ¶
PKCE returns an RFC 7636 verifier (32 random bytes, 43 base64url chars) and its S256 challenge (the base64url SHA-256 of the verifier), as required by a public OAuth client.
func RandomState ¶
RandomState returns an unguessable OAuth state value (16 random bytes) binding an authorization request to its callback.
func SameOrigin ¶
SameOrigin reports whether two URLs share a scheme and host. It guards a paginated lookup from forwarding a credential to a different origin than the one the lookup started on.
Types ¶
This section is empty.