core

package
v0.0.0-...-3c02646 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAuthInvalidCredentials is returned when the credentials provided are invalid.
	ErrAuthInvalidCredentials = errors.New("credentials provided are not valid")

	// ErrAuthPasswordNotSet is returned when a User attempts to authenticate with a password but
	// has not yet set a password (such as when creating their account with a provider).
	ErrAuthPasswordNotSet = errors.New("password is not set")

	// ErrAuthEmailAlreadyRegistered is returned when a User attempts to register with an email address
	// that is already in-use.
	ErrAuthEmailAlreadyRegistered = errors.New("email already registered")
)
View Source
var (
	// ErrSessionsSessionDoesNotExist is returned when a session being terminates does not
	// exist.
	ErrSessionsSessionDoesNotExist = errors.New("session does not exist")
)

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Type AccessTokenType
	Data *ent.Token
	// contains filtered or unexported fields
}

AccessToken is an access token for User and Bot access.

func (*AccessToken) String

func (a *AccessToken) String() (string, error)

type AccessTokenType

type AccessTokenType int

AccessTokenType represents the type of object an AccessToken is issued to.

const (
	// UserAccessTokenType represents an AccessToken issued to a User.
	UserAccessTokenType AccessTokenType = iota + 1

	// BotAccessTokenType represents an AccessToken issued to a Bot.
	BotAccessTokenType
)

type AuthService

type AuthService interface {

	// TokenFromCredentials returns a token given valid credentials or an error if the credetnails are invalid.
	TokenFromCredentials(ctx context.Context, opts *TokenFromCredentialsOptions) (*TokenResult, error)

	// TokenFromProvider returns a token given valid provider credentials or an error if the credetnails are invalid.
	TokenFromProvider(ctx context.Context, opts *TokenFromProviderOptions) (*TokenResult, error)

	// Register is called when registering a User.
	Register(ctx context.Context, opts *RegisterOptions) (*ent.User, error)
}

AuthService handles user authentication.

type Backend

type Backend interface {
	Database() *database.Database
	Events() events.PubSub
	Cluster() cluster.Cluster
}

Backend describes the methods requires to properly initialize Core.

type Core

type Core struct {
	Auth     AuthService
	Users    UsersService
	Sessions SessionsService
	// contains filtered or unexported fields
}

Core is a wrapper around database and application logic, queries, and event subscribers.

func New

func New(logger log.ComponentLogger, svcs Backend) (*Core, error)

New initializes a new Core instance using the services implementation.

type CreateSessionOptions

type CreateSessionOptions struct {
	UserID                int
	BrowserName           string
	BrowserVersion        string
	DeviceType            string
	DeviceOperatingSystem string
	IPAddress             string
}

CreateSessionOptions configures the CreateSession method.

type CreateTokenOptions

type CreateTokenOptions struct {
	SessionID     int
	UserID        int
	TokenDuration time.Duration
	Claims        *TokenClaims
}

CreateTokenOptions configures the CreateToken

type RegisterOptions

type RegisterOptions struct {
	Name     string
	Email    string
	Password string
}

RegisterOptions configures the registration of a User.

type ResponseTokenClaims

type ResponseTokenClaims struct {
	Name string
}

ResponseTokenClaims contains the Response-specific claims stored in JWT's.

type SessionsService

type SessionsService interface {
	GetSession(ctx context.Context, id int) (*ent.Session, error)
	CreateSession(ctx context.Context, opts *CreateSessionOptions) (*ent.Session, error)
	TerminateSession(ctx context.Context, opts *TerminateSessionOptions) error
}

SessionsService allows managing sessions in Response.

type TerminateSessionOptions

type TerminateSessionOptions struct {
	SessionID int
	Reason    string
}

TerminateSessionOptions configures the TerminateSession method.

type TokenClaims

type TokenClaims struct {
	jwt.StandardClaims
	Response ResponseTokenClaims
}

TokenClaims are the standard and Respnose-specific claims stored in JWT's.

type TokenFromCredentialsOptions

type TokenFromCredentialsOptions struct {
	Email                 string
	Password              string
	BrowserName           string
	BrowserVersion        string
	DeviceType            string
	DeviceOperatingSystem string
	IPAddress             string
}

TokenFromCredentialsOptions configures the TokenFromCredentials method.

type TokenFromProviderOptions

type TokenFromProviderOptions struct {
	Provider    int
	AccessToken string
}

TokenFromProviderOptions configures the TokenFromProvider method.

type TokenResult

type TokenResult struct {
	Token     *AccessToken
	ExpiredAt time.Time
}

TokenResult provides a token when the token has been succcessfully created from an authentication attempt.

type Users

type Users []*ent.User

Users represents many User instances.

type UsersService

type UsersService interface {
	GetUserByID(ctx context.Context, id int) (*ent.User, error)
	GetUserByEmail(ctx context.Context, email string) (*ent.User, error)
}

UsersService is an instance of the service that contols users, updates to users, and user subscribers.

Jump to

Keyboard shortcuts

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