clitoken

package
v1.0.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BestCredentialCache

func BestCredentialCache() tokencache.CredentialCache

BestCredentialCache returns the most preferred available credential client for the platform and environment.

Types

type CommandOpener

type CommandOpener struct {
	CommandName string
}

CommandOpener opens a URL by executing a command with the URL as the first argument. CommandOpener works well with MacOS's `open` command.

func (*CommandOpener) Open

func (o *CommandOpener) Open(ctx context.Context, url string) error

type Config

type Config struct {
	// OAuth2Config is the configuration for the provider. Required.
	OAuth2Config oauth2.Config

	// Opener is used to launch the users browser in to the auth flow. If not
	// set, an appropriate opener for the platform will be automatically
	// configured.
	Opener Opener

	// PortLow is used with PortHigh to specify the port range of the local
	// server. If not set, Go's default port allocation is used. Both PortLow
	// and PortHigh must be specified.
	PortLow uint16
	// PortHigh sets the upper range of ports used to configure the local
	// server, if PortLow is set.
	PortHigh uint16

	// Renderer is used to render the callback page in the users browser, on
	// completion of the auth flow. Defaults to a basic UI
	Renderer Renderer

	// AuthCodeOptions are used to provide additional options to the auth code
	// URL when starting the flow. The code challenge/PKCE option should not be
	// set here, it will be managed dynamically.
	AuthCodeOptions []oauth2.AuthCodeOption
	// SkipPKCE disables the use of PKCE/Code challenge. This should only be
	// used if problems are experienced with it, with consideration to the
	// security implications.
	SkipPKCE bool
}

Config configures a CLI local token source. This is used to implement the 3-legged oauth2 flow for local/CLI applications, where the callback is a dynamic server listening on localhost.

func (*Config) TokenSource

func (c *Config) TokenSource(ctx context.Context) (oauth2.TokenSource, error)

TokenSource creates a token source that command line (CLI) programs can use to fetch tokens from an OAuth2/OIDC Provider for use in authenticating clients to other systems (e.g., Kubernetes clusters, Docker registries, etc.). The client should be configured with any scopes or auth code options that are required.

This will trigger the auth flow each time, in practice the result should be cached. The resulting tokens are not verified, and the caller should verify if desired.

Example:

ctx := context.TODO()

provider, err := oidc.DiscoverProvider(ctx, issuer)
if err != nil {
    // handle err
}

cfg := Config{
    OAuth2Config: oauth2.Config{
        ClientID:       clientID,
        ClientSecret:   clientSecret,
        Endpoint:       provider.Endpoint(),
        Scopes:         []string{oidc.ScopeOpenID},
    }
}

ts, err := cfg.TokenSource(ctx)
if err != nil {
    // handle err
}

token, err := ts.Token()
if err != nil {
    // handle error
}

// use token

type EchoOpener

type EchoOpener struct{}

EchoOpener opens a URL by printing it to the console for the user to manually click on. It is used as a last resort.

func (*EchoOpener) Open

func (o *EchoOpener) Open(ctx context.Context, url string) error

type EncryptedFileCredentialCache

type EncryptedFileCredentialCache struct {
	// Dir is the path where encrypted cache files will be stored.
	// If empty, to oidc-cache in the os.UserCacheDir
	Dir string

	// PassphrasePromptFunc is a function that prompts the user to enter a
	// passphrase used to encrypt and decrypt a file.
	PassphrasePromptFunc
}

func (*EncryptedFileCredentialCache) Available

func (e *EncryptedFileCredentialCache) Available() bool

func (*EncryptedFileCredentialCache) Get

func (e *EncryptedFileCredentialCache) Get(issuer, key string) (*oauth2.Token, error)

func (*EncryptedFileCredentialCache) Set

func (e *EncryptedFileCredentialCache) Set(issuer, key string, token *oauth2.Token) error

type KeychainCLICredentialCache

type KeychainCLICredentialCache struct{}

KeychainCLICredentialCache uses /usr/bin/security to store items. This is flexible and doesn't require CGO, however any other process can read the items via the command

func (*KeychainCLICredentialCache) Available

func (k *KeychainCLICredentialCache) Available() bool

func (*KeychainCLICredentialCache) Get

func (k *KeychainCLICredentialCache) Get(issuer, key string) (*oauth2.Token, error)

func (*KeychainCLICredentialCache) Set

func (k *KeychainCLICredentialCache) Set(issuer, key string, token *oauth2.Token) error

type MemoryWriteThroughCredentialCache

type MemoryWriteThroughCredentialCache struct {
	tokencache.CredentialCache
	// contains filtered or unexported fields
}

MemoryWriteThroughCredentialCache is a write-through cache for another underlying CredentialCache. If a credential has been previously requested from the underlying store, it is read from memory the next time it is requested.

MemoryWriteThroughCredentialCache is useful when the underlying store requires user input (e.g., a passphrase) or is otherwise expensive.

func (*MemoryWriteThroughCredentialCache) Available

func (c *MemoryWriteThroughCredentialCache) Available() bool

func (*MemoryWriteThroughCredentialCache) Get

func (c *MemoryWriteThroughCredentialCache) Get(issuer, key string) (*oauth2.Token, error)

func (*MemoryWriteThroughCredentialCache) Set

func (c *MemoryWriteThroughCredentialCache) Set(issuer, key string, token *oauth2.Token) error

type NullCredentialCache

type NullCredentialCache struct{}

NullCredentialCache will not cache tokens. Used it to opt out of caching.

func (*NullCredentialCache) Available

func (c *NullCredentialCache) Available() bool

func (*NullCredentialCache) Get

func (c *NullCredentialCache) Get(issuer, key string) (*oauth2.Token, error)

func (*NullCredentialCache) Set

func (c *NullCredentialCache) Set(issuer, key string, token *oauth2.Token) error

type Opener

type Opener interface {
	// Open opens the provided URL in the user's browser
	Open(ctx context.Context, url string) error
}

func DetectOpener

func DetectOpener() Opener

DetectOpener attempts to find the best opener for a user's system. If there is no best opener for the system, it defaults to an opener that prints the URL to the console so the user can click on it.

type PassphrasePromptFunc

type PassphrasePromptFunc func(prompt string) (passphrase string, err error)

type Renderer

type Renderer interface {
	RenderLocalTokenSourceTokenIssued(w io.Writer) error
	RenderLocalTokenSourceError(w io.Writer, message string) error
}

Jump to

Keyboard shortcuts

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