generated from OpenSourcePolitics/decidim-app
-
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.
[WIP] Omniauth SAML strategy for IMT
- Loading branch information
Showing
7 changed files
with
103 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
12 changes: 12 additions & 0 deletions
12
app/controllers/decidim/devise/custom_omniauth_registrations_controller.rb
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module Devise | ||
class CustomOmniauthRegistrationsController < ::Decidim::Devise::OmniauthRegistrationsController | ||
# rubocop:disable Rails/LexicallyScopedActionFilter | ||
skip_before_action :verify_authenticity_token, only: [:imt] | ||
skip_after_action :verify_same_origin_request, only: [:imt] | ||
# rubocop:enable Rails/LexicallyScopedActionFilter | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require "omniauth/strategies/imt" | ||
|
||
if Rails.application.secrets.dig(:omniauth, :imt).present? | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
OmniAuth.config.logger = Rails.logger | ||
provider( | ||
OmniAuth::Strategies::IMT, | ||
setup: lambda { |env| | ||
request = Rack::Request.new(env) | ||
organization = Decidim::Organization.find_by(host: request.host) | ||
provider_config = organization.enabled_omniauth_providers[:imt] | ||
env["omniauth.strategy"].options[:issuer] = provider_config[:issuer] | ||
env["omniauth.strategy"].options[:assertion_consumer_service_url] = provider_config[:assertion_consumer_service_url] | ||
env["omniauth.strategy"].options[:sp_entity_id] = provider_config[:sp_entity_id] | ||
env["omniauth.strategy"].options[:idp_sso_service_url] = provider_config[:idp_sso_service_url] | ||
env["omniauth.strategy"].options[:idp_slo_service_url] = provider_config[:idp_slo_service_url] | ||
env["omniauth.strategy"].options[:idp_cert] = provider_config[:idp_cert] | ||
env["omniauth.strategy"].options[:name_identifier_format] = provider_config[:name_identifier_format] | ||
env["omniauth.strategy"].options[:attribute_service_name] = provider_config[:attribute_service_name] | ||
} | ||
# , | ||
# request_attributes: [ | ||
# { :name => 'email', :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', :friendly_name => 'Email address' }, | ||
# { :name => 'name', :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', :friendly_name => 'Full name' }, | ||
# { :name => 'first_name', :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', :friendly_name => 'Given name' }, | ||
# { :name => 'last_name', :name_format => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic', :friendly_name => 'Family name' } | ||
# ], | ||
# attribute_statements: { | ||
# name: ["name"], | ||
# email: ["email", "mail"], | ||
# first_name: ["first_name", "firstname", "firstName"], | ||
# last_name: ["last_name", "lastname", "lastName"] | ||
# } | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "omniauth-saml" | ||
|
||
module OmniAuth | ||
module Strategies | ||
class IMT < OmniAuth::Strategies::SAML | ||
option :name, :imt | ||
option :protocol_binding, "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" | ||
|
||
option :idp_cert_fingerprint_algorithm, XMLSecurity::Document::SHA256 | ||
option :security, | ||
digest_method: XMLSecurity::Document::SHA256, | ||
signature_method: XMLSecurity::Document::RSA_SHA256 | ||
end | ||
end | ||
end | ||
|
||
OmniAuth.config.add_camelization "imt", "IMT" |