accounts

package
v0.0.0-...-080ad10 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Type          string            `json:"type"`               // Account type (e.g. "Xbox").
	ID            string            `json:"id"`                 // Account ID.
	AuthData      *string           `json:"authData,omitempty"` // Encoded account data.
	Properties    map[string]string `json:"properties"`         // Account properties (like avatar or display name).
	Authorization *Authorization    `json:"-"`                  // Authorization data.
}

type AuthFlow

type AuthFlow[I IntermediateState] struct {
	AccountType  string        // Accounts type this flow creates.
	Steps        []FlowStep[I] // Every step of the flow to run sequentially.
	InitialState I             // Initial state for every flow run.
}

AuthFlow represents an authentication flow. It is used to authenticate new or refresh existing accounts.

func (*AuthFlow[I]) AddStep

func (f *AuthFlow[I]) AddStep(step FlowStep[I])

AddStep adds a new step to the flow.

func (*AuthFlow[I]) CreateAccount

func (f *AuthFlow[I]) CreateAccount() (Account, error)

CreateAccount creates a new account of type specified by the flow.

func (*AuthFlow[I]) RefreshAccount

func (f *AuthFlow[I]) RefreshAccount(account *Account) error

RefreshAccount refreshes an existing account of type specified by the flow.

type Authorization

type Authorization struct {
	UserUUID    string
	UserName    string
	UserType    string
	AccessToken string
	DemoUser    bool
}

type FlowState

type FlowState[I IntermediateState] struct {
	Account           *Account // Account which being authenticated.
	IntermediateState *I       // Shared state between every step of the flow.
}

FlowState represents a mutable structure that represents current authentication flow state. It is always passed by reference and supposed to be modified by every authentication step.

type FlowStep

type FlowStep[I IntermediateState] interface {
	ID() string                          // ID returns flow step identifier.
	Authorize(state *FlowState[I]) error // Authorize performs authorization.
	Refresh(state *FlowState[I]) error   // Refresh refreshes the existing token.
}

FlowStep represents an authentication step.

type IntermediateState

type IntermediateState interface{}

IntermediateState represents an intermediate state within authentication flow, it can be anything that helps get authentication done, and can be modified throughout the flow.

For example, Xbox authentication stores Authentication data in it, which gets modified with every step adding new data, such as Xbox Live token, Minecraft token. In the end this authentication data gets stored with new account.

type StepError

type StepError struct {
	StepID string // Identifier of the step that failed.
	Err    error  // Error that occurred during running of this step.
}

StepError represents an error that occurred during the authentication flow.

func (*StepError) Error

func (s *StepError) Error() string

func (*StepError) Is

func (s *StepError) Is(target error) bool

func (*StepError) Unwrap

func (s *StepError) Unwrap() error

type Store

type Store struct {
	Accounts        map[string]Account `json:"accounts"`                  // Accounts mapped by their IDs.
	SelectedAccount string             `json:"selectedAccount,omitempty"` // ID of the selected account.
}

func (*Store) AddAccount

func (s *Store) AddAccount(account Account)

func (*Store) GetSelectedAccount

func (s *Store) GetSelectedAccount() *Account

GetSelectedAccount returns the reference to the selected account or nil if no account is selected.

func (*Store) RemoveAccount

func (s *Store) RemoveAccount(account Account)

type StoreFile

type StoreFile struct {
	Store
	// contains filtered or unexported fields
}

func OpenStoreFile

func OpenStoreFile(filepath string) (*StoreFile, error)

func (*StoreFile) Close

func (f *StoreFile) Close() error

func (*StoreFile) Save

func (f *StoreFile) Save() error

Save saves the file.

Jump to

Keyboard shortcuts

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