copilot

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 9 Imported by: 0

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):

  1. Request device code from GitHub
  2. User visits verification URL and enters the user code
  3. Poll for access token until authorized
  4. Use access token with the Copilot API (OpenAI-compatible)

Credentials are stored in the unified auth store (~/.local/share/lokit/auth.json).

Index

Constants

View Source
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

func EnsureAuth(ctx context.Context) (string, error)

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

func LoadToken() *settings.Info

LoadToken loads the Copilot OAuth token from the unified auth store. Returns nil if no token is stored.

func SaveToken

func SaveToken(access string) error

SaveToken saves a Copilot OAuth token to the unified auth store.

func SetAuthHeaders

func SetAuthHeaders(req *http.Request, accessToken string)

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.

Jump to

Keyboard shortcuts

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