api

package
v27.3.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeout = errors.New("timed out waiting for device token")

Functions

This section is empty.

Types

type API

type API struct {
	// TenantURL is the base used for each request to Auth0.
	TenantURL string
	// ClientID is the client ID for the application to auth with the tenant.
	ClientID string
	// Scopes are the scopes that are requested during the device auth flow.
	Scopes []string
}

API represents API interactions with Auth0.

func (API) GetAutoPAT

func (a API) GetAutoPAT(ctx context.Context, audience string, res TokenResponse) (string, error)

func (API) GetDeviceCode

func (a API) GetDeviceCode(ctx context.Context, audience string) (State, error)

GetDeviceCode initiates the device-code auth flow with the tenant. The state returned contains the device code that the user must use to authenticate, as well as the URL to visit, etc.

func (API) RevokeToken

func (a API) RevokeToken(ctx context.Context, refreshToken string) error

RevokeToken revokes a refresh token with the tenant so that it can no longer be used to get new tokens.

func (API) WaitForDeviceToken

func (a API) WaitForDeviceToken(ctx context.Context, state State) (TokenResponse, error)

WaitForDeviceToken polls the tenant to get access/refresh tokens for the user. This should be called after GetDeviceCode, and will block until the user has authenticated or we have reached the time limit for authenticating (based on the response from GetDeviceCode).

type OAuthAPI

type OAuthAPI interface {
	GetDeviceCode(ctx context.Context, audience string) (State, error)
	WaitForDeviceToken(ctx context.Context, state State) (TokenResponse, error)
	RevokeToken(ctx context.Context, refreshToken string) error
	GetAutoPAT(ctx context.Context, audience string, res TokenResponse) (string, error)
}

type State

type State struct {
	DeviceCode      string `json:"device_code"`
	UserCode        string `json:"user_code"`
	VerificationURI string `json:"verification_uri_complete"`
	ExpiresIn       int    `json:"expires_in"`
	Interval        int    `json:"interval"`
}

State represents the state of exchange after submitting.

func (State) ExpiryDuration

func (s State) ExpiryDuration() time.Duration

ExpiryDuration returns the total duration for which the client should keep polling.

func (State) IntervalDuration

func (s State) IntervalDuration() time.Duration

IntervalDuration returns the duration that should be waited between each auth polling event.

type TokenResponse

type TokenResponse struct {
	AccessToken      string  `json:"access_token"`
	IDToken          string  `json:"id_token"`
	RefreshToken     string  `json:"refresh_token"`
	Scope            string  `json:"scope"`
	ExpiresIn        int     `json:"expires_in"`
	TokenType        string  `json:"token_type"`
	Error            *string `json:"error,omitempty"`
	ErrorDescription string  `json:"error_description,omitempty"`
}

TokenResponse represents the response of the /oauth/token route.

Jump to

Keyboard shortcuts

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