auth

package
v0.4.16 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteCredentials

func DeleteCredentials(profile string) error

func SaveCredentials

func SaveCredentials(profile string, pc *ProfileCredentials) error

Types

type AuthTransport

type AuthTransport struct {
	Credentials *ProfileCredentials
	Profile     string
	Base        http.RoundTripper

	// RefreshFunc is called to refresh expired tokens. Defaults to RefreshAccessToken.
	RefreshFunc RefreshFunc
	// contains filtered or unexported fields
}

func (*AuthTransport) RoundTrip

func (t *AuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

type Credentials

type Credentials struct {
	Profiles map[string]ProfileCredentials `json:"profiles"`
}

type OAuthResult added in v0.4.15

type OAuthResult struct {
	AccessToken  string
	RefreshToken string
	ExpiresAt    *time.Time
}

OAuthResult holds the tokens returned by an OAuth flow or token refresh.

func OAuthFlow

func OAuthFlow(subdomain, clientID, clientSecret, scope string) (*OAuthResult, error)

func RefreshAccessToken added in v0.4.15

func RefreshAccessToken(subdomain, clientID, refreshToken string) (*OAuthResult, error)

RefreshAccessToken exchanges a refresh token for a new access token. Zendesk refresh tokens are single-use: the response includes a new refresh token that must be stored to replace the old one.

type ProfileCredentials

type ProfileCredentials struct {
	Method         string     `json:"method"`
	Subdomain      string     `json:"subdomain"`
	Email          string     `json:"email,omitempty"`
	APIToken       string     `json:"api_token,omitempty"`
	OAuthToken     string     `json:"oauth_token,omitempty"`
	OAuthClientID  string     `json:"oauth_client_id,omitempty"`
	RefreshToken   string     `json:"refresh_token,omitempty"`
	TokenExpiresAt *time.Time `json:"token_expires_at,omitempty"`
}

func LoadCredentials

func LoadCredentials(profile string) (*ProfileCredentials, error)

func ResolveCredentials

func ResolveCredentials(profile string) (*ProfileCredentials, error)

func (*ProfileCredentials) IsTokenExpired added in v0.4.15

func (pc *ProfileCredentials) IsTokenExpired() bool

IsTokenExpired returns true if the OAuth token is within 60 seconds of expiry. Returns false if no expiry is set (backward compat with legacy tokens).

type RefreshFunc added in v0.4.15

type RefreshFunc func(subdomain, clientID, refreshToken string) (*OAuthResult, error)

RefreshFunc is the signature for a function that refreshes an OAuth token.

Jump to

Keyboard shortcuts

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