oauth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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

func DeriveAuthBaseURL(apiHost string) string

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

func GenerateState() (string, error)

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 IsExpired

func IsExpired(t *TokenData) bool

IsExpired returns true if the token is expired or within 30s of expiring.

func LoadCachedRegistration

func LoadCachedRegistration() (clientID string, scopes []string)

LoadCachedRegistration reads the cached client_id and scopes from config.

func NewConfig

func NewConfig(authBaseURL, clientID string, scopes []string) *oauth2.Config

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

func SaveOAuth2Token(tok *oauth2.Token) error

SaveOAuth2Token converts and persists an oauth2.Token.

func SaveRegistration

func SaveRegistration(clientID string, scopes []string) error

SaveRegistration persists the client_id and scopes to config.

func SaveTokens

func SaveTokens(t *TokenData) error

SaveTokens writes OAuth tokens into ~/.rootly-catalog-sync/config.yaml, preserving all other config fields.

func ToOAuth2Token

func ToOAuth2Token(t *TokenData) *oauth2.Token

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

func LoadTokens() (*TokenData, error)

LoadTokens reads OAuth tokens from ~/.rootly-catalog-sync/config.yaml.

func TokenDataFromOAuth2

func TokenDataFromOAuth2(tok *oauth2.Token) *TokenData

TokenDataFromOAuth2 converts an oauth2.Token to TokenData for storage.

Jump to

Keyboard shortcuts

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