Documentation
¶
Index ¶
- Constants
- type AuthResult
- type Client
- func (c *Client) ClearTokens() error
- func (c *Client) GetAccessToken(ctx context.Context) (string, error)
- func (c *Client) GetStorageBackend() StorageBackend
- func (c *Client) GetTokenPath() string
- func (c *Client) GetTokens() (*Tokens, error)
- func (c *Client) HasClientCredentials() bool
- func (c *Client) IsAuthenticated() bool
- func (c *Client) LoadTokens() (*Tokens, error)
- func (c *Client) Login(ctx context.Context) (*AuthResult, error)
- func (c *Client) LoginWithClientCredentials(ctx context.Context) (*AuthResult, error)
- func (c *Client) RefreshTokens(ctx context.Context) (*Tokens, error)
- func (c *Client) SaveTokens(tokens *Tokens) error
- func (c *Client) SetTokenPath(path string)
- func (c *Client) TokensExist() bool
- type StorageBackend
- type Tokens
- type UserInfo
Constants ¶
const ( // DefaultPort is the default port for the callback server DefaultPort = 5747 // DefaultCallbackPath is the default path for the OIDC callback DefaultCallbackPath = "/auth/sstart" // DefaultTimeout is the default timeout for the authentication flow DefaultTimeout = 5 * time.Minute )
const ( // TokenFileName is the name of the file where tokens are stored (fallback) TokenFileName = "tokens.json" // ConfigDirName is the name of the directory where sstart stores its configuration ConfigDirName = "sstart" // KeyringService is the service name used for keyring storage KeyringService = "sstart" // KeyringUser is the user/account name used for keyring storage KeyringUser = "sso-tokens" )
const SSOSecretEnvVar = "SSTART_SSO_SECRET"
SSOSecretEnvVar is the environment variable name for the OIDC client secret
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthResult ¶
AuthResult holds the result of a successful authentication
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an OIDC client for SSO authentication
func NewClient ¶
func NewClient(cfg *config.OIDCConfig) (*Client, error)
NewClient creates a new OIDC client from the provided configuration
func (*Client) ClearTokens ¶
ClearTokens removes the stored tokens from both keyring and file
func (*Client) GetAccessToken ¶
GetAccessToken returns the current access token, refreshing if needed
func (*Client) GetStorageBackend ¶
func (c *Client) GetStorageBackend() StorageBackend
GetStorageBackend returns the current storage backend being used
func (*Client) GetTokenPath ¶
GetTokenPath returns the current token storage path (file storage)
func (*Client) HasClientCredentials ¶
HasClientCredentials returns true if the client has both client ID and client secret configured This indicates the client can use the client credentials flow for non-interactive authentication
func (*Client) IsAuthenticated ¶
IsAuthenticated checks if valid tokens exist
func (*Client) LoadTokens ¶
LoadTokens loads the tokens, trying keyring first then falling back to file
func (*Client) Login ¶
func (c *Client) Login(ctx context.Context) (*AuthResult, error)
Login initiates the OIDC login flow It starts a local HTTP server to handle the callback, opens the browser for authentication, and returns the tokens upon successful authentication
func (*Client) LoginWithClientCredentials ¶
func (c *Client) LoginWithClientCredentials(ctx context.Context) (*AuthResult, error)
LoginWithClientCredentials performs the OAuth2 client credentials flow This is used for non-interactive (machine-to-machine) authentication
func (*Client) RefreshTokens ¶
RefreshTokens refreshes the access token using the refresh token
func (*Client) SaveTokens ¶
SaveTokens saves the tokens, trying keyring first then falling back to file
func (*Client) SetTokenPath ¶
SetTokenPath sets a custom path for storing tokens (file storage)
func (*Client) TokensExist ¶
TokensExist checks if tokens exist in either keyring or file
type StorageBackend ¶
type StorageBackend string
StorageBackend represents the type of storage being used
const ( // StorageBackendKeyring indicates tokens are stored in the system keyring StorageBackendKeyring StorageBackend = "keyring" // StorageBackendFile indicates tokens are stored in a file StorageBackendFile StorageBackend = "file" )
type Tokens ¶
type Tokens struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token,omitempty"`
IDToken string `json:"id_token,omitempty"`
TokenType string `json:"token_type,omitempty"`
Expiry time.Time `json:"expiry,omitempty"`
}
Tokens represents the OIDC tokens received after authentication
type UserInfo ¶
type UserInfo struct {
Subject string `json:"sub"`
Name string `json:"name,omitempty"`
GivenName string `json:"given_name,omitempty"`
FamilyName string `json:"family_name,omitempty"`
PreferredUsername string `json:"preferred_username,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"email_verified,omitempty"`
}
UserInfo represents the user information from the OIDC provider