tokenservice

package
v0.0.0-...-a9081ec Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package tokenservice holds the business logic and data structures associated with the token domain.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearCookies

func ClearCookies(c *gin.Context, host *configs.Host)

ClearCookies will clear the cookie for the id and refresh tokens

func IsInvalidToken

func IsInvalidToken(err error) bool

IsInvalidToken return boolean and compare error with InvalidTokenError

Types

type Config

type Config struct {
	TokenRepository Repository
	StudCert        *configs.CertPair
	AdminCert       *configs.CertPair
	Logger          *otelzap.Logger
	Tracer          trace.Tracer
	Conf            *configs.Jwt
}

Config will hold repository and used utils that will be injected into this Service layer on service initialization

type IDToken

type IDToken struct {
	SignedToken string `json:"idToken"`
}

IDToken model info

@Description	IDToken stores token properties that
@Description	are accessed in multiple application layers

type Interface

type Interface interface {
	NewPairFromStudent(ctx context.Context, u *ent.Student, prevTokenID string) (*PairToken, error)
	NewPairFromAdmin(ctx context.Context, u *ent.Admin, prevTokenID string) (*PairToken, error)
	Signout(ctx context.Context, uid uuid.UUID) error
	ValidateStudentIDToken(ctx context.Context, tokenString string) (*ent.Student, error)
	ValidateAdminIDToken(ctx context.Context, tokenString string) (*ent.Admin, error)
	GetRoleFromIDToken(tokenString string) (primitive.Roles, error)
	ValidateRefreshToken(ctx context.Context, refreshTokenString string) (*RefreshToken, error)
}

Interface specifies the business operations of the service.

func New

func New(c *Config) Interface

New configures and returns an Interface implementation.

type InvalidTokenError

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

InvalidTokenError is used to indicate an error with a provided token

func NewInvalidToken

func NewInvalidToken(label string) *InvalidTokenError

NewInvalidToken return invalid token error to client in proper manner

func (*InvalidTokenError) Error

func (e *InvalidTokenError) Error() string

Error implements the error interface.

type MockInterface

type MockInterface struct {
	mock.Mock
}

MockInterface is an autogenerated mock type for the Interface type

func NewMockInterface

func NewMockInterface(t mockConstructorTestingTNewMockInterface) *MockInterface

NewMockInterface creates a new instance of MockInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockInterface) GetRoleFromIDToken

func (_m *MockInterface) GetRoleFromIDToken(tokenString string) (primitive.Roles, error)

GetRoleFromIDToken provides a mock function with given fields: tokenString

func (*MockInterface) NewPairFromAdmin

func (_m *MockInterface) NewPairFromAdmin(ctx context.Context, u *ent.Admin, prevTokenID string) (*PairToken, error)

NewPairFromAdmin provides a mock function with given fields: ctx, u, prevTokenID

func (*MockInterface) NewPairFromStudent

func (_m *MockInterface) NewPairFromStudent(ctx context.Context, u *ent.Student, prevTokenID string) (*PairToken, error)

NewPairFromStudent provides a mock function with given fields: ctx, u, prevTokenID

func (*MockInterface) Signout

func (_m *MockInterface) Signout(ctx context.Context, uid uuid.UUID) error

Signout provides a mock function with given fields: ctx, uid

func (*MockInterface) ValidateAdminIDToken

func (_m *MockInterface) ValidateAdminIDToken(ctx context.Context, tokenString string) (*ent.Admin, error)

ValidateAdminIDToken provides a mock function with given fields: ctx, tokenString

func (*MockInterface) ValidateRefreshToken

func (_m *MockInterface) ValidateRefreshToken(ctx context.Context, refreshTokenString string) (*RefreshToken, error)

ValidateRefreshToken provides a mock function with given fields: ctx, refreshTokenString

func (*MockInterface) ValidateStudentIDToken

func (_m *MockInterface) ValidateStudentIDToken(ctx context.Context, tokenString string) (*ent.Student, error)

ValidateStudentIDToken provides a mock function with given fields: ctx, tokenString

type MockRepository

type MockRepository struct {
	mock.Mock
}

MockRepository is an autogenerated mock type for the Repository type

func NewMockRepository

func NewMockRepository(t mockConstructorTestingTNewMockRepository) *MockRepository

NewMockRepository creates a new instance of MockRepository. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.

func (*MockRepository) DeleteRefreshToken

func (_m *MockRepository) DeleteRefreshToken(ctx context.Context, userID string, prevTokenID string) error

DeleteRefreshToken provides a mock function with given fields: ctx, userID, prevTokenID

func (*MockRepository) DeleteUserRefreshTokens

func (_m *MockRepository) DeleteUserRefreshTokens(ctx context.Context, userID string) error

DeleteUserRefreshTokens provides a mock function with given fields: ctx, userID

func (*MockRepository) SetRefreshToken

func (_m *MockRepository) SetRefreshToken(ctx context.Context, userID string, tokenID string, expiresIn time.Duration) error

SetRefreshToken provides a mock function with given fields: ctx, userID, tokenID, expiresIn

type PairToken

type PairToken struct {
	*IDToken
	*RefreshToken
}

PairToken model info

@Description	PairToken is used for returning pairs
@Description	of id and refresh tokens

func (*PairToken) SetCookies

func (r *PairToken) SetCookies(c *gin.Context, duration *configs.Jwt, host *configs.Host)

SetCookies will set the cookie for the id and refresh tokens

func (*PairToken) ToFront

func (r *PairToken) ToFront() *PairToken

ToFront is the structure returned to the frontend

type RefreshToken

type RefreshToken struct {
	SignedToken string    `json:"refreshToken"`
	ID          uuid.UUID `json:"-"`
	UID         uuid.UUID `json:"-"`
}

RefreshToken model info

@Description	RefreshToken stores token properties that
@Description	are accessed in multiple application layers

type Repository

type Repository interface {
	SetRefreshToken(ctx context.Context, userID string, tokenID string, expiresIn time.Duration) error
	DeleteRefreshToken(ctx context.Context, userID string, prevTokenID string) error
	DeleteUserRefreshTokens(ctx context.Context, userID string) error
}

Repository contain all the function available in the defined domain

Jump to

Keyboard shortcuts

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