Documentation ¶
Overview ¶
Package tokenservice holds the business logic and data structures associated with the token domain.
Index ¶
- func ClearCookies(c *gin.Context, host *configs.Host)
- func IsInvalidToken(err error) bool
- type Config
- type IDToken
- type Interface
- type InvalidTokenError
- type MockInterface
- func (_m *MockInterface) GetRoleFromIDToken(tokenString string) (primitive.Roles, error)
- func (_m *MockInterface) NewPairFromAdmin(ctx context.Context, u *ent.Admin, prevTokenID string) (*PairToken, error)
- func (_m *MockInterface) NewPairFromStudent(ctx context.Context, u *ent.Student, prevTokenID string) (*PairToken, error)
- func (_m *MockInterface) Signout(ctx context.Context, uid uuid.UUID) error
- func (_m *MockInterface) ValidateAdminIDToken(ctx context.Context, tokenString string) (*ent.Admin, error)
- func (_m *MockInterface) ValidateRefreshToken(ctx context.Context, refreshTokenString string) (*RefreshToken, error)
- func (_m *MockInterface) ValidateStudentIDToken(ctx context.Context, tokenString string) (*ent.Student, error)
- type MockRepository
- func (_m *MockRepository) DeleteRefreshToken(ctx context.Context, userID string, prevTokenID string) error
- func (_m *MockRepository) DeleteUserRefreshTokens(ctx context.Context, userID string) error
- func (_m *MockRepository) SetRefreshToken(ctx context.Context, userID string, tokenID string, expiresIn time.Duration) error
- type PairToken
- type RefreshToken
- type Repository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearCookies ¶
ClearCookies will clear the cookie for the id and refresh tokens
func IsInvalidToken ¶
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.
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 ¶
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) 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 ¶
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 ¶
SetCookies will set the cookie for the id and refresh tokens
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