auth

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const ProviderGithub = "github"
View Source
const ProviderGoogle = "google"
View Source
const ProviderLocal = "local"

Variables

View Source
var (
	MSG_USER_SAVE_ERROR               = "Error saving user"
	MSG_USER_ACTIVATION_ERROR         = "Error activating user"
	MSG_USER_ALREADY_ACTIVE           = "Your account is already activated"
	MSG_INVALID_TOKEN                 = "Invalid token"
	MSG_TOKEN_EXPIRED                 = "Token expired"
	MSG_CREATE_ACTIVATION_MAIL_ERROR  = "Error while creating activation email: %w"
	MSG_USER_UPDATE_PROVIDER_ID_ERROR = "Error while update provider id: %w"
	MSG_CREATEP_RECOVERY_MAIL_ERROR   = "Error while creating recovery email"
	MSG_INVALID_EMAIL                 = "Invalid email"
	MSG_INVALID_PASSWORD              = "Invalid password"
	MSG_INVALID_LOGIN_OR_PASSWORD     = "Invalid login or password" //nolint:gosec // G101: This is an error message, not a hardcoded credential
	MSG_USER_IS_INACTIVE              = "User is inactive"
	MSG_INVALID_REGISTRATION          = "Email, password and confirm_password are required"
	MSG_SEND_ACTIVATION_EMAIL_ERROR   = "Error while sending activation email"
	MSG_MAILER_NOT_SET                = "Mailer is not set"
	MSG_CHECKING_USER_ERROR           = "Error checking user"
	MSG_USER_EXISTS                   = "User already exists"
	MSG_EXISTING_USER_WITH_EMAIL      = "" /* 147-byte string literal not displayed */

	ERR_SAVE_USER           = errors.InternalServerError(MSG_USER_SAVE_ERROR)
	ERR_INVALID_TOKEN       = errors.BadRequest(MSG_INVALID_TOKEN)
	ERR_TOKEN_EXPIRED       = errors.BadRequest(MSG_TOKEN_EXPIRED)
	ERR_INVALID_LOGIN       = errors.UnprocessableEntity(MSG_INVALID_LOGIN_OR_PASSWORD)
	ERR_USER_ALREADY_ACTIVE = errors.BadRequest(MSG_USER_ALREADY_ACTIVE)
)

Functions

func CreateActivationEmail added in v0.6.0

func CreateActivationEmail(la *LocalProvider, user *fs.User) (*fs.Mail, error)

func CreateConfirmationURL added in v0.6.0

func CreateConfirmationURL(baseURL, appKey string, user *fs.User) (string, error)

func CreateRecoveryEmail added in v0.6.0

func CreateRecoveryEmail(la *LocalProvider, user *fs.User) (*fs.Mail, error)

func NewGithubAuthProvider

func NewGithubAuthProvider(config fs.Map, redirectURL string) (fs.AuthProvider, error)

func NewGoogleAuthProvider

func NewGoogleAuthProvider(config fs.Map, redirectURL string) (fs.AuthProvider, error)

func NewLocalAuthProvider added in v0.5.0

func NewLocalAuthProvider(config fs.Map, redirectURL string) (fs.AuthProvider, error)

func SendConfirmationEmail added in v0.6.0

func SendConfirmationEmail(la *LocalProvider, logger logger.Logger, mail *fs.Mail)

func ValidateConfirmationToken added in v0.6.0

func ValidateConfirmationToken(token, key string) (uint64, error)

func ValidateRegisterData added in v0.6.0

func ValidateRegisterData(
	c context.Context,
	logger logger.Logger,
	dbClient db.Client,
	payload *Register,
) (err error)

Types

type Activation added in v0.6.0

type Activation struct {
	Activation string `json:"activation"` // auto, manual, email, activated
}

type Confirmation added in v0.6.0

type Confirmation struct {
	Token string `json:"token"`
}

type GithubAccessTokenResponse

type GithubAccessTokenResponse struct {
	Scope       string `json:"scope"`
	TokenType   string `json:"token_type"`
	AccessToken string `json:"access_token"`
}

type GithubAuthProvider

type GithubAuthProvider struct {
	// contains filtered or unexported fields
}

func (*GithubAuthProvider) Callback

func (ga *GithubAuthProvider) Callback(c fs.Context) (_ *fs.User, err error)

func (*GithubAuthProvider) Login

func (ga *GithubAuthProvider) Login(c fs.Context) (_ any, err error)

func (*GithubAuthProvider) Name

func (ga *GithubAuthProvider) Name() string

func (*GithubAuthProvider) VerifyIDToken added in v0.7.5

func (ga *GithubAuthProvider) VerifyIDToken(c fs.Context, t fs.IDToken) (_ *fs.User, err error)

func (*GithubAuthProvider) WithResources added in v0.6.0

func (ga *GithubAuthProvider) WithResources(resource *fs.Resource)

