users

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const GenericRetrievalErr = "unable to retrieve user"
View Source
const TokenHeader string = "X-Lbry-Auth-Token"

TokenHeader is the name of HTTP header which is supplied by client and should contain internal-api auth_token.

Variables

This section is empty.

Functions

func GetIPAddressForRequest added in v0.8.3

func GetIPAddressForRequest(r *http.Request) string

GetIPAddressForRequest returns the real IP address of the request

func IsPrivateSubnet added in v0.8.3

func IsPrivateSubnet(ipAddress net.IP) bool

IsPrivateSubnet checks if this ip is in a private subnet

func StartAuthenticatingAPIServer added in v0.11.1

func StartAuthenticatingAPIServer(userID int) *httptest.Server

func StartDummyAPIServer added in v0.11.1

func StartDummyAPIServer(response []byte) *httptest.Server

func StartEasyAPIServer added in v0.11.1

func StartEasyAPIServer() *httptest.Server

Types

type AuthenticatedFunc added in v0.8.0

type AuthenticatedFunc func(http.ResponseWriter, *AuthenticatedRequest)

type AuthenticatedRequest added in v0.8.0

type AuthenticatedRequest struct {
	*http.Request
	WalletID  string
	AuthError error
}

func (*AuthenticatedRequest) AuthFailed added in v0.8.0

func (r *AuthenticatedRequest) AuthFailed() bool

AuthFailed is a helper to see if there was an error authenticating user.

func (*AuthenticatedRequest) IsAuthenticated added in v0.8.0

func (r *AuthenticatedRequest) IsAuthenticated() bool

IsAuthenticated is a helper to see if a user was authenticated. If it is false, AuthError might be provided (in case user retriever has errored) or be nil if no auth token was present in headers.

type Authenticator added in v0.8.0

type Authenticator struct {
	// contains filtered or unexported fields
}

func NewAuthenticator added in v0.8.0

func NewAuthenticator(retriever Retriever) *Authenticator

NewAuthenticator provides HTTP handler wrapping methods and should be initialized with an object that allows user retrieval.

func (*Authenticator) GetWalletID added in v0.9.0

func (a *Authenticator) GetWalletID(r *http.Request) (string, error)

GetWalletID retrieves user token from HTTP headers and subsequently an SDK account ID from Retriever.

func (*Authenticator) Wrap added in v0.8.0

Wrap result can be supplied to all functions that accept http.HandleFunc, supplied function will be wrapped and called with AuthenticatedRequest instead of http.Request.

type Query added in v0.8.2

type Query struct {
	Token        string
	MetaRemoteIP string
}

Query contains queried user details and optional metadata about the request

type RemoteUser

type RemoteUser struct {
	ID               int
	HasVerifiedEmail bool
}

RemoteUser encapsulates internal-apis user data

type Retriever added in v0.8.0

type Retriever interface {
	Retrieve(query Query) (*models.User, error)
}

Retriever is an interface for user retrieval by internal-apis auth token

type TestUserRetriever added in v0.8.0

type TestUserRetriever struct {
	WalletID string
	Token    string
}

TestUserRetriever is a helper allowing to test API endpoints that require authentication without actually creating DB records.

func (*TestUserRetriever) Retrieve added in v0.8.0

func (r *TestUserRetriever) Retrieve(q Query) (*models.User, error)

Retrieve returns WalletID set during TestUserRetriever creation, checking it against TestUserRetriever's Token field if one was supplied.

type WalletService added in v0.9.0

type WalletService struct {
	Logger monitor.ModuleLogger
}

WalletService retrieves user wallet data.

func NewWalletService added in v0.9.0

func NewWalletService() *WalletService

NewWalletService returns WalletService instance for retrieving or creating wallet-based user records and accounts.

func (*WalletService) LogErrorAndReturn added in v0.9.0

func (s *WalletService) LogErrorAndReturn(log *logrus.Entry, message string, a ...interface{}) error

LogErrorAndReturn logs error with rich context and returns an error object so it can be returned from the function

func (*WalletService) Retrieve added in v0.9.0

func (s *WalletService) Retrieve(q Query) (*models.User, error)

Retrieve gets user by internal-apis auth token provided in the supplied Query.

Jump to

Keyboard shortcuts

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