auth

package
v1.1.41 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderGitHubCopilot = "github-copilot"
	ProviderAnthropic     = "anthropic"
)

Variables

This section is empty.

Functions

func CopilotAPIBaseURL

func CopilotAPIBaseURL(enterpriseURL string) string

func CreateClaudeAPIKey added in v1.1.34

func CreateClaudeAPIKey(ctx context.Context, accessToken string) (string, error)

CreateClaudeAPIKey creates a long-lived API key from an OAuth access token.

func DefaultPath

func DefaultPath() string

func GenerateCodeChallenge added in v1.1.34

func GenerateCodeChallenge(verifier string) string

GenerateCodeChallenge creates a S256 code challenge from a code verifier.

func GenerateCodeVerifier added in v1.1.34

func GenerateCodeVerifier() (string, error)

GenerateCodeVerifier creates a cryptographically random code verifier for PKCE.

func GenerateState added in v1.1.34

func GenerateState() (string, error)

GenerateState creates a random state parameter for OAuth.

func NormalizeEnterpriseURL

func NormalizeEnterpriseURL(raw string) (string, error)

func WaitForClaudeAuthCode added in v1.1.34

func WaitForClaudeAuthCode(ctx context.Context, flow *ClaudeOAuthFlow) (string, bool, error)

WaitForClaudeAuthCode waits for the authorization code from the local callback.

Types

type ClaudeOAuthFlow added in v1.1.34

type ClaudeOAuthFlow struct {
	AutoURL      string
	ManualURL    string
	CodeVerifier string
	State        string
	Port         int
	// contains filtered or unexported fields
}

ClaudeOAuthFlow holds the state for an in-progress OAuth 2.0 + PKCE flow.

func StartClaudeOAuthFlow added in v1.1.34

func StartClaudeOAuthFlow(_ context.Context) (*ClaudeOAuthFlow, error)

StartClaudeOAuthFlow initiates a new OAuth 2.0 + PKCE flow.

func (*ClaudeOAuthFlow) Close added in v1.1.34

func (f *ClaudeOAuthFlow) Close()

Close shuts down the callback HTTP server.

type ClaudeProfile added in v1.1.34

type ClaudeProfile struct {
	SubscriptionType string
	DisplayName      string
	RateLimitTier    string
}

ClaudeProfile holds user profile information from the Anthropic API.

func FetchClaudeProfile added in v1.1.34

func FetchClaudeProfile(ctx context.Context, accessToken string) (*ClaudeProfile, error)

FetchClaudeProfile fetches the user's profile information.

type ClaudeTokenResponse added in v1.1.34

type ClaudeTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"scope"`
}

ClaudeTokenResponse holds the parsed token exchange response.

func ExchangeClaudeCodeForTokens added in v1.1.34

func ExchangeClaudeCodeForTokens(ctx context.Context, code, codeVerifier string, isManual bool, port int) (*ClaudeTokenResponse, error)

ExchangeClaudeCodeForTokens exchanges an authorization code for OAuth tokens.

type CopilotDeviceFlow

type CopilotDeviceFlow struct {
	Domain          string
	EnterpriseURL   string
	VerificationURI string
	UserCode        string
	DeviceCode      string
	Interval        time.Duration
}

func StartCopilotDeviceFlow

func StartCopilotDeviceFlow(ctx context.Context, enterpriseURL string) (*CopilotDeviceFlow, error)

type Info

type Info struct {
	ProviderID    string    `json:"provider_id"`
	Type          string    `json:"type"`
	AccessToken   string    `json:"access_token,omitempty"`
	RefreshToken  string    `json:"refresh_token,omitempty"`
	EnterpriseURL string    `json:"enterprise_url,omitempty"`
	ExpiresAt     time.Time `json:"expires_at,omitempty"`
	UpdatedAt     time.Time `json:"updated_at"`
}

func PollCopilotDeviceFlow

func PollCopilotDeviceFlow(ctx context.Context, flow *CopilotDeviceFlow) (*Info, error)

func RefreshClaudeToken added in v1.1.34

func RefreshClaudeToken(ctx context.Context, refreshToken string) (*Info, error)

RefreshClaudeToken refreshes an expired access token using the refresh token.

func (*Info) IsExpired added in v1.1.34

func (i *Info) IsExpired() bool

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

type Store

type Store struct {
	// contains filtered or unexported fields
}

func DefaultStore

func DefaultStore() *Store

func NewStore

func NewStore(path string) *Store

func (*Store) Delete

func (s *Store) Delete(providerID string) error

func (*Store) HasUsableToken

func (s *Store) HasUsableToken(providerID string) (bool, error)

func (*Store) Load

func (s *Store) Load(providerID string) (*Info, error)

func (*Store) Save

func (s *Store) Save(info *Info) error

Jump to

Keyboard shortcuts

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