type GithubUserResponse

type GithubUserResponse struct {
	Login     string `json:"login"`
	ID        int    `json:"id"`
	AvatarURL string `json:"avatar_url"`
	Name      string `json:"name"`
	Blog      string `json:"blog"`
	Email     string `json:"email"`
	Bio       string `json:"bio"`
}

type GoogleAuthProvider

type GoogleAuthProvider struct {
	// contains filtered or unexported fields
}

func (*GoogleAuthProvider) Callback

func (as *GoogleAuthProvider) Callback(c fs.Context) (_ *fs.User, err error)

func (*GoogleAuthProvider) Login

func (as *GoogleAuthProvider) Login(c fs.Context) (_ any, err error)

func (*GoogleAuthProvider) Name

func (as *GoogleAuthProvider) Name() string

func (*GoogleAuthProvider) VerifyIDToken added in v0.7.5

func (as *GoogleAuthProvider) VerifyIDToken(c fs.Context, t fs.IDToken) (_ *fs.User, err error)

type GoogleUser added in v0.7.3

type GoogleUser struct {
	Issuer    string    `json:"iss"`
	Audience  string    `json:"aud"`
	ExpiresAt time.Time `json:"exp"`
	IssuedAt  time.Time `json:"iat"`

	ID            string `json:"id"` // Using token Subject as ID
	Email         string `json:"email"`
	Name          string `json:"name"`
	GivenName     string `json:"given_name"`
	FamilyName    string `json:"family_name"`
	Locale        string `json:"locale"`
	Picture       string `json:"picture"`
	EmailVerified bool   `json:"email_verified"`
	HD            string `json:"hd"`
}

func (*GoogleUser) ToFSUser added in v0.7.5

func (gu *GoogleUser) ToFSUser() *fs.User

type LocalProvider added in v0.6.0

type LocalProvider struct {
	// contains filtered or unexported fields
}

LocalProvider represents the local authentication provider.

config: activationMethod: auto, manual, email

auto: user is activated automatically
manual: user is activated manually by admin
email: user is activated by email

func (*LocalProvider) Activate added in v0.6.0

func (la *LocalProvider) Activate(c fs.Context, data *Confirmation) (*Activation, error)

func (*LocalProvider) Callback added in v0.6.0

func (la *LocalProvider) Callback(c fs.Context) (user *fs.User, err error)

func (*LocalProvider) Init added in v0.6.0

func (la *LocalProvider) Init(
	db func() db.Client,
	appKey func() string,
	appName func() string,
	appBaseURL func() string,
	mailer func(names ...string) fs.Mailer,
	jwtCustomClaimsFunc func() fs.JwtCustomClaimsFunc,
)

func (*LocalProvider) LocalLogin added in v0.6.0

func (la *LocalProvider) LocalLogin(c fs.Context, payload *LoginData) (*fs.User, error)

LocalLogin performs local login with username/email and password

func (*LocalProvider) Login added in v0.6.0

func (la *LocalProvider) Login(c fs.Context) (_ any, err error)

func (*LocalProvider) Name added in v0.6.0

func (la *LocalProvider) Name() string

func (*LocalProvider) Recover added in v0.6.0

func (la *LocalProvider) Recover(c fs.Context, data *Recovery) (_ bool, err error)

func (*LocalProvider) RecoverCheck added in v0.6.0

func (la *LocalProvider) RecoverCheck(c fs.Context, data *Confirmation) (_ bool, err error)

func (*LocalProvider) Register added in v0.6.0

func (la *LocalProvider) Register(c fs.Context, payload *Register) (*Activation, error)

func (*LocalProvider) ResetPassword added in v0.6.0

func (la *LocalProvider) ResetPassword(c fs.Context, data *ResetPassword) (_ bool, err error)
func (la *LocalProvider) SendActivationLink(c fs.Context, data *Confirmation) (*Activation, error)

func (*LocalProvider) VerifyIDToken added in v0.7.5

func (la *LocalProvider) VerifyIDToken(c fs.Context, t fs.IDToken) (user *fs.User, err error)

type LoginData added in v0.5.0

type LoginData struct {
	Login    string `json:"login"`
	Password string `json:"password"`
}

type Recovery added in v0.6.0

type Recovery struct {
	Email string `json:"email"`
}

type Register added in v0.6.0

type Register struct {
	Username        string `json:"username"`
	Email           string `json:"email"`
	FirstName       string `json:"first_name"`
	LastName        string `json:"last_name"`
	Password        string `json:"password"`
	ConfirmPassword string `json:"confirm_password"`
}

func (*Register) Entity added in v0.6.0

func (d *Register) Entity(activationMethod, provider string) *entity.Entity

type ResetPassword added in v0.6.0

type ResetPassword struct {
	*Confirmation

	Password        string `json:"password"`
	ConfirmPassword string `json:"confirm_password"`
}

Jump to

Keyboard shortcuts

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