Copy the Chatwoot (v4.14.0) frontend runnable subset into frontend/ for customization: - app/javascript/ (Vue SPA: dashboard, widget, sdk, portal, superadmin) - app/views/ (ERB templates for vite-plugin-ruby entrypoint resolution) - app/helpers/, app/assets/ (Rails view helpers, static assets) - enterprise/ (Enterprise edition frontend overlay) - config/vite.json, vite.config.ts, bin/vite (Vite-Rails toolchain) - package.json, pnpm-lock.yaml, tailwind/postcss/eslint configs - Gemfile, Gemfile.lock (vite_rails gem for bin/vite binstub) Excluded Rails backend: controllers, models, services, jobs, mailers, policies, db, lib, spec, public, node_modules. Update references to the new frontend location: - .gitignore: exclude frontend build artifacts (node_modules, tmp, packs), keep frontend/bin/ and frontend/vendor/ via negation - backend/scripts/parity_frontend_smoke.sh: CHATWOOT_DIR default reference/chatwoot -> ../frontend - backend/scripts/parity_frontend_browser_smoke.mjs: same default update - AGENTS.md: add frontend section with Rails/Vite coupling notes - README: architecture tree includes frontend/
46 lines
2.0 KiB
Ruby
46 lines
2.0 KiB
Ruby
# Enterprise Edition SAML SSO Provider
|
|
# This initializer adds SAML authentication support for Enterprise customers
|
|
|
|
# SAML setup proc for multi-tenant configuration
|
|
SAML_SETUP_PROC = proc do |env|
|
|
request = ActionDispatch::Request.new(env)
|
|
|
|
# Extract account_id from various sources
|
|
account_id = request.params['account_id'] ||
|
|
env['omniauth.params']&.dig('account_id')
|
|
relay_state = request.params['RelayState'] || ''
|
|
|
|
if account_id
|
|
# Keep SAML request context in OmniAuth env so the callback can be processed
|
|
# without depending on the Rails session cookie.
|
|
env['omniauth.params'] ||= {}
|
|
env['omniauth.params']['account_id'] = account_id
|
|
env['omniauth.params']['RelayState'] = relay_state
|
|
|
|
# Find SAML settings for this account
|
|
settings = AccountSamlSettings.find_by(account_id: account_id)
|
|
|
|
if settings
|
|
# Configure the strategy options dynamically
|
|
env['omniauth.strategy'].options[:idp_sso_service_url_runtime_params] = { RelayState: :RelayState }
|
|
env['omniauth.strategy'].options[:assertion_consumer_service_url] = "#{ENV.fetch('FRONTEND_URL', 'http://localhost:3000')}/omniauth/saml/callback?account_id=#{account_id}"
|
|
env['omniauth.strategy'].options[:sp_entity_id] = settings.sp_entity_id
|
|
env['omniauth.strategy'].options[:idp_entity_id] = settings.idp_entity_id
|
|
env['omniauth.strategy'].options[:idp_sso_service_url] = settings.sso_url
|
|
env['omniauth.strategy'].options[:idp_cert] = settings.certificate
|
|
env['omniauth.strategy'].options[:name_identifier_format] = 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'
|
|
else
|
|
# Set a dummy certificate to avoid the error
|
|
env['omniauth.strategy'].options[:idp_cert] = 'DUMMY'
|
|
end
|
|
else
|
|
# Set a dummy certificate to avoid the error
|
|
env['omniauth.strategy'].options[:idp_cert] = 'DUMMY'
|
|
end
|
|
end
|
|
|
|
Rails.application.config.middleware.use OmniAuth::Builder do
|
|
# SAML provider with setup phase for multi-tenant configuration
|
|
provider :saml, setup: SAML_SETUP_PROC
|
|
end
|