deviceauth

package
v0.38.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAuthenticationTimedout = fmt.Errorf("authentication timed out")
	ErrCodeRejected           = fmt.Errorf("confirmation code rejected")
)

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)
}

Authenticator is the interface for authentication via device oauth

type DeviceAuthenticator

type DeviceAuthenticator struct {
	BaseURL  *url.URL
	Clock    clock.Clock
	ClientID string
	// contains filtered or unexported fields
}

DeviceAuthenticator performs the authentication flow for logging in.

func New

func New(authURL string) (*DeviceAuthenticator, error)

New returns an instance of the DeviceAuthenticator

func (*DeviceAuthenticator) GetAccessTokenForDevice

func (d *DeviceAuthenticator) GetAccessTokenForDevice(ctx context.Context, v *DeviceVerification) (*OAuthTokenResponse, error)

GetAccessTokenForDevice uses the device verification response to fetch an access token.

func (*DeviceAuthenticator) VerifyDevice

func (d *DeviceAuthenticator) VerifyDevice(ctx context.Context, redirectURL string) (*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 OAuthTokenResponse

type OAuthTokenResponse struct {
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in,string"`
	TokenType   string `json:"token_type"`
	UserID      string `json:"user_id"`
}

OAuthTokenResponse contains the information returned after fetching an access token for a device.

Jump to

Keyboard shortcuts

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