ghserver

command
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2026 License: Apache-2.0 Imports: 30 Imported by: ? 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.

README

ghserver

A minimal GitHub-compatible server that the gh CLI signs in to with gh auth login --hostname. It shows how an application serves the oauth package: the device flow, the code flow, personal access tokens, and the parts of GitHub's API that gh calls during sign-in. The OpenID conformance suite runs against it.

The package documentation is in main.go. To read it with the API, run go doc ./examples/ghserver.

To run the real gh CLI against it on port 443 (Linux, needs gh), run just test-gh.

Contents

Name What it holds
main.go The server, its clients, and the GitHub API routes gh calls; the command documentation, with how to run it with a self-signed certificate

The tests are in the *_test.go files next to the code.

See also

Documentation

Overview

Command ghserver is a minimal GitHub-compatible server that the gh CLI can sign in to with "gh auth login --hostname". It shows how an application serves the oauth package: the device flow, the code flow, personal access tokens, and the parts of GitHub's API that gh calls during sign-in.

gh only talks HTTPS on port 443, so the server needs a certificate that gh trusts. To try it on Linux with a self-signed certificate, run:

go run ./examples/ghserver -self-signed cert.pem
SSL_CERT_FILE=cert.pem GH_CONFIG_DIR=$(mktemp -d) gh auth login --hostname localhost --web

Binding port 443 needs root or, on Linux, the CAP_NET_BIND_SERVICE capability. On macOS, gh ignores SSL_CERT_FILE, so run gh in a Linux container or trust the certificate in the keychain.

The server signs anyone in by name on its demo sign-in page, without a password or passkey. It is a demo: a real application signs users in with the passkey package, as examples/passkeyapp does.

Jump to

Keyboard shortcuts

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