auth

package
v0.0.0-...-cff5d44 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SubjectLoginStarted = "Auth.LoginStart"
)

Variables

View Source
var (
	VerificationExpired = rescode.New(3000, http.StatusForbidden, codes.Unauthenticated, "verification_expired", rescode.R{
		"isExpired": true,
	})
	VerificationExceeded = rescode.New(3001, http.StatusForbidden, codes.Unauthenticated, "verification_exceeded", rescode.R{
		"isExceeded": true,
	})
	VerificationInvalid = rescode.New(3002, http.StatusForbidden, codes.Unauthenticated, "verification_invalid", rescode.R{
		"isInvalid": true,
	})
	InvalidRefreshOrAccessTokens = rescode.New(3003, http.StatusForbidden, codes.InvalidArgument, "invalid_refresh_or_access_tokens", rescode.R{
		"isInvalid": true,
	})
	InvalidAccess = rescode.New(3004, http.StatusForbidden, codes.InvalidArgument, "invalid_access", rescode.R{
		"isInvalid": true,
	})
	InvalidOrExpiredToken = rescode.New(3005, http.StatusForbidden, codes.InvalidArgument, "invalid_or_expired_token", rescode.R{
		"isInvalidOrExpired": true,
	})
	InvalidRefreshToken = rescode.New(3006, http.StatusForbidden, codes.InvalidArgument, "invalid_refresh_token", rescode.R{
		"isInvalid": true,
	})
	Unauthorized = rescode.New(3007, http.StatusForbidden, codes.Unauthenticated, "unauthorized", rescode.R{
		"isUnauthorized": true,
	})
)

Functions

This section is empty.

Types

type EventLoginStarted

type EventLoginStarted struct {
	Email  string       `json:"email"`
	Code   string       `json:"code"`
	Device agent.Device `json:"device"`
}

type FindAllByUserOpts

type FindAllByUserOpts struct {
	UserId uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
}

type Session

type Session struct {
	DeviceId     string    `json:"device_id"`
	DeviceName   string    `json:"device_name"`
	DeviceType   string    `json:"device_type"`
	DeviceOS     string    `json:"device_os"`
	IpAddress    string    `json:"ip_address"`
	FcmToken     string    `json:"fcm_token"`
	RefreshToken string    `json:"refresh_token"`
	AccessToken  string    `json:"access_token"`
	LastLogin    time.Time `json:"last_login"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

func NewSession

func NewSession(cnf SessionConfig) *Session

func (*Session) IsAccessValid

func (s *Session) IsAccessValid(accessToken, ipAddress string) bool

func (*Session) IsRefreshValid

func (s *Session) IsRefreshValid(accessToken, refreshToken string, ipAddress string) bool

func (*Session) Refresh

func (s *Session) Refresh(token string)

func (*Session) SetFcmToken

func (s *Session) SetFcmToken(token string)

func (*Session) SetFromDevice

func (s *Session) SetFromDevice(d *agent.Device)

func (*Session) VerifyRefreshToken

func (s *Session) VerifyRefreshToken(token string) bool

func (*Session) VerifyToken

func (s *Session) VerifyToken(token string) bool

type SessionConfig

type SessionConfig struct {
	Device       agent.Device
	DeviceId     string `example:"550e8400-e29b-41d4-a716-446655440000"`
	AccessToken  string
	RefreshToken string
}

type SessionDestroyOpts

type SessionDestroyOpts struct {
	UserId   uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
	DeviceId string    `example:"device_id"`
}

type SessionFindOpts

type SessionFindOpts struct {
	UserId   uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
	DeviceId string    `example:"device_id"`
}

type SessionRepo

type SessionRepo interface {
	Save(ctx context.Context, t trace.Tracer, opts SessionSaveOpts) error
	Find(ctx context.Context, t trace.Tracer, opts SessionFindOpts) (*Session, bool, error)
	FindAllByUser(ctx context.Context, t trace.Tracer, opts FindAllByUserOpts) ([]*Session, error)
	Destroy(ctx context.Context, t trace.Tracer, opts SessionDestroyOpts) error
}

type SessionSaveOpts

type SessionSaveOpts struct {
	UserId  uuid.UUID `example:"550e8400-e29b-41d4-a716-446655440000"`
	Session *Session  `example:"{}"`
}

type Verify

type Verify struct {
	DeviceId  string    `json:"device_id"`
	Locale    string    `json:"locale"`
	UserId    uuid.UUID `json:"user_id"`
	Code      string    `json:"code"`
	TryCount  int       `json:"try_count"`
	ExpiresAt int64     `json:"expires_at"`
}

func NewVerify

func NewVerify(cnf VerifyConfig) *Verify

func (*Verify) IncTryCount

func (v *Verify) IncTryCount()

func (*Verify) IsExceeded

func (v *Verify) IsExceeded() bool

func (*Verify) IsExpired

func (v *Verify) IsExpired() bool

type VerifyConfig

type VerifyConfig struct {
	UserId   uuid.UUID
	DeviceId string
	Locale   string
}

type VerifyDeleteOpts

type VerifyDeleteOpts struct {
	Token    string `example:"token"`
	DeviceId string `example:"device_id"`
}

type VerifyFindOpts

type VerifyFindOpts struct {
	Token    string `example:"token"`
	DeviceId string `example:"device_id"`
}

type VerifyIsExistsOpts

type VerifyIsExistsOpts struct {
	Token    string `example:"token"`
	DeviceId string `example:"device_id"`
}

type VerifyRepo

type VerifyRepo interface {
	Save(ctx context.Context, t trace.Tracer, opts VerifySaveOpts) error
	IsExists(ctx context.Context, t trace.Tracer, opts VerifyIsExistsOpts) (bool, error)
	Find(ctx context.Context, t trace.Tracer, opts VerifyFindOpts) (*Verify, error)
	Delete(ctx context.Context, t trace.Tracer, opts VerifyDeleteOpts) error
}

type VerifySaveOpts

type VerifySaveOpts struct {
	Token  string  `example:"token"`
	Verify *Verify `example:"{}"`
}

Jump to

Keyboard shortcuts

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