Documentation
¶
Index ¶
- Constants
- func GenerateState() (string, error)
- func GetTokenFromConfig(cfg *config.Config) (string, bool)
- func GetTokenFromEnv() (string, bool)
- func OpenBrowser(url string) error
- type OAuthClient
- func (c *OAuthClient) ExchangeCode(ctx context.Context, code string) (*Token, error)
- func (c *OAuthClient) GetState() string
- func (c *OAuthClient) InitAuthFlow() error
- func (c *OAuthClient) RefreshToken(ctx context.Context, refreshToken string) (*Token, error)
- func (c *OAuthClient) RevokeToken(ctx context.Context, token string, tokenTypeHint string) error
- func (c *OAuthClient) StartAuthFlow(ctx context.Context) (string, error)
- func (c *OAuthClient) StartCallbackServer(ctx context.Context, expectedState string) (string, error)
- type OAuthConfig
- type PKCEParams
- type Storage
- type Token
- type TokenInfo
- type TokenSource
Constants ¶
const DefaultCallbackPort = config.DefaultOAuthCallbackPort
DefaultCallbackPort is the default port for the OAuth2 callback server.
Variables ¶
This section is empty.
Functions ¶
func GenerateState ¶
GenerateState generates a random state parameter for CSRF protection
func GetTokenFromConfig ¶
GetTokenFromConfig checks for token in config file
func GetTokenFromEnv ¶
GetTokenFromEnv checks for token in environment variables Checks: NR_API_TOKEN, NODERINGS_API_TOKEN
func OpenBrowser ¶
OpenBrowser opens the authorization URL in the default browser. On failure it returns a short error without embedding the URL; callers print the URL once.
Types ¶
type OAuthClient ¶
type OAuthClient struct {
// contains filtered or unexported fields
}
OAuthClient handles OAuth2 authentication flows with PKCE
func NewOAuthClient ¶
func NewOAuthClient(config *OAuthConfig) *OAuthClient
NewOAuthClient creates a new OAuth client
func (*OAuthClient) ExchangeCode ¶
ExchangeCode exchanges authorization code for access token using PKCE
func (*OAuthClient) GetState ¶
func (c *OAuthClient) GetState() string
GetState returns the current state value (for callback verification)
func (*OAuthClient) InitAuthFlow ¶
func (c *OAuthClient) InitAuthFlow() error
InitAuthFlow initializes PKCE and state parameters (called before starting callback server)
func (*OAuthClient) RefreshToken ¶
RefreshToken exchanges refresh token for new access token
func (*OAuthClient) RevokeToken ¶
RevokeToken revokes an access or refresh token
func (*OAuthClient) StartAuthFlow ¶
func (c *OAuthClient) StartAuthFlow(ctx context.Context) (string, error)
StartAuthFlow generates the authorization URL (called after callback server has updated redirect URL)
func (*OAuthClient) StartCallbackServer ¶
func (c *OAuthClient) StartCallbackServer(ctx context.Context, expectedState string) (string, error)
StartCallbackServer starts a local HTTP server to receive the authorization callback Uses a fixed port (DefaultCallbackPort) for simplicity and consistency
type OAuthConfig ¶
type OAuthConfig struct {
ClientID string
AuthURL string
TokenURL string
RedirectURL string
Scopes []string
APIBaseURL string
Debug bool // Enable debug logging for troubleshooting
TLSInsecure bool // Skip TLS certificate verification (development only)
}
OAuthConfig holds OAuth2 configuration
type PKCEParams ¶
PKCEParams holds PKCE code verifier and challenge
func GeneratePKCE ¶
func GeneratePKCE() (*PKCEParams, error)
GeneratePKCE generates PKCE code verifier and challenge
type Storage ¶
type Storage struct {
// contains filtered or unexported fields
}
Storage handles secure token storage
func NewStorage ¶
NewStorage creates a new token storage
func (*Storage) DeleteToken ¶
DeleteToken removes a token from storage
type Token ¶
type Token struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt time.Time `json:"expires_at"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
}
Token represents an authentication token
type TokenInfo ¶
type TokenInfo struct {
Token string
Source TokenSource
IsOAuthToken bool // true if this is an OAuth token with refresh capability
OAuthToken *Token // Only set if IsOAuthToken is true
}
TokenInfo contains token information and its source
func LoadTokenInfo ¶
LoadTokenInfo loads token from various sources in priority order: 1. Environment variables (highest priority) - for service account tokens 2. Config file - for service account tokens 3. OAuth token storage - for OAuth tokens (via 'nr auth login')
Both OAuth and Service Account tokens are fully supported. The priority order determines which token is used when multiple are available.
type TokenSource ¶
type TokenSource string
TokenSource represents where a token was loaded from
const ( TokenSourceEnvVar TokenSource = "environment_variable" TokenSourceConfigFile TokenSource = "config_file" TokenSourceOAuth TokenSource = "oauth" TokenSourceUnknown TokenSource = "unknown" )