mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-07-22 12:41:27 +02:00
Pass emailLoginNotificationEnabled to CreateNewSignInWithEmail instead of the whole AppConfigModel, so the sign-in audit business logic no longer takes the config struct just to read one flag. The caller evaluates the flag from the config it already loaded. The background notification email, which is sent in a detached goroutine after the request completes, now resolves the current config from the app config service rather than threading the request's snapshot into the goroutine. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZ6SoJpmnLggZqactXxrak
148 lines
5.1 KiB
Go
148 lines
5.1 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/italypaleale/francis/host/local"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/pocket-id/pocket-id/backend/internal/api"
|
|
"github.com/pocket-id/pocket-id/backend/internal/apikey"
|
|
"github.com/pocket-id/pocket-id/backend/internal/appconfig"
|
|
"github.com/pocket-id/pocket-id/backend/internal/common"
|
|
"github.com/pocket-id/pocket-id/backend/internal/job"
|
|
"github.com/pocket-id/pocket-id/backend/internal/oidc"
|
|
"github.com/pocket-id/pocket-id/backend/internal/service"
|
|
"github.com/pocket-id/pocket-id/backend/internal/storage"
|
|
"github.com/pocket-id/pocket-id/backend/internal/usersignup"
|
|
"github.com/pocket-id/pocket-id/backend/internal/webauthn"
|
|
)
|
|
|
|
type services struct {
|
|
appConfigService *appconfig.AppConfigService
|
|
appImagesService *service.AppImagesService
|
|
emailService *service.EmailService
|
|
geoLiteService *service.GeoLiteService
|
|
auditLogService *service.AuditLogService
|
|
jwtService *service.JwtService
|
|
scimService *service.ScimService
|
|
userService *service.UserService
|
|
customClaimService *service.CustomClaimService
|
|
oidcService *service.OidcService
|
|
userGroupService *service.UserGroupService
|
|
ldapService *service.LdapService
|
|
versionService *service.VersionService
|
|
fileStorage storage.FileStorage
|
|
appLockService *service.AppLockService
|
|
oneTimeAccessService *service.OneTimeAccessService
|
|
|
|
apiKeyModule *apikey.Module
|
|
oidcModule *oidc.Module
|
|
webauthnModule *webauthn.Module
|
|
userSignUpModule *usersignup.Module
|
|
apiModule *api.Module
|
|
}
|
|
|
|
// Initializes all services
|
|
func initServices(
|
|
ctx context.Context,
|
|
db *gorm.DB,
|
|
instanceID string,
|
|
actors *local.Host,
|
|
httpClient *http.Client,
|
|
imageExtensions map[string]string,
|
|
fileStorage storage.FileStorage,
|
|
scheduler *job.Scheduler,
|
|
) (svc *services, err error) {
|
|
svc = &services{}
|
|
|
|
// Init the app config service
|
|
svc.appConfigService, err = appconfig.NewService(ctx, actors, db)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create app config service: %w", err)
|
|
}
|
|
|
|
svc.fileStorage = fileStorage
|
|
svc.appImagesService = service.NewAppImagesService(imageExtensions, fileStorage)
|
|
svc.appLockService = service.NewAppLockService(db)
|
|
|
|
svc.emailService, err = service.NewEmailService(db)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create email service: %w", err)
|
|
}
|
|
|
|
svc.geoLiteService = service.NewGeoLiteService(httpClient)
|
|
svc.auditLogService = service.NewAuditLogService(db, svc.emailService, svc.geoLiteService, svc.appConfigService)
|
|
svc.jwtService, err = service.NewJwtService(ctx, db, instanceID)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create JWT service: %w", err)
|
|
}
|
|
|
|
svc.customClaimService = service.NewCustomClaimService(db)
|
|
svc.webauthnModule, err = webauthn.New(webauthn.Dependencies{
|
|
DB: db,
|
|
AppURL: common.EnvConfig.AppURL,
|
|
Signer: svc.jwtService,
|
|
AuditLog: svc.auditLogService,
|
|
AppConfig: svc.appConfigService,
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create WebAuthn module: %w", err)
|
|
}
|
|
|
|
svc.scimService = service.NewScimService(db, scheduler, httpClient)
|
|
|
|
svc.apiModule = api.New(api.Dependencies{DB: db, Issuer: common.EnvConfig.AppURL})
|
|
|
|
svc.oidcModule, err = oidc.New(ctx, oidc.Dependencies{
|
|
DB: db,
|
|
HTTPClient: httpClient,
|
|
Config: oidc.Config{
|
|
BaseURL: common.EnvConfig.AppURL,
|
|
TokenBaseURL: common.EnvConfig.AppURL,
|
|
Secret: common.EnvConfig.EncryptionKey,
|
|
AllowInsecureCallbackURLs: common.EnvConfig.AllowInsecureCallbackURLs,
|
|
},
|
|
Signer: svc.jwtService,
|
|
CustomClaims: svc.customClaimService,
|
|
Reauth: svc.webauthnModule,
|
|
AuditLog: svc.auditLogService,
|
|
APIAccess: svc.apiModule,
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create OIDC module: %w", err)
|
|
}
|
|
|
|
svc.oidcService, err = service.NewOidcService(db, svc.jwtService, svc.oidcModule.Preview, svc.scimService, httpClient, fileStorage)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create OIDC service: %w", err)
|
|
}
|
|
|
|
svc.userGroupService = service.NewUserGroupService(db, svc.scimService)
|
|
svc.userService = service.NewUserService(db, svc.jwtService, svc.auditLogService, svc.emailService, svc.customClaimService, svc.appImagesService, svc.scimService, fileStorage)
|
|
svc.ldapService = service.NewLdapService(db, httpClient, svc.userService, svc.userGroupService, fileStorage)
|
|
|
|
svc.apiKeyModule, err = apikey.New(ctx, apikey.Dependencies{
|
|
DB: db,
|
|
StaticApiKey: common.EnvConfig.StaticApiKey,
|
|
})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create API key module: %w", err)
|
|
}
|
|
|
|
svc.userSignUpModule = usersignup.New(usersignup.Dependencies{
|
|
DB: db,
|
|
Signer: svc.jwtService,
|
|
AuditLog: svc.auditLogService,
|
|
UserCreator: svc.userService,
|
|
AppConfig: svc.appConfigService,
|
|
})
|
|
svc.oneTimeAccessService = service.NewOneTimeAccessService(db, svc.userService, svc.jwtService, svc.auditLogService, svc.emailService)
|
|
|
|
svc.versionService = service.NewVersionService(httpClient)
|
|
|
|
return svc, nil
|
|
}
|