service

package
v0.0.0-...-dad66ff Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAccountService

func NewAccountService(cfg *config.Config, r AccountRepo, s Session) *accountService

func NewAuthService

func NewAuthService(cfg *config.Config, t jwt.Token, a Account, s Session) *authService

func NewSessionService

func NewSessionService(cfg *config.Config, s SessionRepo) *sessionService

func NewSocialAuthService

func NewSocialAuthService(cfg *config.Config, a Account, s Session) *socialAuthService

Types

type Account

type Account interface {
	// Create new account, username, email and password should be provided, returns account id.
	Create(ctx context.Context, a domain.Account) (string, error)

	// GetByID account.
	GetByID(ctx context.Context, aid string) (domain.Account, error)

	// GetByEmail account.
	GetByEmail(ctx context.Context, email string) (domain.Account, error)

	// Delete sets account IsArchive state to true.
	Delete(ctx context.Context, aid, sid string) error

	// Verify verifies account using provided code.
	Verify(ctx context.Context, code string) error
}

type AccountRepo

type AccountRepo interface {
	// Create account with given credentials, returns id of created account.
	Create(ctx context.Context, a domain.Account) (string, error)

	// FindByID account in DB.
	FindByID(ctx context.Context, aid string) (domain.Account, error)

	// FindByEmail account in DB.
	FindByEmail(ctx context.Context, email string) (domain.Account, error)

	// Archive sets entity.Account.IsArchive state to provided value.
	Archive(ctx context.Context, aid string, archive bool) error
}

type Auth

type Auth interface {
	// EmailLogin creates new session using provided account email and password.
	EmailLogin(ctx context.Context, email, password string, d Device) (domain.Session, error)

	// Logout logs out session by id.
	Logout(ctx context.Context, sid string) error

	// NewAccessToken generates JWT token which must be used to perform protected operations.
	NewAccessToken(ctx context.Context, aid, password string) (string, error)

	// ParseAccessToken parses and validates JWT access token, returns subject from payload.
	ParseAccessToken(ctx context.Context, t string) (string, error)
}

type Device

type Device struct {
	UserAgent string
	IP        string
}

Device represents data transfer object with user device data

type Session

type Session interface {
	// Create new session for account with id and device of given provider.
	Create(ctx context.Context, aid, provider string, d Device) (domain.Session, error)

	// GetByID session.
	GetByID(ctx context.Context, sid string) (domain.Session, error)

	// GetAll account sessions using provided account id.
	GetAll(ctx context.Context, aid string) ([]domain.Session, error)

	// Terminate session by id excluding current session with id.
	Terminate(ctx context.Context, sid, currSid string) error

	// TerminateAll account sessions excluding current session with id.
	TerminateAll(ctx context.Context, aid, sid string) error
}

type SessionRepo

type SessionRepo interface {
	// Create new session in DB.
	Create(ctx context.Context, s domain.Session) error

	// FindByID session.
	FindByID(ctx context.Context, sid string) (domain.Session, error)

	// FindAll accounts sessions by provided account id.
	FindAll(ctx context.Context, aid string) ([]domain.Session, error)

	// Delete session by id.
	Delete(ctx context.Context, sid string) error

	// DeleteAll account sessions by provided account id excluding current session.
	DeleteAll(ctx context.Context, aid, sid string) error
}

type SocialAuth

type SocialAuth interface {
	// AuthorizationURL returns OAuth authorization URL of given provider with
	// client id, scope and state query parameters.
	AuthorizationURL(ctx context.Context, provider string) (*url.URL, error)

	// GitHubLogin handles OAuth2 login via GitHub.
	GitHubLogin(ctx context.Context, code string, d Device) (domain.Session, error)

	// GoogleLogin handles OAuth2 login via Google.
	GoogleLogin(ctx context.Context, code string, d Device) (domain.Session, error)
}

Jump to

Keyboard shortcuts

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