auth

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Well-known public client for the Kontext CLI. No secret.
	DefaultClientID = "app_a4fb6d20-e937-450f-aa19-db585405aa92"

	// Default API base URL.
	DefaultIssuerURL = "https://api.kontext.security"
)

Variables

This section is empty.

Functions

func ClearSession

func ClearSession() error

ClearSession removes the stored session from the system keyring.

func SaveSession

func SaveSession(session *Session) error

SaveSession stores the session in the system keyring.

Types

type LoginResult

type LoginResult struct {
	Session *Session
}

LoginResult is the output of a successful login flow.

func Login

func Login(ctx context.Context, issuerURL, clientID string, scopes ...string) (*LoginResult, error)

Login performs the browser-based OAuth PKCE login flow. When scopes are omitted, the default CLI login scopes are used.

type OAuthMetadata

type OAuthMetadata struct {
	Issuer                string `json:"issuer"`
	AuthorizationEndpoint string `json:"authorization_endpoint"`
	TokenEndpoint         string `json:"token_endpoint"`
	JwksURI               string `json:"jwks_uri"`
}

OAuthMetadata is the response from /.well-known/oauth-authorization-server.

func DiscoverEndpoints

func DiscoverEndpoints(ctx context.Context, baseURL string) (*OAuthMetadata, error)

DiscoverEndpoints fetches OAuth authorization server metadata.

type Session

type Session struct {
	User         UserInfo  `json:"user"`
	IssuerURL    string    `json:"issuer_url"`
	Subject      string    `json:"subject"`
	AccessToken  string    `json:"access_token"`
	IDToken      string    `json:"id_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresAt    time.Time `json:"expires_at"`
}

Session holds the authenticated user's OIDC identity and tokens.

func LoadSession

func LoadSession() (*Session, error)

LoadSession reads the stored session from the system keyring.

func Preflight

func Preflight(ctx context.Context) (*Session, error)

Preflight loads the session and refreshes if needed. Returns a ready-to-use session.

func RefreshSession

func RefreshSession(ctx context.Context, session *Session) (*Session, error)

RefreshSession attempts to refresh an expired session using the refresh token.

func (*Session) DisplayIdentity added in v0.4.0

func (s *Session) DisplayIdentity() string

DisplayIdentity returns the human-readable identity for terminal output.

func (*Session) IdentityKey added in v0.4.0

func (s *Session) IdentityKey() (string, error)

IdentityKey returns the stable identity used for backend session attribution.

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired returns true if the access token has expired or will expire within the buffer.

type UserInfo added in v0.4.0

type UserInfo struct {
	Name  string `json:"name"`
	Email string `json:"email"`
}

UserInfo holds the user identity extracted from the ID token.

Jump to

Keyboard shortcuts

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