Documentation
¶
Index ¶
- type API
- func (a *API) DeleteAccount(c fiber.Ctx) error
- func (a *API) GitHubOAuth(c fiber.Ctx) error
- func (a *API) GoogleOAuth(c fiber.Ctx) error
- func (a *API) Logout(c fiber.Ctx) error
- func (a *API) RefreshToken(c fiber.Ctx) error
- func (a *API) ResendVerificationEmail(c fiber.Ctx) error
- func (a *API) SignIn(c fiber.Ctx) error
- func (a *API) SignUp(c fiber.Ctx) error
- func (a *API) UpdateProfile(c fiber.Ctx) error
- func (a *API) VerifyEmail(c fiber.Ctx) error
- type APICfg
- type GitHubOAuthClient
- type GoogleIDTokenClient
- type UserFacade
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API describes dependencies for auth endpoints
func NewAPI ¶
func NewAPI(log *zap.Logger, googleIDTokenClient GoogleIDTokenClient, githubOAuthClient GitHubOAuthClient, userFacade UserFacade, cfg APICfg) (*API, error)
NewAPI return new instance of auth api
func (*API) DeleteAccount ¶ added in v1.3.0
DeleteAccount deletes user account and clears refresh token cookie
func (*API) GitHubOAuth ¶ added in v1.3.0
GitHubOAuth signs in or signs up user with GitHub authorization code, returns access token and sets refresh token cookie
func (*API) GoogleOAuth ¶ added in v1.3.0
GoogleOAuth signs in or signs up user with Google ID token, returns access token and sets refresh token cookie
func (*API) Logout ¶ added in v1.3.0
Logout revokes refresh token from cookie if present and clears refresh token cookie
func (*API) RefreshToken ¶ added in v1.3.0
RefreshToken exchanges refresh token cookie for new access token and rotates refresh token cookie
func (*API) ResendVerificationEmail ¶ added in v1.3.0
ResendVerificationEmail queues email verification code for asynchronous delivery
func (*API) SignIn ¶ added in v1.3.0
SignIn authenticates user with username and password, returns access token and sets refresh token cookie
func (*API) SignUp ¶ added in v1.3.0
SignUp creates new user account, returns access token and sets refresh token cookie
func (*API) UpdateProfile ¶ added in v1.3.0
UpdateProfile updates user name and/or password, returns new access token and sets refresh token cookie
type APICfg ¶
type APICfg struct {
RefreshTokenCookieSameSite string
RefreshTokenCookieSecure bool
ContactEmail string
}
APICfg describes configuration for auth api
type GitHubOAuthClient ¶
type GitHubOAuthClient interface {
ExchangeCodeForUser(ctx context.Context, code string) (githubapi.UserInfo, error)
}
GitHubOAuthClient provides methods for GitHub OAuth authentication
type GoogleIDTokenClient ¶
type GoogleIDTokenClient interface {
ValidateIDToken(ctx context.Context, idToken string) (*idtoken.Payload, error)
}
GoogleIDTokenClient provides methods for validating Google ID tokens
type UserFacade ¶
type UserFacade interface {
GoogleOAuth(ctx context.Context, oauthID, email string, emailVerified bool) (model.User, error)
GitHubOAuth(ctx context.Context, oauthID, email, username string, emailVerified bool) (model.User, error)
DeleteUser(ctx context.Context, userID string) error
UpdateUserProfile(ctx context.Context, userID string, params model.UpdateProfileParams) (model.User, error)
VerifyEmail(ctx context.Context, userID string, code string) (model.User, error)
ResendVerificationEmail(ctx context.Context, userID string) error
SignIn(ctx context.Context, username, password string) (model.User, error)
SignUp(ctx context.Context, username, displayName, email, password string, isPublisher bool) (model.User, error)
CreateTokens(ctx context.Context, user model.User) (facade.TokenPair, error)
RefreshTokens(ctx context.Context, refreshTokenStr string) (facade.TokenPair, error)
RevokeRefreshToken(ctx context.Context, refreshTokenStr string) error
ValidateAccessToken(tokenStr string) bool
GetClaimsFromAccessToken(tokenStr string) (auth.Claims, error)
}
UserFacade provides methods for working with user facade