2022-04-19 14:57:53 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'omniauth_openid_connect'
|
2022-04-20 14:12:22 +02:00
|
|
|
require_relative '../data_mapping/mapper'
|
2022-04-19 14:57:53 +02:00
|
|
|
|
2023-03-29 18:01:16 +02:00
|
|
|
# Authentication strategy provided trough OpenID Connect
|
|
|
|
class OmniAuth::Strategies::SsoOpenidConnectProvider < OmniAuth::Strategies::OpenIDConnect
|
|
|
|
include OmniAuth::DataMapping::Mapper
|
2022-04-19 14:57:53 +02:00
|
|
|
|
2023-03-29 18:01:16 +02:00
|
|
|
def self.active_provider
|
|
|
|
active_provider = Rails.configuration.auth_provider
|
|
|
|
if active_provider.providable_type != 'OpenIdConnectProvider'
|
|
|
|
raise "Trying to instantiate the wrong provider: Expected OpenIdConnectProvider, received #{active_provider.providable_type}"
|
2022-04-19 14:57:53 +02:00
|
|
|
end
|
|
|
|
|
2023-03-29 18:01:16 +02:00
|
|
|
active_provider
|
|
|
|
end
|
2022-04-19 14:57:53 +02:00
|
|
|
|
2023-03-29 18:01:16 +02:00
|
|
|
# Strategy name.
|
|
|
|
option :name, active_provider.strategy_name
|
2022-04-20 14:12:22 +02:00
|
|
|
|
2023-03-29 18:01:16 +02:00
|
|
|
info do
|
|
|
|
{
|
|
|
|
mapping: parsed_info
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def parsed_info
|
|
|
|
mapped_info(
|
|
|
|
OmniAuth::Strategies::SsoOpenidConnectProvider.active_provider.auth_provider_mappings,
|
|
|
|
user_info: user_info.raw_attributes
|
|
|
|
)
|
2022-04-19 14:57:53 +02:00
|
|
|
end
|
|
|
|
end
|