oauth

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ChatGPTAuthEndpoint  = "https://auth.openai.com/oauth/authorize"
	ChatGPTTokenEndpoint = "https://auth.openai.com/oauth/token"
	// Temporary until we figure out how term-llm can get a proper client ID
	ChatGPTClientID     = "app_EMoamEEZ73f0CkXaXp7hrann"
	ChatGPTRedirectURI  = "http://localhost:1455/auth/callback"
	ChatGPTScopes       = "openid profile email offline_access"
	ChatGPTCallbackPort = 1455
)
View Source
const (
	// CopilotClientID is the VS Code GitHub Copilot extension's client ID.
	// This is required for access to GitHub's internal Copilot APIs (usage, token exchange).
	// Using the VS Code client ID is a common approach in the Copilot developer community.
	CopilotClientID = "Iv1.b507a08c87ecfe98"

	// CopilotScope is the OAuth scope required for Copilot API access
	CopilotScope = "read:user"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatGPTCredentials

type ChatGPTCredentials struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresAt    int64  `json:"expires_at"` // Unix timestamp in seconds
	AccountID    string `json:"account_id"` // ChatGPT account ID from JWT
}

ChatGPTCredentials holds the OAuth tokens

func AuthenticateChatGPT

func AuthenticateChatGPT(ctx context.Context) (*ChatGPTCredentials, error)

AuthenticateChatGPT runs the full OAuth flow and returns credentials

func (*ChatGPTCredentials) IsExpired

func (c *ChatGPTCredentials) IsExpired() bool

IsExpired returns true if the access token is expired or will expire within 5 minutes

type ChatGPTTokenResponse

type ChatGPTTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	IDToken      string `json:"id_token"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
}

func RefreshToken

func RefreshToken(refreshToken string) (*ChatGPTTokenResponse, error)

RefreshToken refreshes an expired access token

type CopilotCredentials added in v0.0.34

type CopilotCredentials struct {
	AccessToken string `json:"access_token"`
	ExpiresAt   int64  `json:"expires_at"` // 0 = no expiry tracking
}

CopilotCredentials holds the OAuth token for Copilot. Note: credentials.CopilotCredentials is the storage type with the same fields.

func AuthenticateCopilot added in v0.0.34

func AuthenticateCopilot(ctx context.Context) (*CopilotCredentials, error)

AuthenticateCopilot runs the full device code OAuth flow and returns credentials

type CopilotDeviceCodeResponse added in v0.0.34

type CopilotDeviceCodeResponse struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"` // Polling interval in seconds
}

CopilotDeviceCodeResponse holds the device code response from GitHub

func RequestCopilotDeviceCode added in v0.0.34

func RequestCopilotDeviceCode() (*CopilotDeviceCodeResponse, error)

RequestCopilotDeviceCode initiates the device code flow

type CopilotTokenResponse added in v0.0.34

type CopilotTokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
	Error       string `json:"error,omitempty"`
}

CopilotTokenResponse holds the token response from GitHub

func PollForCopilotToken added in v0.0.34

func PollForCopilotToken(ctx context.Context, deviceCode string, interval int) (*CopilotTokenResponse, error)

PollForCopilotToken polls for the access token after the user has authorized

Jump to

Keyboard shortcuts

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