auth

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotLoggedIn means no usable credential is stored. Errors wrapping it
	// already tell the user to run `oku auth login`.
	ErrNotLoggedIn = errors.New("run: oku auth login")

	// ErrKeyringUnavailable means the system keychain could not be read or
	// written. Errors wrapping it already suggest HARDCOVER_TOKEN instead.
	ErrKeyringUnavailable = errors.New("keyring backend unavailable")
)

Functions

func EnvTokenSet added in v0.12.0

func EnvTokenSet() bool

EnvTokenSet reports whether HARDCOVER_TOKEN overrides the stored login.

func GetConf added in v0.12.0

func GetConf() *oauth2.Config

func Login added in v0.12.0

func Login(ctx context.Context, out io.Writer) (*oauth2.Token, error)

func NewTokenURL added in v0.12.0

func NewTokenURL() string

NewTokenURL returns a link to Hardcover's "New API Key" form with oku's required scopes pre-checked, per https://docs.hardcover.app/api/pat-link-builder/

func PromptToken

func PromptToken() (string, error)

PromptToken reads a token interactively from stdin. On a terminal the input is not echoed so the secret stays out of the screen and scrollback. This backs the manual `set-token` fallback for environments where the browser-based login flow (`oku auth login`) isn't usable.

func Remedy added in v0.16.0

func Remedy(k Kind) string

Remedy says, in a line short enough for a status bar, how to get the Hardcover permissions oku is missing with a credential of kind k: signing in again can't help while HARDCOVER_TOKEN overrides the login, and a stored key can be replaced either way. RemedyDetail follows it where there is room.

func RemedyDetail added in v0.16.0

func RemedyDetail(k Kind) string

RemedyDetail is what follows Remedy for kind k where there is room: where to create a key, or, for a browser login, where to report a sign-in page that leaves the permissions out.

func SetToken

func SetToken(token *oauth2.Token) error

SetToken stores an OAuth token in the system keychain.

Types

type Credential added in v0.14.0

type Credential struct {
	Kind Kind
	// TokenSource authorizes API requests. For a browser login it refreshes
	// an expired token under the cross-process lock and persists the result.
	TokenSource oauth2.TokenSource
}

Credential is the login oku should use right now.

func Current added in v0.14.0

func Current(ctx context.Context) (Credential, error)

Current returns the credential to authenticate with: HARDCOVER_TOKEN when set, otherwise whatever the keychain holds. With nothing stored the error wraps ErrNotLoggedIn; with an unusable keychain it wraps ErrKeyringUnavailable.

type Kind added in v0.14.0

type Kind int

Kind says which credential oku authenticates with, and so where it came from.

const (
	// KindNone means no credential was found.
	KindNone Kind = iota
	// KindEnv is the HARDCOVER_TOKEN environment variable, which overrides
	// anything stored in the keychain.
	KindEnv
	// KindBrowserLogin is an OAuth token from `oku auth login`, refreshed and
	// re-stored on demand.
	KindBrowserLogin
	// KindPersonalAPIKey is a stored hc_pat_ key, whether from `oku auth
	// set-token` or carried over from before OAuth support.
	KindPersonalAPIKey
	// KindLegacyAPIKey is a pre-hc_pat_ JWT key stored with `oku auth
	// set-token` or carried over from before OAuth support.
	KindLegacyAPIKey
)

func (Kind) String added in v0.14.0

func (k Kind) String() string

type LogoutReport added in v0.14.0

type LogoutReport struct {
	// Kind is the stored credential being cleared, or KindNone when none
	// could be read.
	Kind Kind
	// RevokeErr is set when revoking the browser login with Hardcover failed;
	// the login is still cleared locally.
	RevokeErr error
	// EnvTokenSet reports that HARDCOVER_TOKEN is set; it still overrides the
	// stored login and logging out does not clear it.
	EnvTokenSet bool
}

LogoutReport describes what Logout did, for the caller to tell the user.

func Logout added in v0.14.0

func Logout(ctx context.Context, beforeClear func(report LogoutReport, legacyKey string)) (LogoutReport, error)

Logout revokes a stored browser login with Hardcover where possible and clears every stored credential. Revoking is best-effort: a missing, unreadable or unrevocable token is still cleared locally.

beforeClear, when not nil, runs after the revoke and before the keychain is cleared, so the caller can tell the user about the credential while it is still stored: if they abort there, nothing is lost. legacyKey is the stored key when the report's Kind is KindLegacyAPIKey, and empty otherwise; such keys can only be invalidated by pasting the key itself.

The report is returned even when clearing the keychain fails, the only error returned.

func (LogoutReport) ManualRevoke added in v0.14.0

func (r LogoutReport) ManualRevoke() bool

ManualRevoke reports whether the cleared credential is an API key, which oku cannot revoke and the user has to revoke on Hardcover themselves.

Jump to

Keyboard shortcuts

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