auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package auth - OAuth 2.0 Device Flow implementation

Package auth handles authentication for GitScrum CLI

Index

Constants

View Source
const (
	// OAuth endpoints (matching Laravel API routes)
	DeviceCodeEndpoint = "/oauth/device/code"
	TokenEndpoint      = "/oauth/device/token"

	// Grant types
	GrantTypeDeviceCode = "urn:ietf:params:oauth:grant-type:device_code"
)

Variables

View Source
var (
	ErrNotAuthenticated = errors.New("not authenticated. Run 'gitscrum login' to authenticate")
	ErrTokenExpired     = errors.New("token expired. Run 'gitscrum login' to re-authenticate")
)

Errors

Functions

func DeleteToken

func DeleteToken() error

DeleteToken removes the token file

func SaveToken

func SaveToken(token *Token) error

SaveToken writes the token to file

Types

type DeviceAuthenticator

type DeviceAuthenticator struct {
	BaseURL    string
	ClientID   string
	Scopes     string
	HTTPClient *http.Client
}

DeviceAuthenticator handles OAuth Device Flow

func NewDeviceAuthenticator

func NewDeviceAuthenticator(baseURL, clientID, scopes string) *DeviceAuthenticator

NewDeviceAuthenticator creates a new authenticator

func (*DeviceAuthenticator) OpenBrowser

func (a *DeviceAuthenticator) OpenBrowser(verificationURI string) error

OpenBrowser opens the verification URL in the default browser

func (*DeviceAuthenticator) PollForToken

func (a *DeviceAuthenticator) PollForToken(deviceCode string, interval, expiresIn int) (*Token, error)

PollForToken polls the token endpoint until authorization is complete

func (*DeviceAuthenticator) StartDeviceFlow

func (a *DeviceAuthenticator) StartDeviceFlow() (*DeviceCodeResponse, error)

StartDeviceFlow initiates the device authorization flow

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete,omitempty"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

DeviceCodeResponse from device authorization endpoint

type Token

type Token struct {
	AccessToken  string    `json:"access_token"`
	TokenType    string    `json:"token_type"`
	ExpiresIn    int       `json:"expires_in"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	CreatedAt    time.Time `json:"created_at"`
}

Token represents the OAuth token

func LoadToken

func LoadToken() (*Token, error)

LoadToken reads the token from environment variable or file For CI/CD environments, set GITSCRUM_ACCESS_TOKEN environment variable

func (*Token) IsExpired

func (t *Token) IsExpired() bool

IsExpired checks if the token has expired

Jump to

Keyboard shortcuts

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