auth

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MCP Server OAuth endpoints (which proxy to Clerk)
	DefaultAuthBaseURL = "https://auth.onkernel.com"

	// OAuth client configuration
	DefaultClientID = "hmFrJn9hKDV2N02M"
	RedirectURI     = "http://localhost"

	// OAuth scopes - openid for the MCP server flow
	DefaultScope = "openid email"
)
View Source
const (
	KeyringService = "kernel-cli"
	KeyringUser    = "oauth-tokens"
)

Variables

This section is empty.

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 DeleteTokens

func DeleteTokens() error

DeleteTokens removes stored authentication tokens

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 securely in the OS keychain

Types

type AuthResult

type AuthResult struct {
	Code  string `json:"code"`
	OrgID string `json:"org_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"`
}

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"`
	AuthBaseURL   string    `json:"auth_base_url,omitempty"`
	OAuthClientID string    `json:"oauth_client_id,omitempty"`
}

TokenStorage represents stored authentication tokens

func LoadTokens

func LoadTokens() (*TokenStorage, error)

LoadTokens retrieves authentication tokens from secure storage

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)

Jump to

Keyboard shortcuts

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