auth

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 20 Imported by: ? 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

View Source
const (
	ProdGovcloudURL = "https://api-gov.resim.ai/v1/"
	ProdAPIURL      = "https://api.resim.ai/v1/"
	StagingAPIURL   = "https://api.resim.io/v1/"
	ProdAuthURL     = "https://resim.us.auth0.com/"
	DevAuthURL      = "https://resim-dev.us.auth0.com/"

	CredentialCacheFilename = "cache.json"

	DefaultDevInteractiveClientID     = "Rg1F0ZOCBmVYje4UVrS3BKIh4T2nCW9y"
	DefaultDevNonInteractiveClientID  = "LLNl3xsbNLSd16gQyYsiEn3tbLDZo1gj"
	DefaultProdInteractiveClientID    = "gTp1Y0kOyQ7QzIo2lZm0auGM6FJZZVvy"
	DefaultProdNonInteractiveClientID = "0Ip56H1LLAo6Dc6IfePaNzgpUxbJGyVI"

	// Viper/flag key names used for config binding.
	KeyURL                      = "url"
	KeyAuthURL                  = "auth-url"
	KeyClientID                 = "client-id"
	KeyClientSecret             = "client-secret"
	KeyUsername                 = "username"
	KeyPassword                 = "password"
	KeyAPIKey                   = "api-key"
	KeyDevInteractiveClient     = "dev-interactive-client"
	KeyProdInteractiveClient    = "prod-interactive-client"
	KeyDevNonInteractiveClient  = "dev-non-interactive-client"
	KeyProdNonInteractiveClient = "prod-non-interactive-client"
)

Variables

This section is empty.

Functions

func NewAPIClient

func NewAPIClient(ctx context.Context, cache CredentialCache, apiURL string) (*api.ClientWithResponses, error)

NewAPIClient creates an API client authenticated with the given credential cache.

func NewBFFClient

func NewBFFClient(ctx context.Context, cache CredentialCache, apiURL string) (graphql.Client, error)

NewBFFClient creates a BFF client authenticated with the given credential cache: GraphQL for user and machine tokens, the REST API for an API key.

Types

type AuthMode

type AuthMode string
const (
	ModeClientCredentials AuthMode = "clientcredentials"
	ModeDeviceCode        AuthMode = "devicecode"
	ModePassword          AuthMode = "password"
	ModeAPIKey            AuthMode = "apikey"
)

type AuthResult

type AuthResult struct {
	Cache  *CredentialCache
	APIURL string
}

func Authenticate

func Authenticate(ctx context.Context, cfg Config) (*AuthResult, error)

Authenticate performs OAuth2 authentication using the provided config. It returns an AuthResult containing the credential cache and the resolved API URL (which may differ from Config.APIURL if govcloud mode is enabled).

type Config

type Config struct {
	APIURL       string
	AuthURL      string
	ClientID     string
	ClientSecret string
	Username     string
	Password     string
	APIKey       string
	Govcloud     bool
	CacheDir     string

	DevInteractiveClientID     string
	ProdInteractiveClientID    string
	DevNonInteractiveClientID  string
	ProdNonInteractiveClientID string

	// AuthMode optionally overrides auth mode inference.
	// If empty, the mode is inferred from which credential fields are populated.
	AuthMode AuthMode

	// DeviceCodeOutput is the writer for device code prompts. Defaults to os.Stdout.
	DeviceCodeOutput io.Writer

	// DeviceCodeBrowserOpen opens a URL in the user's browser. Defaults to browser.OpenURL.
	DeviceCodeBrowserOpen func(string) error
}

func ConfigFromViper

func ConfigFromViper(v *viper.Viper, cacheDir string) Config

ConfigFromViper builds a Config from a viper instance. The cacheDir parameter specifies where credential caches are stored (e.g., os.ExpandEnv("$HOME/.signalflag")). This preserves viper.IsSet() semantics for auth mode detection, so CI environments with empty env vars behave correctly.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config pre-filled with production defaults.

type CredentialCache

type CredentialCache struct {
	Tokens      map[string]oauth2.Token `json:"tokens"`
	TokenSource oauth2.TokenSource
	ClientID    string
	// contains filtered or unexported fields
}

func (*CredentialCache) Load

func (c *CredentialCache) Load(cacheDir string) error

Load reads the credential cache from disk. Returns nil if the file does not exist. Returns an error if the file exists but is malformed or unreadable.

func (*CredentialCache) Save

func (c *CredentialCache) Save(cacheDir string) error

Save writes the credential cache to disk. Creates the cache directory if needed. It does nothing for an API key session, so the key is never written to disk.

Jump to

Keyboard shortcuts

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