Identity
Overview
The Identity
domain is a default domain in comby. Identities can be linked to accounts, associated with groups, and assigned tokens for secure interactions. The Identity aggregate is at the core of this domain, handling events and maintaining consistency across identity-related operations.
An Identity
can only be associated with a single Tenant. However, an account can have multiple identities, each linked to a different Tenant. This design allows a user to log in to multiple Tenants using a single account.
Structure
The Identity aggregate extends the BaseAggregate, inheriting core event-sourcing capabilities like event tracking and versioning. It includes fields to represent the identity’s relationships, attributes, and associated entities:
The Identity
is an aggregate that represents a user within a system holding entities Profile and Token. Profile contains information about the user, such as their name, email address, title, and avatar. Token represents API tokens associated with the identity, each containing a unique UUID, name, description, token value, and expiration. An identity can act as an Service Account - without an associated account.
References:
- AccountUuid: Link the identity to an existing account in the Account domain (optional).
- GroupUuids: Tracks the groups to which the identity belongs.
Entities:
- Profile: Captures personal information about the identity, such as name, email, title, and avatar.
- Tokens: Represents authentication or API tokens associated with the identity, each containing a unique UUID, name, description, token value, and expiration.
Commands
- IdentityCommandAddGroup
- IdentityCommandAddToken
- IdentityCommandCreate
- IdentityCommandRemove
- IdentityCommandRemoveAttribute
- IdentityCommandRemoveGroup
- IdentityCommandRemoveToken
- IdentityCommandSetAttribute
- IdentityCommandUpdate
- IdentityCommandUpdateProfile
IdentityCommandAddGroup
Domain Command Struct:
type IdentityCommandAddGroup struct {
IdentityUuid string `json:"identityUuid"`
GroupUuid string `json:"groupUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandAddGroup(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandAddGroup) ([]comby.Event, error)
IdentityCommandAddToken
Domain Command Struct:
type IdentityCommandAddToken struct {
IdentityUuid string `json:"identityUuid"`
TokenUuid string `json:"tokenUuid"`
TokenValue string `json:"tokenValue"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
ExpiredAt int64 `json:"expiredAt,omitempty"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandAddToken(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandAddToken) ([]comby.Event, error)
IdentityCommandCreate
Domain Command Struct:
type IdentityCommandCreate struct {
IdentityUuid string `json:"identityUuid"`
AccountUuid string `json:"accountUuid,omitempty"`
GroupUuids []string `json:"groupUuids"`
Attributes string `json:"attributes,omitempty"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandCreate(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandCreate) ([]comby.Event, error)
IdentityCommandRemove
Domain Command Struct:
type IdentityCommandRemove struct {
IdentityUuid string `json:"identityUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandRemove(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandRemove) ([]comby.Event, error)
IdentityCommandRemoveAttribute
Domain Command Struct:
type IdentityCommandRemoveAttribute struct {
IdentityUuid string `json:"identityUuid"`
Key string `json:"key"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandRemoveAttribute(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandRemoveAttribute) ([]comby.Event, error)
IdentityCommandRemoveGroup
Domain Command Struct:
type IdentityCommandRemoveGroup struct {
IdentityUuid string `json:"identityUuid"`
GroupUuid string `json:"groupUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandRemoveGroup(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandRemoveGroup) ([]comby.Event, error)
IdentityCommandRemoveToken
Domain Command Struct:
type IdentityCommandRemoveToken struct {
IdentityUuid string `json:"identityUuid"`
TokenUuid string `json:"tokenUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandRemoveToken(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandRemoveToken) ([]comby.Event, error)
IdentityCommandSetAttribute
Domain Command Struct:
type IdentityCommandSetAttribute struct {
IdentityUuid string `json:"identityUuid"`
Key string `json:"key"`
Value any `json:"value"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandSetAttribute(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandSetAttribute) ([]comby.Event, error)
IdentityCommandUpdate
Domain Command Struct:
type IdentityCommandUpdate struct {
IdentityUuid string `json:"identityUuid"`
Attributes string `json:"attributes,omitempty"`
PatchedFields []string `json:"patchedFields"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandUpdate(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandUpdate) ([]comby.Event, error)
IdentityCommandUpdateProfile
Domain Command Struct:
type IdentityCommandUpdateProfile struct {
IdentityUuid string `json:"identityUuid"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Title string `json:"title,omitempty"`
Avatar string `json:"avatar,omitempty"`
PatchedFields []string `json:"patchedFields" doc:"list of fields that should be patched - comma separated" example:"field1,field2"`
}
Domain Command Handling Method:
func (cs *commandHandler) IdentityCommandUpdateProfile(ctx context.Context, cmd comby.Command, domainCmd *IdentityCommandUpdateProfile) ([]comby.Event, error)
Queries
Domain Query Structs:
- IdentityQueryListByAccountUuid
- IdentityQueryListByAccountTenantUuid
- IdentityQueryList
- IdentityQueryModel
- IdentityQueryModelIndependentOfOrganization
Domain Query Responses:
IdentityQueryListByAccountUuid
Domain Query Struct:
type IdentityQueryListByAccountUuid struct {
AccountUuid string `json:"accountUuid"`
Page int64 `json:"page,omitempty"`
PageSize int64 `json:"pageSize,omitempty"`
OrderBy string `json:"orderBy,omitempty"`
}
Domain Query Handling Method:
func (qs *queryHandler) IdentityQueryListByAccountUuid(ctx context.Context, qry comby.Query, domainQry *IdentityQueryListByAccountUuid) (*IdentityQueryListResponse, error)
IdentityQueryListByAccountTenantUuid
Domain Query Struct:
type IdentityQueryListByAccountTenantUuid struct {
TenantUuid string `json:"tenantUuid"`
AccountUuid string `json:"accountUuid"`
Page int64 `json:"page,omitempty"`
PageSize int64 `json:"pageSize,omitempty"`
OrderBy string `json:"orderBy,omitempty"`
}
Domain Query Handling Method:
func (qs *queryHandler) IdentityQueryListByAccountTenantUuid(ctx context.Context, qry comby.Query, domainQry *IdentityQueryListByAccountTenantUuid) (*IdentityQueryListResponse, error)
IdentityQueryList
Domain Query Struct:
type IdentityQueryList struct {
TenantUuid string `json:"tenantUuid"`
Page int64 `json:"page,omitempty"`
PageSize int64 `json:"pageSize,omitempty"`
OrderBy string `json:"orderBy,omitempty"`
Attributes string `json:"attributes,omitempty"`
}
Domain Query Handling Method:
func (qs *queryHandler) IdentityQueryList(ctx context.Context, qry comby.Query, domainQry *IdentityQueryList) (*IdentityQueryListResponse, error)
IdentityQueryModel
Domain Query Struct:
type IdentityQueryModel struct {
IdentityUuid string `json:"identityUuid"`
}
Domain Query Handling Method:
func (qs *queryHandler) IdentityQueryModel(ctx context.Context, qry comby.Query, domainQry *IdentityQueryModel) (*IdentityQueryItemResponse, error)
IdentityQueryModelIndependentOfOrganization
Domain Query Struct:
type IdentityQueryModelIndependentOfOrganization struct {
SessionUuid string `json:"sessionUuid"`
IdentityUuid string `json:"identityUuid,omitempty"`
}
Domain Query Handling Method:
func (qs *queryHandler) IdentityQueryModelIndependentOfOrganization(ctx context.Context, qry comby.Query, domainQry *IdentityQueryModelIndependentOfOrganization) (*IdentityQueryItemResponse, error)
IdentityQueryListResponse
type IdentityQueryListResponse struct {
Items []*readmodel.IdentityModel `json:"items,omitempty"`
Total int64 `json:"total,omitempty"`
Page int64 `json:"page,omitempty"`
PageSize int64 `json:"pageSize,omitempty"`
}
IdentityQueryItemResponse
type IdentityQueryItemResponse struct {
Item *readmodel.IdentityModel `json:"item,omitempty"`
}
Events
- IdentityAddedGroupEvent
- IdentityAddedTokenEvent
- IdentityCreatedEvent
- IdentityRemovedEvent
- IdentityAttributeRemovedEvent
- IdentityRemovedGroupEvent
- IdentityRemovedTokenEvent
- IdentityAttributeSetEvent
- IdentityUpdatedEvent
- IdentityProfileUpdatedEvent
IdentityAddedGroupEvent
Domain Event Struct:
type IdentityAddedGroupEvent struct {
GroupUuid string `json:"groupUuid"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityAddedGroupEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityAddedGroupEvent) (error)
IdentityAddedTokenEvent
Domain Event Struct:
type IdentityAddedTokenEvent struct {
TokenUuid string `json:"tokenUuid"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
TokenValue string `json:"tokenValue"`
ExpiredAt int64 `json:"expiredAt,omitempty"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityAddedTokenEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityAddedTokenEvent) (error)
IdentityCreatedEvent
Domain Event Struct:
type IdentityCreatedEvent struct {
AccountUuid string `json:"accountUuid,omitempty"`
Attributes string `json:"attributes,omitempty"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityCreatedEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityCreatedEvent) (error)
IdentityRemovedEvent
Domain Event Struct:
type IdentityRemovedEvent struct {
Reason string `json:"reason,omitempty"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityRemovedEvent) (error)
IdentityAttributeRemovedEvent
Domain Event Struct:
type IdentityAttributeRemovedEvent struct {
Key string `json:"key"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityAttributeRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityAttributeRemovedEvent) (error)
IdentityRemovedGroupEvent
Domain Event Struct:
type IdentityRemovedGroupEvent struct {
GroupUuid string `json:"groupUuid"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityRemovedGroupEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityRemovedGroupEvent) (error)
IdentityRemovedTokenEvent
Domain Event Struct:
type IdentityRemovedTokenEvent struct {
TokenUuid string `json:"tokenUuid"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityRemovedTokenEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityRemovedTokenEvent) (error)
IdentityAttributeSetEvent
Domain Event Struct:
type IdentityAttributeSetEvent struct {
Key string `json:"key"`
Value any `json:"value"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityAttributesSetEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityAttributeSetEvent) (error)
IdentityUpdatedEvent
Domain Event Struct:
type IdentityUpdatedEvent struct {
Attributes string `json:"attributes,omitempty"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityUpdatedEvent) (error)
IdentityProfileUpdatedEvent
Domain Event Struct:
type IdentityProfileUpdatedEvent struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
Title string `json:"title,omitempty"`
Avatar string `json:"avatar,omitempty"`
}
Domain Event Handling Method:
func (agg *Identity) IdentityProfileUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *IdentityProfileUpdatedEvent) (error)
Aggregate
Aggregate Struct:
type Identity struct {
*comby.BaseAggregate
// References
AccountUuid string
GroupUuids []string
// Entities
Profile *Profile
Tokens []*Token
}
Methods
AddGroup
func (agg *Identity) AddGroup(groupUuid string) (error)
AddToken
func (agg *Identity) AddToken(tokenUuid, tokenValue, name, description string, expiredAt int64) (error)
Add
func (agg *Identity) Add(accountUuid, attributes string) (error)
Remove
func (agg *Identity) Remove() (error)
RemoveAttribute
func (agg *Identity) RemoveAttribute(key string) (error)
RemoveGroup
func (agg *Identity) RemoveGroup(groupUuid string) (error)
RemoveToken
func (agg *Identity) RemoveToken(tokenUuid string) (error)
SetAttribute
func (agg *Identity) SetAttribute(key string, value any) (error)
Update
func (agg *Identity) Update(attributes string) (error)
UpdateProfile
func (agg *Identity) UpdateProfile(name, email, title, avatar string) (error)
Event Handlers
IdentityReadmodel
Domain Event | Method |
---|---|
tenantAggregate.TenantCreatedEvent | TenantCreatedEvent |
tenantAggregate.TenantAttributeRemovedEvent | TenantAttributeRemovedEvent |
tenantAggregate.TenantAttributeSetEvent | TenantAttributeSetEvent |
tenantAggregate.TenantUpdatedEvent | TenantUpdatedEvent |
tenantAggregate.TenantRemovedEvent | TenantRemovedEvent |
identityAggregate.IdentityAttributeRemovedEvent | IdentityAttributeRemovedEvent |
identityAggregate.IdentityRemovedTokenEvent | IdentityRemovedTokenEvent |
identityAggregate.IdentityUpdatedEvent | IdentityUpdatedEvent |
identityAggregate.IdentityRemovedEvent | IdentityRemovedEvent |
identityAggregate.IdentityAddedGroupEvent | IdentityAddedGroupEvent |
identityAggregate.IdentityRemovedGroupEvent | IdentityRemovedGroupEvent |
identityAggregate.IdentityAddedTokenEvent | IdentityAddedTokenEvent |
identityAggregate.IdentityCreatedEvent | IdentityCreatedEvent |
identityAggregate.IdentityProfileUpdatedEvent | IdentityProfileUpdatedEvent |
identityAggregate.IdentityAttributeSetEvent | IdentityAttributeSetEvent |
groupAggregate.GroupUpdatedEvent | GroupUpdatedEvent |
groupAggregate.GroupRemovedEvent | GroupRemovedEvent |
groupAggregate.GroupAddedEvent | GroupAddedEvent |
assetAggregate.AssetAddedEvent | AssetAddedEvent |
assetAggregate.AssetRemovedEvent | AssetRemovedEvent |
assetAggregate.AssetUpdatedEvent | AssetUpdatedEvent |
Custom Permissions
Name | Type | Comment |
---|---|---|
IdentityCommandAddToken | Command | Add token for any other identity |
IdentityCommandRemoveToken | Command | Remove token of any other identity |
IdentityCommandUpdateProfile | Command | Update profile of any other identity |
IdentityCommandSetAttribute | Command | Set attributes of any other identity |