Documentation
¶
Overview ¶
Package copilot implements native GitHub Copilot OAuth authentication using the device code flow, without requiring any external CLI tools.
The flow follows RFC 8628 (OAuth 2.0 Device Authorization Grant):
- Request device code from GitHub
- User visits verification URL and enters the user code
- Poll for access token until authorized
- Use access token with the Copilot API (OpenAI-compatible)
Credentials are stored in the unified auth store (~/.local/share/lokit/auth.json).
Index ¶
- Constants
- func DeleteToken() error
- func DeviceCodeFlow(ctx context.Context, onPrompt func(verificationURI, userCode string)) (string, error)
- func EnsureAuth(ctx context.Context) (string, error)
- func LoadToken() *settings.Info
- func SaveToken(access string) error
- func SetAuthHeaders(req *http.Request, accessToken string)
- func TokenStatus() string
Constants ¶
const (
// Copilot API
CopilotAPIBase = "https://api.githubcopilot.com"
)
Variables ¶
This section is empty.
Functions ¶
func DeleteToken ¶
func DeleteToken() error
DeleteToken removes the Copilot credentials from the unified auth store.
func DeviceCodeFlow ¶
func DeviceCodeFlow(ctx context.Context, onPrompt func(verificationURI, userCode string)) (string, error)
DeviceCodeFlow initiates the GitHub OAuth device code flow. It prints instructions for the user and blocks until authentication is complete or the context is cancelled.
onPrompt is called with the verification URL and user code so the caller can display them to the user.
func EnsureAuth ¶
EnsureAuth returns a valid Copilot access token. If a token is already stored, it returns that. Otherwise, it initiates the device code flow interactively.
func LoadToken ¶
LoadToken loads the Copilot OAuth token from the unified auth store. Returns nil if no token is stored.
func SetAuthHeaders ¶
SetAuthHeaders sets the required headers for Copilot API requests. This must be called on each request to the Copilot API.
func TokenStatus ¶
func TokenStatus() string
TokenStatus returns a human-readable status of the stored token.
Types ¶
This section is empty.