action

package
v0.0.0-...-726ff5c Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const IdentityTypeGoogle = "google"

Variables

View Source
var ErrAccountIsBlocked = errsys.New("account is blocked", "Your account is blocked. Please contact support.")
View Source
var ErrFailedToExchangeToken = errsys.New(
	"failed to exchange token",
	"There is an issue to exchange Google token. Please try again later or contact support",
)
View Source
var ErrFailedToGetUserInfo = errsys.New(
	"failed to get user info",
	"There is an issue to get user info from Google. Please try again later",
)
View Source
var ErrInvalidIdentity = errsys.New(
	"invalid identity",
	"The Google registration is broken. We cannot authenticate you at the moment. Please try again later or use another type of registration.",
)
View Source
var ErrUserAlreadyExists = erruser.New(
	"user already exists",
	"User with such email already exists. Please log in using another type of authentication.",
)

Functions

This section is empty.

Types

type DefaultUserCreator

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

func (*DefaultUserCreator) CreateUserFromGoogle

func (c *DefaultUserCreator) CreateUserFromGoogle(ctx context.Context, user User) (User, error)

type GoogleConfig

type GoogleConfig struct {
	RedirectUrl  string   `env:"AUTH_GOOGLE_REDIRECT_URL, default=http://localhost:8001/auth/google/callback"`
	ClientID     string   `env:"AUTH_GOOGLE_CLIENT_ID"`
	ClientSecret string   `env:"AUTH_GOOGLE_SECRET"`
	Scopes       []string `env:"AUTH_GOOGLE_SCOPES, default=openid,email,profile"`
}

type GoogleUser

type GoogleUser struct {
	ID            string `json:"id"`
	Email         string `json:"email"`
	VerifiedEmail bool   `json:"verified_email"`
	Name          string `json:"name"`
	GivenName     string `json:"given_name"`
	FamilyName    string `json:"family_name"`
	Picture       string `json:"picture"`
	Locale        string `json:"locale"`
}

type Register

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

func NewRegister

func NewRegister(
	config GoogleConfig,
	plainTokenAuth *auth.PlainTokenAuthenticator,
	identityRepository repository.IdentityRepository,
	accountRepository repository.AccountRepository,
	creator UserCreator,
) *Register

func (*Register) Execute

func (r *Register) Execute(ctx context.Context, input RegisterInput) (auth.TokenPair, error)

type RegisterInput

type RegisterInput struct {
	Code        string                 `json:"code"`
	Verifier    string                 `json:"verifier"`
	RedirectUrl string                 `json:"redirectUrl"`
	Roles       []string               `json:"roles"`
	UserInfo    map[string]interface{} `json:"userInfo"`
}

type User

type User struct {
	ID                          uuid.UUID
	Email                       string
	GoogleUser                  GoogleUser
	UserInfo                    map[string]interface{}
	SubscribedToMarketingEmails bool
}

type UserCreator

type UserCreator interface {
	// CreateUserFromGoogle creates a new user with id and email.
	// It returns the created user.
	// Errors:
	// * ErrUserAlreadyExists - if the user already exists. In a case of this error it should return the existing user.
	CreateUserFromGoogle(ctx context.Context, user User) (User, error)
}

func NewDefaultUserCreator

func NewDefaultUserCreator(logger *slog.Logger) UserCreator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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