auth

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthBaseURL = func() string {
	if v := viper.GetString("auth-url"); v != "" {
		return v
	}
	return "https://eu.prod.surfe.com"
}

AuthBaseURL returns the base URL for authentication and API calls. Override via config file (auth-url), env var (SURFER_AUTH_URL), or --auth-url flag.

View Source
var ClientID = func() string {
	if v := viper.GetString("client-id"); v != "" {
		return v
	}
	return "hubspot"
}

ClientID returns the OAuth client ID. Override via config file (client-id), env var (SURFER_CLIENT_ID), or --client-id flag.

View Source
var LoginTimeout = 2 * time.Minute
View Source
var OpenBrowserFunc = openBrowserDefault

OpenBrowserFunc can be overridden in tests to prevent opening a real browser.

Functions

func ClearTokens

func ClearTokens() error

func DecodeTokenClaims

func DecodeTokenClaims(token string) (map[string]any, error)

DecodeTokenClaims parses the claims from a JWT access token WITHOUT verifying its signature. It is for local display only (e.g. `surfer whoami`) — never use it for authorization decisions. Returns an error for opaque (non-JWT) tokens.

func GetAccessToken

func GetAccessToken() (string, error)

GetAccessToken returns a valid access token, refreshing if expired. Falls back to SURFE_API_KEY env var for server-to-server usage.

func IsLoggedIn

func IsLoggedIn() bool

func Logout

func Logout(accessToken string) error

func SaveTokens

func SaveTokens(store *TokenStore) error

Types

type TokenStore

type TokenStore 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"`
}

func LoadTokens

func LoadTokens() (*TokenStore, error)

func RefreshTokens

func RefreshTokens(refreshToken string) (*TokenStore, error)

func StartLogin

func StartLogin() (*TokenStore, error)

StartLogin opens the browser for OAuth authorization and waits for the callback. Uses port 0 (OS-assigned) like wrangler/gh/gcloud to avoid port conflicts.

Jump to

Keyboard shortcuts

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