Documentation
¶
Index ¶
- Constants
- Variables
- func CurrentAuthBaseURL() string
- func CurrentOAuthClientID() string
- func DeleteTokens() error
- func GetAuthenticatedClient(opts ...option.RequestOption) (*kernel.Client, error)
- func SaveTokens(tokens *TokenStorage) error
- type AuthResult
- type OAuthConfig
- type TokenResponse
- type TokenStorage
Constants ¶
const ( // MCP Server OAuth endpoints (which proxy to Clerk) DefaultAuthBaseURL = "https://auth.onkernel.com" // OAuth client configuration DefaultClientID = "hmFrJn9hKDV2N02M" RedirectURI = "http://localhost" )
const ( KeyringService = "kernel-cli" KeyringUser = "oauth-tokens" )
const ( SourceKeychain = "OS Keychain" SourceFile = "Local file (~/.config/kernel/credentials)" )
Token storage sources, as reported in TokenStorage.Source.
Variables ¶
var ErrAuthorizationDenied = errors.New("authorization denied; no new credentials were saved")
ErrAuthorizationDenied indicates that consent was declined, without issuing new credentials.
Functions ¶
func CurrentAuthBaseURL ¶ added in v0.19.3
func CurrentAuthBaseURL() string
CurrentAuthBaseURL returns the OAuth server base URL for new login flows.
func CurrentOAuthClientID ¶ added in v0.19.3
func CurrentOAuthClientID() string
CurrentOAuthClientID returns the OAuth client ID for new login flows.
func GetAuthenticatedClient ¶
func GetAuthenticatedClient(opts ...option.RequestOption) (*kernel.Client, error)
GetAuthenticatedClient returns a Kernel client with appropriate authentication
func SaveTokens ¶
func SaveTokens(tokens *TokenStorage) error
SaveTokens stores authentication tokens in the OS keychain, or in the credentials file when the keychain refuses them (for example when they are too large). Whichever store is written becomes the one LoadTokens reads.
Types ¶
type AuthResult ¶
type AuthResult struct {
Code string `json:"code"`
OrgID string `json:"org_id,omitempty"`
AccessScope string `json:"access_scope,omitempty"`
ProjectID string `json:"project_id,omitempty"`
}
AuthResult represents the result data passed through the callback channel
type OAuthConfig ¶
type OAuthConfig struct {
Config *oauth2.Config
Verifier string
State string
AuthBaseURL string
OAuthClientID string
}
OAuthConfig represents the OAuth2 configuration
func NewOAuthConfig ¶
func NewOAuthConfig() (*OAuthConfig, error)
NewOAuthConfig creates a new OAuth configuration with PKCE
func (*OAuthConfig) StartOAuthFlow ¶
func (oc *OAuthConfig) StartOAuthFlow(ctx context.Context) (*TokenStorage, error)
StartOAuthFlow initiates the OAuth flow with browser redirect
type TokenResponse ¶
type TokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
OrgID string `json:"org_id"`
AccessScope string `json:"access_scope"`
ProjectID string `json:"project_id"`
}
TokenResponse represents the OAuth token response
type TokenStorage ¶
type TokenStorage struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt time.Time `json:"expires_at"`
OrgID string `json:"org_id"`
AccessScope string `json:"access_scope,omitempty"`
ProjectID string `json:"project_id,omitempty"`
AuthBaseURL string `json:"auth_base_url,omitempty"`
OAuthClientID string `json:"oauth_client_id,omitempty"`
Projects []string `json:"projects,omitempty"` // projects a native grant is limited to; empty means all
// ScopeRecorded is set by CLI versions that record Projects. Credentials
// saved without it may be limited to projects the CLI does not know about.
ScopeRecorded bool `json:"scope_recorded,omitempty"`
// SavedAt tells which of the keyring and the credentials file is current
// when both hold credentials.
SavedAt time.Time `json:"saved_at,omitzero"`
// Source is where LoadTokens found the credentials; it is not stored.
Source string `json:"-"`
}
TokenStorage represents stored authentication tokens
func LoadTokens ¶
func LoadTokens() (*TokenStorage, error)
LoadTokens retrieves authentication tokens from the keychain or the credentials file. When both hold credentials, the newer copy wins.
func RefreshTokens ¶
func RefreshTokens(ctx context.Context, tokens *TokenStorage) (*TokenStorage, error)
RefreshTokens refreshes the access token using the refresh token
func (*TokenStorage) IsExpired ¶
func (t *TokenStorage) IsExpired() bool
IsExpired checks if the access token is expired (with 5 minute buffer)