Documentation
¶
Index ¶
- Variables
- type Auth
- type EmailSender
- type InfoAPIClient
- type Provider
- func (p *Provider) CreateRefreshToken(ctx context.Context, userID string) (RefreshToken, error)
- func (p *Provider) CreateTokens(ctx context.Context, user model.User) (TokenPair, error)
- func (p *Provider) DeleteUser(ctx context.Context, userID string) error
- func (p *Provider) GetClaimsFromAccessToken(tokenStr string) (auth.Claims, error)
- func (p *Provider) GitHubOAuth(ctx context.Context, oauthID, email, username string, emailVerified bool) (model.User, error)
- func (p *Provider) GoogleOAuth(ctx context.Context, oauthID, email string, emailVerified bool) (model.User, error)
- func (p *Provider) IsEmailUnsubscribed(ctx context.Context, email string) (bool, error)
- func (p *Provider) RefreshTokens(ctx context.Context, refreshTokenStr string) (TokenPair, error)
- func (p *Provider) ResendVerificationEmail(ctx context.Context, userID string) error
- func (p *Provider) RevokeRefreshToken(ctx context.Context, refreshTokenStr string) error
- func (p *Provider) SignIn(ctx context.Context, username, password string) (model.User, error)
- func (p *Provider) SignUp(ctx context.Context, username, displayName, email, password string, ...) (model.User, error)
- func (p *Provider) UnsubscribeEmail(ctx context.Context, token string) (string, error)
- func (p *Provider) UpdateUserProfile(ctx context.Context, userID string, params model.UpdateProfileParams) (model.User, error)
- func (p *Provider) ValidateAccessToken(tokenStr string) bool
- func (p *Provider) VerifyEmail(ctx context.Context, userID string, code string) (model.User, error)
- type RefreshToken
- type TokenPair
- type TooManyRequestsError
- type UserRepo
Constants ¶
This section is empty.
Variables ¶
var ( ErrResendVerificationNoEmail = errors.New("resend verification: user has no email") ErrVerifyEmailUserNotFound = errors.New("verify email: user not found") ErrVerifyEmailAlreadyVerified = errors.New("verify email: already verified") ErrVerifyEmailInvalidOrExpired = errors.New("verify email: invalid or expired code") ErrSendVerifyEmailUnsubscribed = errors.New("send verify email: user is unsubscribed") )
errors
var ( // ErrRefreshTokenNotFound is returned when refresh token is not found ErrRefreshTokenNotFound = errors.New("refresh token not found") // ErrRefreshTokenExpired is returned when refresh token has expired ErrRefreshTokenExpired = errors.New("refresh token expired") )
var ( ErrInvalidEmail = errors.New("invalid email") ErrOAuthSignInConflict = errors.New("oauth sign in name conflict") ErrUpdateProfileUserNotFound = errors.New("update profile: user not found") ErrUpdateProfileInvalidPassword = errors.New("update profile: invalid current password") ErrUpdateProfileNotAllowed = errors.New("update profile: password change not allowed for oauth users") ErrSignInInvalidCredentials = errors.New("sign in: invalid credentials") ErrSignUpUsernameExists = errors.New("sign up: username already exists") ErrSignUpEmailExists = errors.New("sign up: email already exists") ErrSignUpEmailRequired = errors.New("sign up: email is required") ErrSignUpPublisherNameExists = errors.New("sign up: publisher name already exists") ErrOAuthPublisherConflict = errors.New("oauth sign in: publisher must use password") ErrOAuthEmailUnverified = errors.New("oauth sign in: email not verified by provider") )
errors
Functions ¶
This section is empty.
Types ¶
type Auth ¶
type Auth interface {
GenerateToken(claims jwt.Claims) (string, error)
GenerateRefreshToken() (string, time.Time, error)
CreateUserClaims(user model.User) jwt.Claims
GetClaimsFromToken(tokenStr string) (auth.Claims, error)
}
Auth provides authentication methods
type EmailSender ¶
type EmailSender interface {
SendEmailVerification(ctx context.Context, req resendapi.SendEmailVerificationRequest) (string, error)
}
EmailSender provides methods for sending emails
type InfoAPIClient ¶
type InfoAPIClient interface {
CompanyExists(ctx context.Context, companyName string) (bool, error)
}
InfoAPIClient provides methods for interacting with game library info API
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider represents dependencies for facade layer
func New ¶
func New(log *zap.Logger, userRepo UserRepo, emailSender EmailSender, authService Auth, unsubscribeTokenGenerator *auth.UnsubscribeTokenGenerator, infoAPIClient InfoAPIClient) *Provider
New creates a new facade provider
func (*Provider) CreateRefreshToken ¶
CreateRefreshToken creates a refresh token for the user
func (*Provider) CreateTokens ¶
CreateTokens creates access token and refresh token for a user
func (*Provider) DeleteUser ¶
DeleteUser deletes user by id
func (*Provider) GetClaimsFromAccessToken ¶
GetClaimsFromAccessToken returns claims from access token
func (*Provider) GitHubOAuth ¶
func (p *Provider) GitHubOAuth(ctx context.Context, oauthID, email, username string, emailVerified bool) (model.User, error)
GitHubOAuth handles GitHub OAuth sign in
func (*Provider) GoogleOAuth ¶
func (p *Provider) GoogleOAuth(ctx context.Context, oauthID, email string, emailVerified bool) (model.User, error)
GoogleOAuth handles Google OAuth sign in
func (*Provider) IsEmailUnsubscribed ¶
IsEmailUnsubscribed checks if an email address is unsubscribed from all notifications
func (*Provider) RefreshTokens ¶
RefreshTokens validates refresh token and returns new access and refresh tokens
func (*Provider) ResendVerificationEmail ¶
ResendVerificationEmail resends email verification code to a user
func (*Provider) RevokeRefreshToken ¶
RevokeRefreshToken revokes a refresh token by deleting it from the database
func (*Provider) SignUp ¶
func (p *Provider) SignUp(ctx context.Context, username, displayName, email, password string, isPublisher bool) (model.User, error)
SignUp creates a new user with provided params and sends verification email if applicable
func (*Provider) UnsubscribeEmail ¶
UnsubscribeEmail unsubscribes an email address from all notifications
func (*Provider) UpdateUserProfile ¶
func (p *Provider) UpdateUserProfile(ctx context.Context, userID string, params model.UpdateProfileParams) (model.User, error)
UpdateUserProfile updates user profile
func (*Provider) ValidateAccessToken ¶
ValidateAccessToken validates access token and returns claims from it
type RefreshToken ¶
RefreshToken represents a refresh token
type TokenPair ¶
type TokenPair struct {
AccessToken string
RefreshToken RefreshToken
}
TokenPair represents an access token and refresh token pair
type TooManyRequestsError ¶
TooManyRequestsError - error with retry after
func AsTooManyRequestsError ¶
func AsTooManyRequestsError(err error) *TooManyRequestsError
AsTooManyRequestsError - returns *TooManyRequestsError if err is of type TooManyRequestsError
func NewTooManyRequestsError ¶
func NewTooManyRequestsError(retryAfter time.Duration) TooManyRequestsError
NewTooManyRequestsError - creates a new ErrTooManyRequestsRetryAfter
func (TooManyRequestsError) Error ¶
func (e TooManyRequestsError) Error() string
Error implements error interface
type UserRepo ¶
type UserRepo interface {
RunWithTx(ctx context.Context, f func(context.Context) error) error
CreateUser(ctx context.Context, user database.User) error
UpdateUser(ctx context.Context, user database.User) error
DeleteUser(ctx context.Context, userID string) error
GetUserByID(ctx context.Context, userID string) (database.User, error)
GetUserByUsername(ctx context.Context, username string) (database.User, error)
GetUserByEmail(ctx context.Context, email string) (database.User, error)
GetUserByOAuthLink(ctx context.Context, provider string, oauthID string) (database.User, error)
CreateUserOAuthLink(ctx context.Context, link database.UserOAuthLink) error
HasOAuthLink(ctx context.Context, userID string) (bool, error)
CheckUserExists(ctx context.Context, name string, role model.Role) (bool, error)
SetUserEmailVerified(ctx context.Context, userID string) error
CreateEmailVerification(ctx context.Context, verification database.EmailVerification) error
GetEmailVerificationByUserID(ctx context.Context, userID string) (database.EmailVerification, error)
SetEmailVerificationMessageID(ctx context.Context, verificationID string, messageID string) error
SetEmailVerificationUsed(ctx context.Context, id string, verified bool) error
SetUnsubscribeToken(ctx context.Context, id string, token string) error
CreateEmailUnsubscribe(ctx context.Context, unsubscribe database.EmailUnsubscribe) error
IsEmailUnsubscribed(ctx context.Context, email string) (bool, error)
CreateRefreshToken(ctx context.Context, refreshToken database.RefreshToken) error
GetRefreshTokenByHash(ctx context.Context, tokenHash string) (database.RefreshToken, error)
DeleteRefreshToken(ctx context.Context, token string) error
DeleteRefreshTokensByUserID(ctx context.Context, userID string) error
}
UserRepo provides methods for working with user repo