Documentation
¶
Index ¶
Constants ¶
const ( DefaultBaseURL = "https://auth.planetscale.com/" OAuthClientID = "wzzkYKOfRcxFAiMgDgfbhO9yIikNIlt9-yhosmvPBQA" // This is safe to be committed to version control, since our OAuth // Application isn't confidential. OAuthClientSecret = "eIDdgw21BYsovcrpC4iKZQ0o7ol9cN1LsSr8fuNyg5o" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
type Authenticator interface {
VerifyDevice(ctx context.Context) (*DeviceVerification, error)
GetAccessTokenForDevice(ctx context.Context, v DeviceVerification) (string, error)
RevokeToken(ctx context.Context, token string) error
}
Authenticator is the interface for authentication via device oauth
type AuthenticatorOption ¶
type AuthenticatorOption func(c *DeviceAuthenticator) error
func SetBaseURL ¶
func SetBaseURL(baseURL string) AuthenticatorOption
SetBaseURL overrides the base URL for the DeviceAuthenticator.
func WithMockClock ¶
func WithMockClock(mock *clock.Mock) AuthenticatorOption
WithMockClock replaces the clock on the authenticator with a mock clock.
type DeviceAuthenticator ¶
type DeviceAuthenticator struct {
BaseURL *url.URL
Clock clock.Clock
ClientID string
ClientSecret string
// contains filtered or unexported fields
}
DeviceAuthenticator performs the authentication flow for logging in.
func New ¶
func New(client *http.Client, clientID, clientSecret string, opts ...AuthenticatorOption) (*DeviceAuthenticator, error)
New returns an instance of the DeviceAuthenticator
func (*DeviceAuthenticator) GetAccessTokenForDevice ¶
func (d *DeviceAuthenticator) GetAccessTokenForDevice(ctx context.Context, v DeviceVerification) (string, error)
GetAccessTokenForDevice uses the device verification response to fetch an access token.
func (*DeviceAuthenticator) RevokeToken ¶
func (d *DeviceAuthenticator) RevokeToken(ctx context.Context, token string) error
RevokeToken revokes an access token.
func (*DeviceAuthenticator) VerifyDevice ¶
func (d *DeviceAuthenticator) VerifyDevice(ctx context.Context) (*DeviceVerification, error)
VerifyDevice performs the device verification API calls.
type DeviceCodeResponse ¶
type DeviceCodeResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
VerificationCompleteURI string `json:"verification_uri_complete"`
ExpiresIn int `json:"expires_in"`
PollingInterval int `json:"interval"`
}
DeviceCodeResponse encapsulates the response for obtaining a device code.
type DeviceVerification ¶
type DeviceVerification struct {
DeviceCode string
UserCode string
VerificationURL string
VerificationCompleteURL string
CheckInterval time.Duration
ExpiresAt time.Time
}
DeviceVerification represents the response from verifying a device.
type ErrorResponse ¶
type ErrorResponse struct {
ErrorCode string `json:"error"`
Description string `json:"error_description"`
}
ErrorResponse is an error response from the API.
func (ErrorResponse) Error ¶
func (e ErrorResponse) Error() string
type OAuthTokenResponse ¶
type OAuthTokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
IDToken string `json:"id_token"`
ExpiresIn int `json:"expires_in"`
}
OAuthTokenResponse contains the information returned after fetching an access token for a device.