Documentation
¶
Index ¶
- Constants
- func ClearRegistration() error
- func ClearTokens() error
- func DeriveAuthBaseURL(apiHost string) string
- func ExchangeCode(ctx context.Context, cfg *oauth2.Config, code, codeVerifier string) (*oauth2.Token, error)
- func GenerateState() (string, error)
- func HasTokens() bool
- func IsExpired(t *TokenData) bool
- func LoadCachedRegistration() (clientID string, scopes []string)
- func NewConfig(authBaseURL, clientID string, scopes []string) *oauth2.Config
- func NewHTTPClient(cfg *oauth2.Config, base http.RoundTripper, userAgent string) (*http.Client, error)
- func RegisterClient(ctx context.Context, authBaseURL string) (clientID string, scopes []string, err error)
- func SaveOAuth2Token(tok *oauth2.Token) error
- func SaveRegistration(clientID string, scopes []string) error
- func SaveTokens(t *TokenData) error
- func ToOAuth2Token(t *TokenData) *oauth2.Token
- func TokenSourceFromStored(cfg *oauth2.Config) (oauth2.TokenSource, error)
- type TokenData
Constants ¶
const ( CallbackPort = "19798" RedirectURI = "http://localhost:" + CallbackPort + "/callback" )
Variables ¶
This section is empty.
Functions ¶
func ClearRegistration ¶
func ClearRegistration() error
ClearRegistration removes the cached client_id and scopes from config.
func ClearTokens ¶
func ClearTokens() error
ClearTokens removes OAuth tokens from ~/.rootly-catalog-sync/config.yaml, preserving all other config fields.
func DeriveAuthBaseURL ¶
DeriveAuthBaseURL builds the OAuth base URL from the API host. For api.rootly.com it returns https://rootly.com. For localhost it returns http://localhost:<port>.
func ExchangeCode ¶
func ExchangeCode(ctx context.Context, cfg *oauth2.Config, code, codeVerifier string) (*oauth2.Token, error)
ExchangeCode exchanges an authorization code for tokens using PKCE.
func GenerateState ¶
GenerateState creates a cryptographically random state parameter.
func HasTokens ¶
func HasTokens() bool
HasTokens returns true if OAuth tokens exist in the config file (cheap check).
func LoadCachedRegistration ¶
LoadCachedRegistration reads the cached client_id and scopes from config.
func NewConfig ¶
NewConfig creates an oauth2.Config for the given auth base URL, client ID, and scopes.
func NewHTTPClient ¶
func NewHTTPClient(cfg *oauth2.Config, base http.RoundTripper, userAgent string) (*http.Client, error)
NewHTTPClient creates an http.Client that uses stored OAuth tokens with auto-refresh. The userAgent is set on all requests. The base transport is used for underlying HTTP calls.
func RegisterClient ¶
func RegisterClient(ctx context.Context, authBaseURL string) (clientID string, scopes []string, err error)
RegisterClient dynamically registers an OAuth client and returns the client_id and granted scopes.
func SaveOAuth2Token ¶
SaveOAuth2Token converts and persists an oauth2.Token.
func SaveRegistration ¶
SaveRegistration persists the client_id and scopes to config.
func SaveTokens ¶
SaveTokens writes OAuth tokens into ~/.rootly-catalog-sync/config.yaml, preserving all other config fields.
func ToOAuth2Token ¶
ToOAuth2Token converts stored token data to an oauth2.Token.
func TokenSourceFromStored ¶
func TokenSourceFromStored(cfg *oauth2.Config) (oauth2.TokenSource, error)
TokenSourceFromStored creates a token source that auto-refreshes using stored tokens.
Types ¶
type TokenData ¶
type TokenData = authconfig.OAuthData
TokenData is an alias for authconfig.OAuthData used within the oauth package.
func LoadTokens ¶
LoadTokens reads OAuth tokens from ~/.rootly-catalog-sync/config.yaml.
func TokenDataFromOAuth2 ¶
TokenDataFromOAuth2 converts an oauth2.Token to TokenData for storage.