Documentation
¶
Index ¶
- Constants
- func GetAccountIDFromRequest(r *http.Request, retriever Retriever) (string, error)
- func GetIPAddressForRequest(r *http.Request) string
- func IsPrivateSubnet(ipAddress net.IP) bool
- type AuthenticatedFunc
- type AuthenticatedRequest
- type Authenticator
- type Query
- type RemoteUser
- type Retriever
- type TestUserRetriever
- type UserService
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 GetAccountIDFromRequest ¶
GetAccountIDFromRequest retrieves SDK account_id of a user making a http request by a header provided by http client.
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
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) GetAccountID ¶ added in v0.8.0
func (a *Authenticator) GetAccountID(r *http.Request) (string, error)
GetAccountID 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 UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
UserService stores manipulated user data
func NewUserService ¶
func NewUserService() *UserService
NewUserService returns UserService instance for retrieving or creating user records and accounts.