auth

package
v0.0.0-...-75e7317 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 17 Imported by: 0

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_INVALID_TOKEN                = "invalid token"
	MSG_TOKEN_EXPIRED                = "token expired"
	MSG_CREATE_ACTIVATION_MAIL_ERROR = "error while creating activation email"
	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"
	MSG_USER_IS_INACTIVE             = "user is inactive"
	MSG_INVALID_REGISTRATION         = "username, 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"

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

Functions

func CreateActivationEmail

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

func CreateConfirmationURL

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

func CreateRecoveryEmail

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

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

func SendConfirmationEmail

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

func ValidateConfirmationToken

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

func ValidateRegisterData

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

Types

type Activation

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

type Confirmation

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

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

type GoogleUserResponse

type GoogleUserResponse struct {
	ID      string `json:"id"`
	Email   string `json:"email"`
	Name    string `json:"name"`
	Picture string `json:"picture"`
}

type LocalProvider

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

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

func (la *LocalProvider) Activate(c fs.Context, _ any) (*Activation, error)

func (*LocalProvider) Callback

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

func (*LocalProvider) Init

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

func (*LocalProvider) LocalLogin

func (la *LocalProvider) LocalLogin(c fs.Context, payload *LoginData) (_ *LoginResponse, err error)

func (*LocalProvider) Login

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

func (*LocalProvider) Name

func (la *LocalProvider) Name() string

func (*LocalProvider) Recover

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

Masking error reason for security reasons

func (*LocalProvider) RecoverCheck

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

func (*LocalProvider) Register

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

func (*LocalProvider) ResetPassword

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

type LoginData

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

type LoginResponse

type LoginResponse struct {
	Token   string    `json:"token"`
	Expires time.Time `json:"expires"`
}

type Recovery

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

type Register

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

func (*Register) Entity

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

type ResetPassword

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