Documentation
¶
Index ¶
- Variables
- func EnvTokenSet() bool
- func GetConf() *oauth2.Config
- func Login(ctx context.Context, out io.Writer) (*oauth2.Token, error)
- func NewTokenURL() string
- func PromptToken() (string, error)
- func Remedy(k Kind) string
- func RemedyDetail(k Kind) string
- func SetToken(token *oauth2.Token) error
- type Credential
- type Kind
- type LogoutReport
Constants ¶
This section is empty.
Variables ¶
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") // 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 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 ¶
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
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
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.
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 )
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.