users

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 11 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 GetAccountIDFromRequest

func GetAccountIDFromRequest(req *http.Request, retriever Retriever) (string, error)

GetAccountIDFromRequest retrieves SDK account_id of a user making a http request by a header provided by http client.

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
	AccountID 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) 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

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 RemoteUser

type RemoteUser struct {
	ID    int
	Email string
}

RemoteUser encapsulates internal-apis user data

type Retriever added in v0.8.0

type Retriever interface {
	Retrieve(token string) (*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 {
	AccountID 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(token string) (*models.User, error)

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

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.

func (*UserService) Retrieve added in v0.8.0

func (s *UserService) Retrieve(token string) (*models.User, error)

Retrieve authenticates user with internal-api and retrieves/creates locally stored user.

Jump to

Keyboard shortcuts

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