forge

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 8 Imported by: 0

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(header http.Header) string

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

func NormalizeHost(host string) (string, bool)

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

func PATHost(hostEnv, defaultHost string, pinned bool) string

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

func PKCE() (string, string, error)

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

func RandomState() (string, error)

RandomState returns an unguessable OAuth state value (16 random bytes) binding an authorization request to its callback.

func SameOrigin

func SameOrigin(a, b string) bool

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.

Jump to

Keyboard shortcuts

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