auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const ServiceName = "notion-cli"

Variables

This section is empty.

Functions

func ResolveToken

func ResolveToken(flagToken, flagProfile string, cfg *config.Config, store KeyringStore) (string, error)

ResolveToken returns a Notion API token using the following precedence:

  1. flagToken (--token flag)
  2. NOTION_TOKEN env var
  3. NOTION_PROFILE env → keyring lookup
  4. flagProfile (--profile flag) → keyring lookup
  5. config.DefaultProfile → keyring lookup
  6. Only one profile in keyring → use it

Types

type KeyringStore

type KeyringStore interface {
	Get(profile string) (string, error)
	Set(profile string, token string) error
	Delete(profile string) error
	List() ([]string, error)
}

KeyringStore abstracts credential storage for testability.

func NewKeyringStore

func NewKeyringStore() (KeyringStore, error)

NewKeyringStore creates a platform-native credential store. Backend selection: NOTION_KEYRING_BACKEND env → platform default → file fallback.

type OAuthFlow

type OAuthFlow struct {
	// contains filtered or unexported fields
}

OAuthFlow handles OAuth2 PKCE for Notion public integrations.

func NewOAuthFlow

func NewOAuthFlow(clientID, clientSecret string) *OAuthFlow

NewOAuthFlow creates an OAuth flow for Notion.

func (*OAuthFlow) RefreshToken

func (o *OAuthFlow) RefreshToken(refreshToken string) (*oauth2.Token, error)

RefreshToken exchanges a refresh token for a new access token.

func (*OAuthFlow) StartFlow

func (o *OAuthFlow) StartFlow() (authURL string, state string, err error)

StartFlow generates a PKCE auth URL and state parameter.

func (*OAuthFlow) WaitForCallback

func (o *OAuthFlow) WaitForCallback(state string) (*oauth2.Token, error)

WaitForCallback starts a local HTTP server and waits for the OAuth callback. Returns the exchanged token or an error on timeout/mismatch.

type Profile

type Profile struct {
	Name      string
	TokenType string // "integration" or "oauth"
}

Profile represents a stored auth profile.

type ProfileManager

type ProfileManager struct {
	// contains filtered or unexported fields
}

ProfileManager handles profile CRUD via keyring + config.

func NewProfileManager

func NewProfileManager(store KeyringStore, cfg *config.Config) *ProfileManager

NewProfileManager creates a profile manager.

func (*ProfileManager) Add

func (p *ProfileManager) Add(name, token string) error

Add stores a token in the keyring and registers the profile in config.

func (*ProfileManager) Get

func (p *ProfileManager) Get(name string) (string, error)

Get retrieves the token for a profile from the keyring.

func (*ProfileManager) List

func (p *ProfileManager) List() ([]Profile, error)

List returns all known profiles from the keyring.

func (*ProfileManager) Remove

func (p *ProfileManager) Remove(name string) error

Remove deletes a profile from keyring and config.

func (*ProfileManager) SetDefault

func (p *ProfileManager) SetDefault(name string) error

SetDefault marks a profile as the default in config.

Jump to

Keyboard shortcuts

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