{"modulePath":"github.com/Flagsmith/flagsmith-cli","version":"v1.1.1-0.20260730103710-c6179254e1e8","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package auth\n\n## Constants\n\n```go\nconst (\n\t// ClientID is the first-party public OAuth client pre-registered on every\n\t// Flagsmith instance.\n\tClientID = \"flagsmith-cli\"\n\n\tScope = \"admin-api\"\n)\n```\n\n```go\nconst (\n\n\t// SourceKeychain labels credentials loaded from the OS keychain.\n\tSourceKeychain = \"keychain\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\tErrServerSideKey   = errors.New(\"FLAGSMITH_API_KEY contains a server-side environment key\")\n\tErrLegacyAuthtoken = errors.New(\"FLAGSMITH_API_KEY contains a legacy user authtoken, which is not supported\")\n\tErrNotMasterKey    = errors.New(\"FLAGSMITH_API_KEY is not a Master API key (expected {prefix}.{secret})\")\n)\n```\nValidateMasterKey's rejections.\n\n```go\nvar (\n\t// ErrNotLoggedIn means no credential is available for the instance.\n\tErrNotLoggedIn = errors.New(\"not logged in\")\n\n\t// ErrKeychainUnavailable means the OS keychain could not be used. Login\n\t// sessions are stored only in the keychain; when it is unavailable the\n\t// user must supply credentials via FLAGSMITH_API_KEY instead.\n\tErrKeychainUnavailable = errors.New(\"OS keychain unavailable\")\n)\n```\n\n```go\nvar ErrRefreshFailed = errors.New(\"refreshing session failed\")\n```\nErrRefreshFailed means an expired session's refresh-token exchange failed, so the stored session is unusable.\n\n## Functions\n\n```go\nfunc Delete(apiURL string) error\n```\nDelete removes the stored session for an instance. Missing is not an error.\n\n```go\nfunc KeychainAvailable() bool\n```\nKeychainAvailable probes the OS keychain with a write+delete round-trip.\n\n```go\nfunc Revoke(ctx context.Context, httpClient *http.Client, c *Credentials) error\n```\nRevoke invalidates the refresh token (and its access tokens) server-side.\n\n```go\nfunc Save(c *Credentials) error\n```\nSave stores a login session for its instance in the OS keychain.\n\n```go\nfunc ValidateMasterKey(value string) error\n```\nValidateMasterKey checks that a FLAGSMITH\\_API\\_KEY value is a Master API key. Each Admin API env var maps to exactly one credential kind, so the scheme is never guessed from token shape; this only turns common paste-mistakes into actionable errors instead of a silently rejected request.\n\n## Types\n\n```go\ntype Credentials struct {\n\tKind         Kind      `json:\"kind,omitempty\"` // empty means KindOAuth (back-compat)\n\tAPIURL       string    `json:\"api_url\"`\n\tAccessToken  string    `json:\"access_token,omitempty\"`\n\tRefreshToken string    `json:\"refresh_token,omitempty\"`\n\tExpiresAt    time.Time `json:\"expires_at,omitzero\"`\n\tMasterKey    string    `json:\"master_key,omitempty\"`\n}\n```\nCredentials is a stored login session for one Flagsmith instance.\n\n```go\nfunc EnsureFresh(ctx context.Context, httpClient *http.Client, c *Credentials) (creds *Credentials, refreshed bool, err error)\n```\nEnsureFresh refreshes the access token if it is expired or about to expire. The server rotates refresh tokens (120s grace), so refreshed credentials must be saved by the caller.\n\n```go\nfunc Load(apiURL string) (*Credentials, error)\n```\nLoad returns the stored session for an instance, or ErrNotLoggedIn when the keychain holds none. A keychain that cannot be read at all is reported as ErrKeychainUnavailable: telling that user to log in sends them through the whole browser flow only to fail at Save.\n\n```go\nfunc Login(ctx context.Context, httpClient *http.Client, apiURL string, openBrowser func(string) error, out io.Writer) (*Credentials, error)\n```\nLogin runs the authorization-code + PKCE flow on a loopback listener. openBrowser may be nil (--no-browser); the URL is always written to out.\n\n```go\nfunc (c *Credentials) EffectiveKind() Kind\n```\nEffectiveKind returns the credential kind, defaulting to KindOAuth for entries stored before kinds existed.\n\n```go\nfunc (c *Credentials) Token() string\n```\n\n```go\ntype Kind string\n```\nKind is the credential type, which determines the Authorization scheme.\n\n```go\nconst (\n\t// Browser-login session: Bearer access token + refresh token.\n\tKindOAuth Kind = \"oauth\"\n\t// Organisation Master API key: `Api-Key {prefix}.{secret}`.\n\tKindMaster Kind = \"master\"\n\t// OAuth-style access token from FLAGSMITH_ACCESS_TOKEN (OIDC-exchanged in CI): `Bearer {token}`.\n\tKindBearer Kind = \"bearer\"\n)\n```\n\n```go\ntype Metadata struct {\n\tIssuer                string `json:\"issuer\"`\n\tAuthorizationEndpoint string `json:\"authorization_endpoint\"`\n\tTokenEndpoint         string `json:\"token_endpoint\"`\n\tRevocationEndpoint    string `json:\"revocation_endpoint\"`\n}\n```\nMetadata is a subset of RFC 8414 authorization server metadata.\n\n```go\nfunc Discover(ctx context.Context, httpClient *http.Client, apiURL string) (*Metadata, error)\n```\n\n","path":"github.com/Flagsmith/flagsmith-cli/internal/auth","name":"auth","synopsis":"","isRedistributable":true}
