Documentation
¶
Overview ¶
Package auth provides authentication functionality for GitHubby
Index ¶
- Constants
- func FormatTokenSource(source TokenSource) string
- func GetDeviceFlowInstructions(code *device.CodeResponse, hostname string) string
- func MaskToken(token string) string
- func OpenBrowser(url string) error
- func RequestDeviceCode(ctx context.Context) (*device.CodeResponse, error)
- type AuthenticatedUser
- type DeviceFlowOptions
- type DeviceFlowResult
- type Storage
- type TokenResult
- type TokenSource
Constants ¶
const ( // DefaultHostname is the default GitHub hostname DefaultHostname = "github.com" // EnvGitHubToken is the environment variable for GitHub token EnvGitHubToken = "GITHUB_TOKEN" )
const ( // GitHubOAuthClientID is the OAuth App client ID for GitHubby // This is intentionally public - device flow doesn't require a secret // To register your own OAuth App: https://github.com/settings/developers GitHubOAuthClientID = "Ov23liwoBdsJgs7M7kLS" // DefaultScopes are the OAuth scopes requested during authentication // - repo: Full control of private repositories (needed for sync) // - read:org: Read org membership (needed for org sync) DefaultScopes = "repo read:org" )
const ( // KeyringServiceName is the service name used in the system keychain KeyringServiceName = "githubby" // ConfigFileName is the name of the config file ConfigFileName = ".githubby.yaml" )
Variables ¶
This section is empty.
Functions ¶
func FormatTokenSource ¶
func FormatTokenSource(source TokenSource) string
FormatTokenSource returns a human-readable description of the token source
func GetDeviceFlowInstructions ¶
func GetDeviceFlowInstructions(code *device.CodeResponse, hostname string) string
GetDeviceFlowInstructions returns user-friendly instructions for device flow
func OpenBrowser ¶
OpenBrowser opens the default browser to the specified URL
func RequestDeviceCode ¶
func RequestDeviceCode(ctx context.Context) (*device.CodeResponse, error)
RequestDeviceCode requests a device code from GitHub for OAuth This is the first step of the device flow - returns quickly with a code to show user
Types ¶
type AuthenticatedUser ¶
AuthenticatedUser contains information about the authenticated user
func ValidateToken ¶
ValidateToken checks if a token is valid by making a test API call
type DeviceFlowOptions ¶
type DeviceFlowOptions struct {
// ClientID is the OAuth App client ID
ClientID string
// Scopes are the OAuth scopes to request
Scopes []string
// Hostname is the GitHub hostname (for Enterprise)
Hostname string
// OnCode is called when the user code is ready
OnCode func(code *device.CodeResponse)
// OnPoll is called during polling
OnPoll func(interval time.Duration)
}
DeviceFlowOptions configures the device flow authentication
func DefaultDeviceFlowOptions ¶
func DefaultDeviceFlowOptions() *DeviceFlowOptions
DefaultDeviceFlowOptions returns options with sensible defaults
type DeviceFlowResult ¶
DeviceFlowResult contains the result of a device flow authentication
func PollForToken ¶
func PollForToken(ctx context.Context, code *device.CodeResponse) (*DeviceFlowResult, error)
PollForToken polls GitHub waiting for user to authorize the device code This blocks until the user completes authorization or the code expires
func RunDeviceFlow ¶
func RunDeviceFlow(ctx context.Context, opts *DeviceFlowOptions) (*DeviceFlowResult, error)
RunDeviceFlow performs OAuth device flow authentication
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage handles secure token storage
func NewStorageWithConfig ¶
NewStorageWithConfig creates a Storage instance with a custom config path (for testing)
func (*Storage) DeleteToken ¶
DeleteToken removes the stored token for a hostname
func (*Storage) GetStorageLocation ¶
GetStorageLocation returns a description of where tokens are stored
func (*Storage) GetToken ¶
func (s *Storage) GetToken(hostname string) (string, TokenSource, error)
GetToken retrieves the stored token for a hostname
func (*Storage) IsKeychainAvailable ¶
IsKeychainAvailable returns whether the system keychain is available
type TokenResult ¶
type TokenResult struct {
Token string
Source TokenSource
Hostname string
}
TokenResult contains the resolved token and its source
type TokenSource ¶
type TokenSource string
TokenSource represents where the token was obtained from
const ( TokenSourceFlag TokenSource = "flag" TokenSourceEnv TokenSource = "environment" TokenSourceKeychain TokenSource = "keychain" TokenSourceConfig TokenSource = "config" TokenSourceNone TokenSource = "none" )