auth

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DAGGrantType                  = "urn:ietf:params:oauth:grant-type:device_code"
	AuthorizationPendingErrorCode = "authorization_pending"
)

Functions

func GetAuthenticatedClient

func GetAuthenticatedClient(token string) (*kk.SDK, error)

func SaveAccessToken

func SaveAccessToken(cfg config.Hook, token *AccessToken) error

Types

type AccessToken

type AccessToken struct {
	Token      *AccessTokenResponse `json:"token"`
	ReceivedAt time.Time            `json:"received_at"`
}

func LoadAccessToken

func LoadAccessToken(cfg config.Hook, refreshURL string, logger *slog.Logger) (*AccessToken, error)

For a given profile, load a saved token from disk in the same path as the config path. * If there is no file, return error. * If it's not expired, return it. * If it's expired, refresh it, then store it, then return it

func PollForToken

func PollForToken(ctx context.Context, httpClient *http.Client,
	url string, clientID string, deviceCode string, logger *slog.Logger,
) (*AccessToken, error)

func RefreshAccessToken

func RefreshAccessToken(refreshURL string, refreshToken string, _ *slog.Logger) (*AccessToken, error)

func (*AccessToken) IsExpired

func (t *AccessToken) IsExpired() bool

type AccessTokenResponse

type AccessTokenResponse struct {
	AuthToken    string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	TokenType    string `json:"token_type"`
	ExpiresAfter int    `json:"expires_in"`
	Scope        string `json:"scope"`
}

type AuthenticatedClientFactory

type AuthenticatedClientFactory func(token string) (*kk.SDK, error)

type DAGError

type DAGError struct {
	ErrorDescription string `json:"error_description,omitempty"`
	ErrorURI         string `json:"error_uri,omitempty"`
	ErrorCode        string `json:"error"`
}

func (*DAGError) Error

func (d *DAGError) Error() string

type DeviceCodeResponse

type DeviceCodeResponse struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete,omitempty"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval,omitempty"`
}

func RequestDeviceCode

func RequestDeviceCode(httpClient *http.Client,
	url string, clientID string, logger *slog.Logger,
) (DeviceCodeResponse, error)

Jump to

Keyboard shortcuts

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