mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 23:50:36 -05:00
- SSO via OmniAuth OpenID Connect (Authentik, Keycloak, …): link by stable subject, by verified email, or from the profile; optional auto-create, admin-group sync, and turning password sign-in off - Current password required to change email or password; password changes and resets sign out other sessions; idle sessions expire after 30 days; "sign out everywhere else"; session reset on sign-in - Rate-limit password resets; scope squawk components to the aircraft - Strict Content Security Policy with nonces (inline handlers removed), Permissions-Policy and COOP headers; file links expire after an hour Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
2.0 KiB
Ruby
46 lines
2.0 KiB
Ruby
# Single sign-on through an OpenID Connect provider (Authentik, Keycloak,
|
|
# Google…), configured with environment variables:
|
|
#
|
|
# OIDC_ISSUER issuer URL, e.g. https://auth.example.com/application/o/sam/
|
|
# OIDC_CLIENT_ID client ID
|
|
# OIDC_CLIENT_SECRET client secret
|
|
# OIDC_PROVIDER_NAME button label (default "SSO")
|
|
# OIDC_AUTO_CREATE_USERS "true" to create an account for anyone the
|
|
# provider lets through (they start with no aircraft)
|
|
# OIDC_TRUST_EMAIL "true" to link existing accounts by email even when
|
|
# the provider doesn't mark the email verified. Only
|
|
# for providers where users can't change their email.
|
|
# OIDC_ADMIN_GROUP members of this group are admins, others aren't
|
|
# (synced at each sign-in; needs a "groups" claim)
|
|
# PASSWORD_LOGIN "false" to turn off email/password sign-in once SSO works
|
|
# APP_URL public base URL (default https://APP_HOST)
|
|
module Sso
|
|
PROVIDER = :oidc
|
|
|
|
module_function
|
|
|
|
def enabled? = ENV["OIDC_ISSUER"].present? && ENV["OIDC_CLIENT_ID"].present?
|
|
def label = ENV["OIDC_PROVIDER_NAME"].presence || "SSO"
|
|
def auto_create_users? = ENV["OIDC_AUTO_CREATE_USERS"] == "true"
|
|
def trust_email? = ENV["OIDC_TRUST_EMAIL"] == "true"
|
|
def admin_group = ENV["OIDC_ADMIN_GROUP"].presence
|
|
|
|
# Password sign-in stays on unless SSO is set up and it's switched off, so
|
|
# a broken SSO setup can't lock everyone out.
|
|
def password_login? = !enabled? || ENV["PASSWORD_LOGIN"] != "false"
|
|
|
|
def app_url
|
|
ENV["APP_URL"].presence&.chomp("/") ||
|
|
"#{ENV.fetch('FORCE_SSL', 'true') == 'true' ? 'https' : 'http'}://#{ENV.fetch('APP_HOST', 'localhost:3000')}"
|
|
end
|
|
|
|
# Origin of the provider, for the CSP form-action list (the sign-in POST
|
|
# redirects there).
|
|
def issuer_origin
|
|
uri = URI.parse(ENV["OIDC_ISSUER"].to_s)
|
|
uri.host && "#{uri.scheme}://#{uri.host}#{":#{uri.port}" unless uri.port == uri.default_port}"
|
|
rescue URI::InvalidURIError
|
|
nil
|
|
end
|
|
end
|