Documentation
¶
Index ¶
- Constants
- Variables
- func CtxGetState(ctx context.Context) *contextState
- func CtxInitState(ctx context.Context) context.Context
- func Login(ctx context.Context, config *Config, setupKey string, jwtToken string) error
- func ManagementURLDefault() *url.URL
- func RunClient(ctx context.Context, config *Config, statusRecorder *nbStatus.Status) error
- type Claims
- type Config
- type DeviceAuthInfo
- type DeviceAuthorizationFlow
- type Engine
- type EngineConfig
- type HTTPClient
- type Hosted
- func (h *Hosted) GetClientID(ctx context.Context) string
- func (h *Hosted) RequestDeviceCode(ctx context.Context) (DeviceAuthInfo, error)
- func (h *Hosted) RotateAccessToken(ctx context.Context, refreshToken string) (TokenInfo, error)
- func (h *Hosted) WaitToken(ctx context.Context, info DeviceAuthInfo) (TokenInfo, error)
- type OAuthClient
- type Peer
- type ProviderConfig
- type RequestDeviceCodePayload
- type StatusType
- type TokenInfo
- type TokenRequestPayload
- type TokenRequestResponse
Constants ¶
const ( PeerConnectionTimeoutMax = 45000 // ms PeerConnectionTimeoutMin = 30000 // ms )
PeerConnectionTimeoutMax is a timeout of an initial connection attempt to a remote peer. E.g. this peer will wait PeerConnectionTimeoutMax for the remote peer to respond, if not successful then it will retry the connection attempt. Todo pass timeout at EnginConfig
const ( HostedGrantType = "urn:ietf:params:oauth:grant-type:device_code" HostedRefreshGrant = "refresh_token" )
HostedGrantType grant type for device flow on Hosted
Variables ¶
var ErrResetConnection = fmt.Errorf("reset connection")
Functions ¶
func CtxGetState ¶
CtxGetState object to get/update state/errors of process.
func CtxInitState ¶
CtxInitState setup context state into the context tree.
This function should be used to initialize context before CtxGetState will be executed.
func ManagementURLDefault ¶
Types ¶
type Claims ¶
type Claims struct {
Audience string `json:"aud"`
}
Claims used when validating the access token
type Config ¶
type Config struct {
// Wireguard private key of local peer
PrivateKey string
ManagementURL *url.URL
AdminURL *url.URL
WgIface string
IFaceBlackList []string
// SSHKey is a private SSH key in a PEM format
SSHKey string
}
Config Configuration type
type DeviceAuthInfo ¶
type DeviceAuthInfo struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
VerificationURIComplete string `json:"verification_uri_complete"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"`
}
DeviceAuthInfo holds information for the OAuth device login flow
type DeviceAuthorizationFlow ¶
type DeviceAuthorizationFlow struct {
Provider string
ProviderConfig ProviderConfig
}
DeviceAuthorizationFlow represents Device Authorization Flow information
func GetDeviceAuthorizationFlowInfo ¶
func GetDeviceAuthorizationFlowInfo(ctx context.Context, config *Config) (DeviceAuthorizationFlow, error)
type Engine ¶
type Engine struct {
// STUNs is a list of STUN servers used by ICE
STUNs []*ice.URL
// TURNs is a list of STUN servers used by ICE
TURNs []*ice.URL
// contains filtered or unexported fields
}
Engine is a mechanism responsible for reacting on Signal and Management stream events and managing connections to the remote peers.
func NewEngine ¶
func NewEngine( ctx context.Context, cancel context.CancelFunc, signalClient signal.Client, mgmClient mgm.Client, config *EngineConfig, statusRecorder *nbstatus.Status, ) *Engine
NewEngine creates a new Connection Engine
func (*Engine) GetConnectedPeers ¶
GetConnectedPeers returns a connection Status or nil if peer connection wasn't found
func (*Engine) GetPeerConnectionStatus ¶
func (e *Engine) GetPeerConnectionStatus(peerKey string) peer.ConnStatus
GetPeerConnectionStatus returns a connection Status or nil if peer connection wasn't found
func (*Engine) Start ¶
Start creates a new Wireguard tunnel interface and listens to events from Signal and Management services Connections to remote peers are not established here. However, they will be established once an event with a list of peers to connect to will be received from Management Service
type EngineConfig ¶
type EngineConfig struct {
WgPort int
WgIfaceName string
// WgAddr is a Wireguard local address (Netbird Network IP)
WgAddr string
// WgPrivateKey is a Wireguard private key of our peer (it MUST never leave the machine)
WgPrivateKey wgtypes.Key
// IFaceBlackList is a list of network interfaces to ignore when discovering connection candidates (ICE related)
IFaceBlackList []string
// UDPMuxPort default value 0 - the system will pick an available port
UDPMuxPort int
// UDPMuxSrflxPort default value 0 - the system will pick an available port
UDPMuxSrflxPort int
// SSHKey is a private SSH key in a PEM format
SSHKey []byte
}
EngineConfig is a config for the Engine
type HTTPClient ¶
HTTPClient http client interface for API calls
type Hosted ¶
type Hosted struct {
// Hosted API Audience for validation
Audience string
// Hosted Native application client id
ClientID string
// Hosted domain
Domain string
HTTPClient HTTPClient
}
Hosted client
func NewHostedDeviceFlow ¶
NewHostedDeviceFlow returns an Hosted OAuth client
func (*Hosted) GetClientID ¶ added in v0.6.2
GetClientID returns the provider client id
func (*Hosted) RequestDeviceCode ¶
func (h *Hosted) RequestDeviceCode(ctx context.Context) (DeviceAuthInfo, error)
RequestDeviceCode requests a device code login flow information from Hosted
func (*Hosted) RotateAccessToken ¶
RotateAccessToken requests a new token using an existing refresh token
type OAuthClient ¶
type OAuthClient interface {
RequestDeviceCode(ctx context.Context) (DeviceAuthInfo, error)
RotateAccessToken(ctx context.Context, refreshToken string) (TokenInfo, error)
WaitToken(ctx context.Context, info DeviceAuthInfo) (TokenInfo, error)
GetClientID(ctx context.Context) string
}
OAuthClient is a OAuth client interface for various idp providers
type ProviderConfig ¶
type ProviderConfig struct {
// ClientID An IDP application client id
ClientID string
// ClientSecret An IDP application client secret
ClientSecret string
// Domain An IDP API domain
Domain string
// Audience An Audience for to authorization validation
Audience string
}
ProviderConfig has all attributes needed to initiate a device authorization flow
type RequestDeviceCodePayload ¶
type RequestDeviceCodePayload struct {
Audience string `json:"audience"`
ClientID string `json:"client_id"`
}
RequestDeviceCodePayload used for request device code payload for auth0
type StatusType ¶
type StatusType string
const ( StatusIdle StatusType = "Idle" StatusConnecting StatusType = "Connecting" StatusConnected StatusType = "Connected" StatusNeedsLogin StatusType = "NeedsLogin" StatusLoginFailed StatusType = "LoginFailed" )
type TokenInfo ¶
type TokenInfo struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
IDToken string `json:"id_token"`
TokenType string `json:"token_type"`
ExpiresIn int `json:"expires_in"`
}
TokenInfo holds information of issued access token
type TokenRequestPayload ¶
type TokenRequestPayload struct {
GrantType string `json:"grant_type"`
DeviceCode string `json:"device_code,omitempty"`
ClientID string `json:"client_id"`
RefreshToken string `json:"refresh_token,omitempty"`
}
TokenRequestPayload used for requesting the auth0 token
type TokenRequestResponse ¶
type TokenRequestResponse struct {
Error string `json:"error"`
ErrorDescription string `json:"error_description"`
TokenInfo
}
TokenRequestResponse used for parsing Hosted token's response