account

package
v1.6.26 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthHeaderDevice              = "Device-17"
	AuthHeaderToken               = "Token-17"
	AuthHeaderNextToken           = "Next-Token-17"
	AuthHeaderNextTokenDeprecated = "Next_token_17"
)

Authentication Headers.

View Source
const (
	CAAuthenticateURL = "/authenticate"
	CAProfileURL      = "/user/profile"
	CAGetTokensURL    = "/tokens"
)

Customer Agent URLs.

View Source
const (
	CHAuthenticateURL = "/v1/authenticate"
	CHUserProfileURL  = "/v1/user_profile"
)

Customer Hub URLs.

View Source
const (
	// UserStateNone is only used within Portmaster for saving information for
	// logging into the same device.
	UserStateNone      = ""
	UserStateFresh     = "fresh"
	UserStateQueued    = "queued"
	UserStateApproved  = "approved"
	UserStateSuspended = "suspended"
	UserStateLoggedOut = "loggedout" // Portmaster only.

	SubscriptionStateManual    = "manual"    // Manual renewal.
	SubscriptionStateActive    = "active"    // Automatic renewal.
	SubscriptionStateCancelled = "cancelled" // Automatic, but canceled.

	ChargeStatePending   = "pending"
	ChargeStateCompleted = "completed"
	ChargeStateDead      = "dead"
)

User, Subscription and Charge states.

View Source
const (
	// StatusInvalidAuth [401 Unauthorized] is returned when the credentials are
	// invalid or the user was logged out.
	StatusInvalidAuth = 401
	// StatusNoAccess [403 Forbidden] is returned when the user does not have
	// an active subscription or the subscription does not include the required
	// feature for the request.
	StatusNoAccess = 403
	// StatusInvalidDevice [410 Gone] is returned when the device trying to
	// log into does not exist.
	StatusInvalidDevice = 410
	// StatusReachedDeviceLimit [409 Conflict] is returned when the device limit is reached.
	StatusReachedDeviceLimit = 409
	// StatusDeviceInactive [423 Locked] is returned when the device is locked.
	StatusDeviceInactive = 423
	// StatusNotLoggedIn [412 Precondition] is returned by the Portmaster, if an action required to be logged in, but the user is not logged in.
	StatusNotLoggedIn = 412

	// StatusUnknownError is a special status code that signifies an unknown or
	// unexpected error by the API.
	StatusUnknownError = -1
	// StatusConnectionError is a special status code that signifies a
	// connection error.
	StatusConnectionError = -2
)

Agent and Hub return statuses.

View Source
const (
	FeatureSPN           = FeatureID("spn")
	FeatureSafingSupport = FeatureID("support")
	FeatureHistory       = FeatureID("history")
	FeatureBWVis         = FeatureID("bw-vis")
	FeatureVPNCompat     = FeatureID("vpn-compat")
)

A list of all supported features.

Variables

View Source
var (
	ErrMissingDeviceID = errors.New("missing device ID")
	ErrMissingToken    = errors.New("missing token")
)

Errors.

Functions

func ApplyNextTokenToResponse

func ApplyNextTokenToResponse(w http.ResponseWriter, token string)

ApplyNextTokenToResponse applies the next authentication token to a response.

func GetNextTokenFromResponse

func GetNextTokenFromResponse(resp *http.Response) (token string, ok bool)

GetNextTokenFromResponse extracts an authentication token from a response.

Types

type AuthToken

type AuthToken struct {
	Device string
	Token  string
}

AuthToken holds an authentication token.

func GetAuthTokenFromRequest

func GetAuthTokenFromRequest(request *http.Request) (*AuthToken, error)

GetAuthTokenFromRequest extracts an authentication token from a request.

func (*AuthToken) ApplyTo

func (at *AuthToken) ApplyTo(request *http.Request)

ApplyTo applies the authentication token to a request.

type Device

type Device struct {
	Name string `json:"name"`
	ID   string `json:"id"`
}

Device describes a device of an SPN user.

type FeatureID

type FeatureID string

FeatureID defines a feature that requires a plan/subscription.

type Plan

type Plan struct {
	Name       string      `json:"name"`
	Amount     int         `json:"amount"`
	Months     int         `json:"months"`
	Renewable  bool        `json:"renewable"`
	FeatureIDs []FeatureID `json:"feature_ids"`
}

Plan describes an SPN subscription plan.

type Subscription

type Subscription struct {
	EndsAt          *time.Time `json:"ends_at"`
	State           string     `json:"state"`
	NextBillingDate *time.Time `json:"next_billing_date"`
	PaymentProvider string     `json:"payment_provider"`
}

Subscription describes an SPN subscription.

type User

type User struct {
	Username     string        `json:"username"`
	State        string        `json:"state"`
	Balance      int           `json:"balance"`
	Device       *Device       `json:"device"`
	Subscription *Subscription `json:"subscription"`
	CurrentPlan  *Plan         `json:"current_plan"`
	NextPlan     *Plan         `json:"next_plan"`
	View         *View         `json:"view"`
}

User describes an SPN user account.

func (*User) MayUse

func (u *User) MayUse(featureID FeatureID) bool

MayUse returns whether the user may currently use the feature identified by the given feature ID. Leave feature ID empty to check without feature.

func (*User) MayUsePrioritySupport

func (u *User) MayUsePrioritySupport() bool

MayUsePrioritySupport returns whether the user may currently use the priority support.

func (*User) MayUseSPN

func (u *User) MayUseSPN() bool

MayUseSPN returns whether the user may currently use the SPN.

func (*User) UpdateView

func (u *User) UpdateView(requestStatusCode int)

UpdateView updates the view and handles plan/package fallbacks.

type View

type View struct {
	Message           string
	ShowAccountData   bool
	ShowAccountButton bool
	ShowLoginButton   bool
	ShowRefreshButton bool
	ShowLogoutButton  bool
}

View holds metadata that assists in displaying account information.

Jump to

Keyboard shortcuts

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