-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: First try of the addition of the CAS SSO
- Loading branch information
Showing
8 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |