auth

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("token not found")
)

Functions

This section is empty.

Types

type APIToken

type APIToken struct {
	ID         int64
	EntityType TokenType
	EntityID   int64
	CreatedAt  time.Time
	Token      string
	Name       *string
	UUID       uuid.UUID
	Settings   []byte
}

type Config

type Config struct {
	Google GoogleConfig `yaml:"google"`
	Email  EmailConfig  `yaml:"email"`
}

func (*Config) EnabledProviders

func (c *Config) EnabledProviders() []ProviderType

type EmailConfig

type EmailConfig struct {
	Enabled        bool   `yaml:"enabled" env:"EMAIL_AUTH_ENABLED" env-default:"true" env-description:"Enables email auth"`
	FirstUserEmail string `yaml:"user_email" env:"EMAIL_AUTH_USER_EMAIL" env-description:"Email of an user that will be created on a first startup"`
	FirstUserPass  string `` /* 129-byte string literal not displayed */
}

type GoogleConfig

type GoogleConfig struct {
	Enabled               bool   `yaml:"enabled" env:"GOOGLE_AUTH_ENABLED" env-default:"false" env-description:"Internal variable"`
	ClientID              string `yaml:"client_id" env:"GOOGLE_AUTH_CLIENT_ID" env-description:"Internal variable"`
	ClientSecret          string `yaml:"client_secret" env:"GOOGLE_AUTH_CLIENT_SECRET" env-description:"Internal variable"`
	RedirectCallback      string `yaml:"redirect_callback" env:"GOOGLE_AUTH_REDIRECT_CALLBACK" env-description:"Internal variable"`
	AuthenticatedRedirect string `yaml:"authenticated_redirect" env:"GOOGLE_AUTH_REDIRECT_SUCCESS" env-default:"/dashboard" env-description:"Internal variable"`
}

type GoogleOAuthManager

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

func NewGoogleOAuth

func NewGoogleOAuth(cfg GoogleConfig, logger *zerolog.Logger) *GoogleOAuthManager

func (*GoogleOAuthManager) GetAuthenticatedRedirectURL

func (a *GoogleOAuthManager) GetAuthenticatedRedirectURL() string

GetAuthenticatedRedirectURL returns a URL where user should be redirected when already authenticated.

func (*GoogleOAuthManager) RedirectURLWithState added in v0.4.0

func (a *GoogleOAuthManager) RedirectURLWithState() (string, string)

RedirectURLWithState return URL to Google auth screen.

func (*GoogleOAuthManager) ResolveUser

func (a *GoogleOAuthManager) ResolveUser(ctx context.Context, code string) (*GoogleUser, error)

type GoogleUser

type GoogleUser struct {
	Sub           string `json:"sub"`
	Name          string `json:"name"`
	GivenName     string `json:"given_name"`
	FamilyName    string `json:"family_name"`
	Picture       string `json:"picture"`
	Email         string `json:"email"`
	EmailVerified bool   `json:"email_verified"`
	Locale        string `json:"locale"`
}

type ProviderType

type ProviderType string
const (
	ProviderTypeGoogle ProviderType = "google"
	ProviderTypeEmail  ProviderType = "email"
)

type TokenAuthManager

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

func NewTokenAuth

func NewTokenAuth(repo *repository.Queries, logger *zerolog.Logger) *TokenAuthManager

func (*TokenAuthManager) CreateMerchantToken

func (m *TokenAuthManager) CreateMerchantToken(ctx context.Context, merchantID int64, name string) (*APIToken, error)

func (*TokenAuthManager) CreateUserToken

func (m *TokenAuthManager) CreateUserToken(ctx context.Context, merchantID int64, name string) (*APIToken, error)

func (*TokenAuthManager) DeleteToken

func (m *TokenAuthManager) DeleteToken(ctx context.Context, id int64) error

func (*TokenAuthManager) GetMerchantTokenByUUID

func (m *TokenAuthManager) GetMerchantTokenByUUID(ctx context.Context, merchantID int64, id uuid.UUID) (*APIToken, error)

func (*TokenAuthManager) GetToken

func (m *TokenAuthManager) GetToken(ctx context.Context, tokenType TokenType, token string) (*APIToken, error)

func (*TokenAuthManager) GetTokenByUUID

func (m *TokenAuthManager) GetTokenByUUID(ctx context.Context, id uuid.UUID) (*APIToken, error)

func (*TokenAuthManager) ListByEntityType

func (m *TokenAuthManager) ListByEntityType(
	ctx context.Context,
	tokenType TokenType,
	entityID int64,
) ([]*APIToken, error)

type TokenType

type TokenType string
const (
	TokenTypeUser     TokenType = "user"
	TokenTypeMerchant TokenType = "merchant"
)

Jump to

Keyboard shortcuts

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