Documentation
¶
Index ¶
- Constants
- Variables
- func SendEmail[V any](srv *EmailService, toEmail email.Address, template email.Template[V], tData *V) error
- type AccessTokenJWTClaims
- type AppConfigService
- func (s *AppConfigService) InitDbConfig() error
- func (s *AppConfigService) ListAppConfig(showAll bool) ([]model.AppConfigVariable, error)
- func (s *AppConfigService) LoadDbConfigFromDb() error
- func (s *AppConfigService) UpdateAppConfig(input dto.AppConfigUpdateDto) ([]model.AppConfigVariable, error)
- func (s *AppConfigService) UpdateImage(uploadedFile *multipart.FileHeader, imageName string, oldImageType string) error
- func (s *AppConfigService) UpdateImageType(imageName string, fileType string) error
- type AuditLogService
- func (s *AuditLogService) Create(event model.AuditLogEvent, ipAddress, userAgent, userID string, ...) model.AuditLog
- func (s *AuditLogService) CreateNewSignInWithEmail(ipAddress, userAgent, userID string) model.AuditLog
- func (s *AuditLogService) DeviceStringFromUserAgent(userAgent string) string
- func (s *AuditLogService) ListAuditLogsForUser(userID string, page int, pageSize int) ([]model.AuditLog, utils.PaginationResponse, error)
- type CustomClaimService
- func (s *CustomClaimService) GetCustomClaimsForUser(userID string) ([]model.CustomClaim, error)
- func (s *CustomClaimService) GetCustomClaimsForUserGroup(userGroupID string) ([]model.CustomClaim, error)
- func (s *CustomClaimService) GetCustomClaimsForUserWithUserGroups(userID string) ([]model.CustomClaim, error)
- func (s *CustomClaimService) GetSuggestions() ([]string, error)
- func (s *CustomClaimService) UpdateCustomClaimsForUser(userID string, claims []dto.CustomClaimCreateDto) ([]model.CustomClaim, error)
- func (s *CustomClaimService) UpdateCustomClaimsForUserGroup(userGroupID string, claims []dto.CustomClaimCreateDto) ([]model.CustomClaim, error)
- type EmailService
- type GeoLiteService
- type JWK
- type JwtService
- func (s *JwtService) GenerateAccessToken(user model.User) (string, error)
- func (s *JwtService) GenerateIDToken(userClaims map[string]interface{}, clientID string, nonce string) (string, error)
- func (s *JwtService) GenerateOauthAccessToken(user model.User, clientID string) (string, error)
- func (s *JwtService) GetJWK() (JWK, error)
- func (s *JwtService) VerifyAccessToken(tokenString string) (*AccessTokenJWTClaims, error)
- func (s *JwtService) VerifyOauthAccessToken(tokenString string) (*jwt.RegisteredClaims, error)
- type NewLoginTemplateData
- type OidcService
- func (s *OidcService) Authorize(input dto.AuthorizeOidcClientRequestDto, userID, ipAddress, userAgent string) (string, string, error)
- func (s *OidcService) AuthorizeNewClient(input dto.AuthorizeOidcClientRequestDto, userID, ipAddress, userAgent string) (string, string, error)
- func (s *OidcService) CreateClient(input dto.OidcClientCreateDto, userID string) (model.OidcClient, error)
- func (s *OidcService) CreateClientSecret(clientID string) (string, error)
- func (s *OidcService) CreateTokens(code, grantType, clientID, clientSecret, codeVerifier string) (string, string, error)
- func (s *OidcService) DeleteClient(clientID string) error
- func (s *OidcService) DeleteClientLogo(clientID string) error
- func (s *OidcService) GetClient(clientID string) (model.OidcClient, error)
- func (s *OidcService) GetClientLogo(clientID string) (string, string, error)
- func (s *OidcService) GetUserClaimsForClient(userID string, clientID string) (map[string]interface{}, error)
- func (s *OidcService) ListClients(searchTerm string, page int, pageSize int) ([]model.OidcClient, utils.PaginationResponse, error)
- func (s *OidcService) UpdateClient(clientID string, input dto.OidcClientCreateDto) (model.OidcClient, error)
- func (s *OidcService) UpdateClientLogo(clientID string, file *multipart.FileHeader) error
- type TestService
- type UserGroupService
- func (s *UserGroupService) Create(input dto.UserGroupCreateDto) (group model.UserGroup, err error)
- func (s *UserGroupService) Delete(id string) error
- func (s *UserGroupService) Get(id string) (group model.UserGroup, err error)
- func (s *UserGroupService) GetUserCountOfGroup(id string) (int64, error)
- func (s *UserGroupService) List(name string, page int, pageSize int) (groups []model.UserGroup, response utils.PaginationResponse, err error)
- func (s *UserGroupService) Update(id string, input dto.UserGroupCreateDto) (group model.UserGroup, err error)
- func (s *UserGroupService) UpdateUsers(id string, input dto.UserGroupUpdateUsersDto) (group model.UserGroup, err error)
- type UserService
- func (s *UserService) CreateOneTimeAccessToken(userID string, expiresAt time.Time, ipAddress, userAgent string) (string, error)
- func (s *UserService) CreateUser(input dto.UserCreateDto) (model.User, error)
- func (s *UserService) DeleteUser(userID string) error
- func (s *UserService) ExchangeOneTimeAccessToken(token string) (model.User, string, error)
- func (s *UserService) GetUser(userID string) (model.User, error)
- func (s *UserService) ListUsers(searchTerm string, page int, pageSize int) ([]model.User, utils.PaginationResponse, error)
- func (s *UserService) SetupInitialAdmin() (model.User, string, error)
- func (s *UserService) UpdateUser(userID string, updatedUser dto.UserCreateDto, updateOwnUser bool) (model.User, error)
- type WebAuthnService
- func (s *WebAuthnService) BeginLogin() (*model.PublicKeyCredentialRequestOptions, error)
- func (s *WebAuthnService) BeginRegistration(userID string) (*model.PublicKeyCredentialCreationOptions, error)
- func (s *WebAuthnService) DeleteCredential(userID, credentialID string) error
- func (s *WebAuthnService) ListCredentials(userID string) ([]model.WebauthnCredential, error)
- func (s *WebAuthnService) UpdateCredential(userID, credentialID, name string) (model.WebauthnCredential, error)
- func (s *WebAuthnService) VerifyLogin(sessionID string, ...) (model.User, string, error)
- func (s *WebAuthnService) VerifyRegistration(sessionID, userID string, r *http.Request) (model.WebauthnCredential, error)
Constants ¶
const ( UserID idType = "user_id" UserGroupID idType = "user_group_id" )
Variables ¶
var NewLoginTemplate = email.Template[NewLoginTemplateData]{ Path: "login-with-new-device", Title: func(data *email.TemplateData[NewLoginTemplateData]) string { return fmt.Sprintf("New device login with %s", data.AppName) }, }
var TestTemplate = email.Template[struct{}]{ Path: "test", Title: func(data *email.TemplateData[struct{}]) string { return "Test email" }, }
Functions ¶
Types ¶
type AccessTokenJWTClaims ¶
type AccessTokenJWTClaims struct { jwt.RegisteredClaims IsAdmin bool `json:"isAdmin,omitempty"` }
type AppConfigService ¶
type AppConfigService struct { DbConfig *model.AppConfig // contains filtered or unexported fields }
func NewAppConfigService ¶
func NewAppConfigService(db *gorm.DB) *AppConfigService
func (*AppConfigService) InitDbConfig ¶
func (s *AppConfigService) InitDbConfig() error
InitDbConfig creates the default configuration values in the database if they do not exist, updates existing configurations if they differ from the default, and deletes any configurations that are not in the default configuration.
func (*AppConfigService) ListAppConfig ¶
func (s *AppConfigService) ListAppConfig(showAll bool) ([]model.AppConfigVariable, error)
func (*AppConfigService) LoadDbConfigFromDb ¶
func (s *AppConfigService) LoadDbConfigFromDb() error
LoadDbConfigFromDb loads the configuration values from the database into the DbConfig struct.
func (*AppConfigService) UpdateAppConfig ¶
func (s *AppConfigService) UpdateAppConfig(input dto.AppConfigUpdateDto) ([]model.AppConfigVariable, error)
func (*AppConfigService) UpdateImage ¶
func (s *AppConfigService) UpdateImage(uploadedFile *multipart.FileHeader, imageName string, oldImageType string) error
func (*AppConfigService) UpdateImageType ¶
func (s *AppConfigService) UpdateImageType(imageName string, fileType string) error
type AuditLogService ¶
type AuditLogService struct {
// contains filtered or unexported fields
}
func NewAuditLogService ¶
func NewAuditLogService(db *gorm.DB, appConfigService *AppConfigService, emailService *EmailService, geoliteService *GeoLiteService) *AuditLogService
func (*AuditLogService) Create ¶
func (s *AuditLogService) Create(event model.AuditLogEvent, ipAddress, userAgent, userID string, data model.AuditLogData) model.AuditLog
Create creates a new audit log entry in the database
func (*AuditLogService) CreateNewSignInWithEmail ¶
func (s *AuditLogService) CreateNewSignInWithEmail(ipAddress, userAgent, userID string) model.AuditLog
CreateNewSignInWithEmail creates a new audit log entry in the database and sends an email if the device hasn't been used before
func (*AuditLogService) DeviceStringFromUserAgent ¶
func (s *AuditLogService) DeviceStringFromUserAgent(userAgent string) string
func (*AuditLogService) ListAuditLogsForUser ¶
func (s *AuditLogService) ListAuditLogsForUser(userID string, page int, pageSize int) ([]model.AuditLog, utils.PaginationResponse, error)
ListAuditLogsForUser retrieves all audit logs for a given user ID
type CustomClaimService ¶
type CustomClaimService struct {
// contains filtered or unexported fields
}
func NewCustomClaimService ¶
func NewCustomClaimService(db *gorm.DB) *CustomClaimService
func (*CustomClaimService) GetCustomClaimsForUser ¶
func (s *CustomClaimService) GetCustomClaimsForUser(userID string) ([]model.CustomClaim, error)
func (*CustomClaimService) GetCustomClaimsForUserGroup ¶
func (s *CustomClaimService) GetCustomClaimsForUserGroup(userGroupID string) ([]model.CustomClaim, error)
func (*CustomClaimService) GetCustomClaimsForUserWithUserGroups ¶
func (s *CustomClaimService) GetCustomClaimsForUserWithUserGroups(userID string) ([]model.CustomClaim, error)
GetCustomClaimsForUserWithUserGroups returns the custom claims of a user and all user groups the user is a member of, prioritizing the user's claims over user group claims with the same key.
func (*CustomClaimService) GetSuggestions ¶
func (s *CustomClaimService) GetSuggestions() ([]string, error)
GetSuggestions returns a list of custom claim keys that have been used before
func (*CustomClaimService) UpdateCustomClaimsForUser ¶
func (s *CustomClaimService) UpdateCustomClaimsForUser(userID string, claims []dto.CustomClaimCreateDto) ([]model.CustomClaim, error)
UpdateCustomClaimsForUser updates the custom claims for a user
func (*CustomClaimService) UpdateCustomClaimsForUserGroup ¶
func (s *CustomClaimService) UpdateCustomClaimsForUserGroup(userGroupID string, claims []dto.CustomClaimCreateDto) ([]model.CustomClaim, error)
UpdateCustomClaimsForUserGroup updates the custom claims for a user group
type EmailService ¶
type EmailService struct {
// contains filtered or unexported fields
}
func NewEmailService ¶
func NewEmailService(appConfigService *AppConfigService, db *gorm.DB) (*EmailService, error)
func (*EmailService) SendTestEmail ¶
func (srv *EmailService) SendTestEmail() error
type GeoLiteService ¶
type GeoLiteService struct{}
func NewGeoLiteService ¶
func NewGeoLiteService() *GeoLiteService
NewGeoLiteService initializes a new GeoLiteService instance and starts a goroutine to update the GeoLite2 City database.
func (*GeoLiteService) GetLocationByIP ¶
func (s *GeoLiteService) GetLocationByIP(ipAddress string) (country, city string, err error)
GetLocationByIP returns the country and city of the given IP address.
type JwtService ¶
type JwtService struct {
// contains filtered or unexported fields
}
func NewJwtService ¶
func NewJwtService(appConfigService *AppConfigService) *JwtService
func (*JwtService) GenerateAccessToken ¶
func (s *JwtService) GenerateAccessToken(user model.User) (string, error)
func (*JwtService) GenerateIDToken ¶
func (*JwtService) GenerateOauthAccessToken ¶
func (*JwtService) GetJWK ¶
func (s *JwtService) GetJWK() (JWK, error)
GetJWK returns the JSON Web Key (JWK) for the public key.
func (*JwtService) VerifyAccessToken ¶
func (s *JwtService) VerifyAccessToken(tokenString string) (*AccessTokenJWTClaims, error)
func (*JwtService) VerifyOauthAccessToken ¶
func (s *JwtService) VerifyOauthAccessToken(tokenString string) (*jwt.RegisteredClaims, error)
type NewLoginTemplateData ¶
type OidcService ¶
type OidcService struct {
// contains filtered or unexported fields
}
func NewOidcService ¶
func NewOidcService(db *gorm.DB, jwtService *JwtService, appConfigService *AppConfigService, auditLogService *AuditLogService, customClaimService *CustomClaimService) *OidcService
func (*OidcService) Authorize ¶
func (s *OidcService) Authorize(input dto.AuthorizeOidcClientRequestDto, userID, ipAddress, userAgent string) (string, string, error)
func (*OidcService) AuthorizeNewClient ¶
func (s *OidcService) AuthorizeNewClient(input dto.AuthorizeOidcClientRequestDto, userID, ipAddress, userAgent string) (string, string, error)
func (*OidcService) CreateClient ¶
func (s *OidcService) CreateClient(input dto.OidcClientCreateDto, userID string) (model.OidcClient, error)
func (*OidcService) CreateClientSecret ¶
func (s *OidcService) CreateClientSecret(clientID string) (string, error)
func (*OidcService) CreateTokens ¶
func (s *OidcService) CreateTokens(code, grantType, clientID, clientSecret, codeVerifier string) (string, string, error)
func (*OidcService) DeleteClient ¶
func (s *OidcService) DeleteClient(clientID string) error
func (*OidcService) DeleteClientLogo ¶
func (s *OidcService) DeleteClientLogo(clientID string) error
func (*OidcService) GetClient ¶
func (s *OidcService) GetClient(clientID string) (model.OidcClient, error)
func (*OidcService) GetClientLogo ¶
func (s *OidcService) GetClientLogo(clientID string) (string, string, error)
func (*OidcService) GetUserClaimsForClient ¶
func (s *OidcService) GetUserClaimsForClient(userID string, clientID string) (map[string]interface{}, error)
func (*OidcService) ListClients ¶
func (s *OidcService) ListClients(searchTerm string, page int, pageSize int) ([]model.OidcClient, utils.PaginationResponse, error)
func (*OidcService) UpdateClient ¶
func (s *OidcService) UpdateClient(clientID string, input dto.OidcClientCreateDto) (model.OidcClient, error)
func (*OidcService) UpdateClientLogo ¶
func (s *OidcService) UpdateClientLogo(clientID string, file *multipart.FileHeader) error
type TestService ¶
type TestService struct {
// contains filtered or unexported fields
}
func NewTestService ¶
func NewTestService(db *gorm.DB, appConfigService *AppConfigService) *TestService
func (*TestService) ResetAppConfig ¶
func (s *TestService) ResetAppConfig() error
func (*TestService) ResetApplicationImages ¶
func (s *TestService) ResetApplicationImages() error
func (*TestService) ResetDatabase ¶
func (s *TestService) ResetDatabase() error
func (*TestService) SeedDatabase ¶
func (s *TestService) SeedDatabase() error
type UserGroupService ¶
type UserGroupService struct {
// contains filtered or unexported fields
}
func NewUserGroupService ¶
func NewUserGroupService(db *gorm.DB) *UserGroupService
func (*UserGroupService) Create ¶
func (s *UserGroupService) Create(input dto.UserGroupCreateDto) (group model.UserGroup, err error)
func (*UserGroupService) Delete ¶
func (s *UserGroupService) Delete(id string) error
func (*UserGroupService) Get ¶
func (s *UserGroupService) Get(id string) (group model.UserGroup, err error)
func (*UserGroupService) GetUserCountOfGroup ¶
func (s *UserGroupService) GetUserCountOfGroup(id string) (int64, error)
func (*UserGroupService) List ¶
func (s *UserGroupService) List(name string, page int, pageSize int) (groups []model.UserGroup, response utils.PaginationResponse, err error)
func (*UserGroupService) Update ¶
func (s *UserGroupService) Update(id string, input dto.UserGroupCreateDto) (group model.UserGroup, err error)
func (*UserGroupService) UpdateUsers ¶
func (s *UserGroupService) UpdateUsers(id string, input dto.UserGroupUpdateUsersDto) (group model.UserGroup, err error)
type UserService ¶
type UserService struct {
// contains filtered or unexported fields
}
func NewUserService ¶
func NewUserService(db *gorm.DB, jwtService *JwtService, auditLogService *AuditLogService) *UserService
func (*UserService) CreateOneTimeAccessToken ¶
func (*UserService) CreateUser ¶
func (s *UserService) CreateUser(input dto.UserCreateDto) (model.User, error)
func (*UserService) DeleteUser ¶
func (s *UserService) DeleteUser(userID string) error
func (*UserService) ExchangeOneTimeAccessToken ¶
func (*UserService) ListUsers ¶
func (s *UserService) ListUsers(searchTerm string, page int, pageSize int) ([]model.User, utils.PaginationResponse, error)
func (*UserService) SetupInitialAdmin ¶
func (s *UserService) SetupInitialAdmin() (model.User, string, error)
func (*UserService) UpdateUser ¶
func (s *UserService) UpdateUser(userID string, updatedUser dto.UserCreateDto, updateOwnUser bool) (model.User, error)
type WebAuthnService ¶
type WebAuthnService struct {
// contains filtered or unexported fields
}
func NewWebAuthnService ¶
func NewWebAuthnService(db *gorm.DB, jwtService *JwtService, auditLogService *AuditLogService, appConfigService *AppConfigService) *WebAuthnService
func (*WebAuthnService) BeginLogin ¶
func (s *WebAuthnService) BeginLogin() (*model.PublicKeyCredentialRequestOptions, error)
func (*WebAuthnService) BeginRegistration ¶
func (s *WebAuthnService) BeginRegistration(userID string) (*model.PublicKeyCredentialCreationOptions, error)
func (*WebAuthnService) DeleteCredential ¶
func (s *WebAuthnService) DeleteCredential(userID, credentialID string) error
func (*WebAuthnService) ListCredentials ¶
func (s *WebAuthnService) ListCredentials(userID string) ([]model.WebauthnCredential, error)
func (*WebAuthnService) UpdateCredential ¶
func (s *WebAuthnService) UpdateCredential(userID, credentialID, name string) (model.WebauthnCredential, error)
func (*WebAuthnService) VerifyLogin ¶
func (s *WebAuthnService) VerifyLogin(sessionID string, credentialAssertionData *protocol.ParsedCredentialAssertionData, ipAddress, userAgent string) (model.User, string, error)
func (*WebAuthnService) VerifyRegistration ¶
func (s *WebAuthnService) VerifyRegistration(sessionID, userID string, r *http.Request) (model.WebauthnCredential, error)