Skip to content

Commit

Permalink
feat: First try of the addition of the CAS SSO
Browse files Browse the repository at this point in the history
  • Loading branch information
AyakorK committed Dec 31, 2024
1 parent 0b3cdc9 commit 69f3e34
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gem "decidim-survey_multiple_answers", git: "https://github.com/OpenSourcePoliti
gem "decidim-term_customizer", git: "https://github.com/OpenSourcePolitics/decidim-module-term_customizer.git", branch: "fix/email_with_precompile"

# Omniauth gems
gem "omniauth-cas"
gem "omniauth-france_connect", git: "https://github.com/OpenSourcePolitics/omniauth-france_connect"
gem "omniauth_openid_connect"
gem "omniauth-publik", git: "https://github.com/OpenSourcePolitics/omniauth-publik"
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,10 @@ GEM
hashie (>= 3.4.6)
rack (>= 2.2.3)
rack-protection
omniauth-cas (3.0.0)
addressable (~> 2.8)
nokogiri (~> 1.12)
omniauth (~> 2.1)
omniauth-facebook (5.0.0)
omniauth-oauth2 (~> 1.2)
omniauth-google-oauth2 (1.1.2)
Expand Down Expand Up @@ -1187,6 +1191,7 @@ DEPENDENCIES
lograge
multipart-post
nokogiri (= 1.13.4)
omniauth-cas
omniauth-france_connect!
omniauth-publik!
omniauth-rails_csrf_protection (~> 1.0)
Expand Down
Binary file added app/packs/images/icon-cas.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions config/initializers/omniauth_cas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require "omniauth/strategies/ubx"

Rails.application.config.middleware.use OmniAuth::Builder do
OmniAuth.config.logger = Rails.logger

omniauth_config = Rails.application.secrets.fetch(:omniauth, {}).with_indifferent_access

if omniauth_config[:cas].present?
provider(
OmniAuth::Strategies::UBX,
setup: lambda { |env|
request = Rack::Request.new(env)
organization = env["decidim.current_organization"].presence || Decidim::Organization.find_by(host: request.host)
provider_config = organization.enabled_omniauth_providers[:cas] || {}

env["omniauth.strategy"].options[:host] = provider_config[:host] || omniauth_config.dig(:cas, :host)
env["omniauth.strategy"].options[:ssl] = provider_config[:ssl] || omniauth_config.dig(:cas, :ssl)
}
)
end
end
22 changes: 22 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ en:
is in evaluation state.
anonymous_user: Anonymous user
authorization_handlers:
admin:
cas:
help:
- Validate with an external CAS account
cas_student:
help:
- Validate with an external IDNUM student account
cas:
explanation: Validate with an external IDNUM account
fields:
status: status
name: IDNUM
cas_student:
explanation: Validate with an external IDNUM student account
fields:
status: status
name: IDNUM student
osp_authorization_handler:
explanation: Verify your identity by entering a unique number
fields:
Expand Down Expand Up @@ -153,6 +170,9 @@ en:
system:
organizations:
omniauth_settings:
cas:
host: External service host (without http(s)://)
provider_name: External service name
france_connect:
client_id: Client ID
client_secret: Client secret
Expand Down Expand Up @@ -193,6 +213,8 @@ en:
success: Success
first_login:
actions:
cas: Verify your identity with an IDNUM account
cas_student: Verify your identity with an IDNUM student account
osp_authorization_handler: Verify with the identity verification form
osp_authorization_workflow: Verify with the identity verification form
devise:
Expand Down
22 changes: 22 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ fr:
est en cours d’évaluation.
anonymous_user: Utilisateur anonyme
authorization_handlers:
admin:
cas:
help:
- Confirmer une identité avec un compte IDNUM
cas_student:
help:
- Confirmer une identité avec un compte IDNUM étudiant
cas:
explanation: Confirmer votre identité avec un compte IDNUM
fields:
status: votre statut
name: IDNUM
cas_student:
explanation: Confirmer votre identité avec un compte IDNUM
fields:
status: votre statut
name: IDNUM étudiant
osp_authorization_handler:
explanation: Vérifier votre identité en saisissant un numéro unique
fields:
Expand Down Expand Up @@ -155,6 +172,9 @@ fr:
system:
organizations:
omniauth_settings:
cas:
host: Hôte du serveur distant (sans http(s)://)
provider_name: Nom du service distant
france_connect:
client_id: Client ID
client_secret: Client secret
Expand Down Expand Up @@ -195,6 +215,8 @@ fr:
success: Vous avez été vérifié avec succès.
first_login:
actions:
cas: Confirmer votre identité avec un compte IDNUM
cas_student: Confirmer votre identité avec un compte IDNUM étudiant
osp_authorization_handler: Vérifier avec le formulaire de vérification de l'identité
osp_authorization_workflow: Vérifier avec le formulaire de vérification de l'identité
devise:
Expand Down
5 changes: 5 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ default: &default
main: <%= ENV["HELP_SCOUT_BEACON_ID_MAIN"] %>
fallback: <%= ENV["HELP_SCOUT_BEACON_ID_FALLBACK"] %>
omniauth:
cas:
enabled: false
icon_path: "cas-icon.svg"
provider_name: "IDNUM"
host: <%= ENV["OMNIAUTH_SAML_HOST"] %>
facebook:
# It must be a boolean. Remember ENV variables doesn't support booleans.
enabled: false
Expand Down
41 changes: 41 additions & 0 deletions lib/omniauth/strategies/ubx.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# frozen_string_literal: true

require "omniauth-cas"

module OmniAuth
module Strategies
class UBX < OmniAuth::Strategies::CAS
option :name, :cas
option :origin_param, "redirect_url"
option :service_validate_url, "/p3/serviceValidate"

option :name_key, "givenName"
option :status_key, "eduPersonEntitlement"

# Auth hash schema keys for consistency with OmniAuth schema
AUTH_HASH_SCHEMA_KEYS = %w(name email nickname first_name last_name location image phone status).freeze

info do
prune!(
name: raw_info[options[:name_key].to_s],
email: raw_info[options[:email_key].to_s],
nickname: raw_info[options[:nickname_key].to_s],
first_name: raw_info[options[:first_name_key].to_s],
last_name: raw_info[options[:last_name_key].to_s],
location: raw_info[options[:location_key].to_s],
image: raw_info[options[:image_key].to_s],
phone: raw_info[options[:phone_key].to_s],
status: raw_info[options[:status_key].to_s]
)
end

private

def prune!(hash)
hash.delete_if { |_key, value| value.blank? }
end
end
end
end

OmniAuth.config.add_camelization("cas", "CAS")

0 comments on commit 69f3e34

Please sign in to comment.