Documentation ¶
Index ¶
- Constants
- func GetIPAddressForRequest(r *http.Request) string
- func IsPrivateSubnet(ipAddress net.IP) bool
- func StartAuthenticatingAPIServer(userID int) *httptest.Server
- func StartDummyAPIServer(response []byte) *httptest.Server
- func StartEasyAPIServer() *httptest.Server
- type AuthenticatedFunc
- type AuthenticatedRequest
- type Authenticator
- type Query
- type RemoteUser
- type Retriever
- type TestUserRetriever
- type WalletService
Constants ¶
const GenericRetrievalErr = "unable to retrieve user"
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
GetIPAddressForRequest returns the real IP address of the request
func IsPrivateSubnet ¶ added in v0.8.3
IsPrivateSubnet checks if this ip is in a private subnet
func StartAuthenticatingAPIServer ¶ added in v0.11.1
func StartDummyAPIServer ¶ added in v0.11.1
func StartEasyAPIServer ¶ added in v0.11.1
Types ¶
type AuthenticatedFunc ¶ added in v0.8.0
type AuthenticatedFunc func(http.ResponseWriter, *AuthenticatedRequest)
type AuthenticatedRequest ¶ added in v0.8.0
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
func (a *Authenticator) Wrap(wrapped AuthenticatedFunc) http.HandlerFunc
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
Query contains queried user details and optional metadata about the request
type RemoteUser ¶
RemoteUser encapsulates internal-apis user data
type Retriever ¶ added in v0.8.0
Retriever is an interface for user retrieval by internal-apis auth token
type TestUserRetriever ¶ added in v0.8.0
TestUserRetriever is a helper allowing to test API endpoints that require authentication without actually creating DB records.
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