{"modulePath":"github.com/kernel/cli","version":"v0.54.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package auth\n\n## Constants\n\n```go\nconst (\n\t// MCP Server OAuth endpoints (which proxy to Clerk)\n\tDefaultAuthBaseURL = \"https://auth.onkernel.com\"\n\n\t// OAuth client configuration\n\tDefaultClientID = \"hmFrJn9hKDV2N02M\"\n\tRedirectURI     = \"http://localhost\"\n)\n```\n\n```go\nconst (\n\tKeyringService = \"kernel-cli\"\n\tKeyringUser    = \"oauth-tokens\"\n)\n```\n\n```go\nconst (\n\tSourceKeychain = \"OS Keychain\"\n\tSourceFile     = \"Local file (~/.config/kernel/credentials)\"\n)\n```\nToken storage sources, as reported in TokenStorage.Source.\n\n## Variables\n\n```go\nvar ErrAuthorizationDenied = errors.New(\"authorization denied; no new credentials were saved\")\n```\nErrAuthorizationDenied indicates that consent was declined, without issuing new credentials.\n\n## Functions\n\n```go\nfunc CurrentAuthBaseURL() string\n```\nCurrentAuthBaseURL returns the OAuth server base URL for new login flows.\n\n```go\nfunc CurrentOAuthClientID() string\n```\nCurrentOAuthClientID returns the OAuth client ID for new login flows.\n\n```go\nfunc DeleteTokens() error\n```\nDeleteTokens removes stored authentication tokens\n\n```go\nfunc GetAuthenticatedClient(opts ...option.RequestOption) (*kernel.Client, error)\n```\nGetAuthenticatedClient returns a Kernel client with appropriate authentication\n\n```go\nfunc SaveTokens(tokens *TokenStorage) error\n```\nSaveTokens 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.\n\n## Types\n\n```go\ntype AuthResult struct {\n\tCode        string `json:\"code\"`\n\tOrgID       string `json:\"org_id,omitempty\"`\n\tAccessScope string `json:\"access_scope,omitempty\"`\n\tProjectID   string `json:\"project_id,omitempty\"`\n}\n```\nAuthResult represents the result data passed through the callback channel\n\n```go\ntype OAuthConfig struct {\n\tConfig        *oauth2.Config\n\tVerifier      string\n\tState         string\n\tAuthBaseURL   string\n\tOAuthClientID string\n}\n```\nOAuthConfig represents the OAuth2 configuration\n\n```go\nfunc NewOAuthConfig() (*OAuthConfig, error)\n```\nNewOAuthConfig creates a new OAuth configuration with PKCE\n\n```go\nfunc (oc *OAuthConfig) StartOAuthFlow(ctx context.Context) (*TokenStorage, error)\n```\nStartOAuthFlow initiates the OAuth flow with browser redirect\n\n```go\ntype TokenResponse struct {\n\tAccessToken  string `json:\"access_token\"`\n\tRefreshToken string `json:\"refresh_token\"`\n\tExpiresIn    int    `json:\"expires_in\"`\n\tTokenType    string `json:\"token_type\"`\n\tOrgID        string `json:\"org_id\"`\n\tAccessScope  string `json:\"access_scope\"`\n\tProjectID    string `json:\"project_id\"`\n}\n```\nTokenResponse represents the OAuth token response\n\n```go\ntype TokenStorage struct {\n\tAccessToken   string    `json:\"access_token\"`\n\tRefreshToken  string    `json:\"refresh_token\"`\n\tExpiresAt     time.Time `json:\"expires_at\"`\n\tOrgID         string    `json:\"org_id\"`\n\tAccessScope   string    `json:\"access_scope,omitempty\"`\n\tProjectID     string    `json:\"project_id,omitempty\"`\n\tAuthBaseURL   string    `json:\"auth_base_url,omitempty\"`\n\tOAuthClientID string    `json:\"oauth_client_id,omitempty\"`\n\tProjects      []string  `json:\"projects,omitempty\"` // projects a native grant is limited to; empty means all\n\t// ScopeRecorded is set by CLI versions that record Projects. Credentials\n\t// saved without it may be limited to projects the CLI does not know about.\n\tScopeRecorded bool `json:\"scope_recorded,omitempty\"`\n\t// SavedAt tells which of the keyring and the credentials file is current\n\t// when both hold credentials.\n\tSavedAt time.Time `json:\"saved_at,omitzero\"`\n\t// Source is where LoadTokens found the credentials; it is not stored.\n\tSource string `json:\"-\"`\n}\n```\nTokenStorage represents stored authentication tokens\n\n```go\nfunc LoadTokens() (*TokenStorage, error)\n```\nLoadTokens retrieves authentication tokens from the keychain or the credentials file. When both hold credentials, the newer copy wins.\n\n```go\nfunc RefreshTokens(ctx context.Context, tokens *TokenStorage) (*TokenStorage, error)\n```\nRefreshTokens refreshes the access token using the refresh token\n\n```go\nfunc (t *TokenStorage) IsExpired() bool\n```\nIsExpired checks if the access token is expired (with 5 minute buffer)\n\n","path":"github.com/kernel/cli/pkg/auth","name":"auth","synopsis":"","isRedistributable":true}
