1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

(authentication) configure devise/omniauth to use the OpenIdConnect configuration

This commit is contained in:
Sylvain 2022-03-29 12:18:16 +02:00
parent 8495e2a7a0
commit bd68c5e7e8
2 changed files with 26 additions and 0 deletions

View File

@ -4,4 +4,28 @@
# the OpenID Connect protocol.
class OpenIdConnectProvider < ApplicationRecord
has_one :auth_provider, as: :providable
validates :issuer, presence: true
validates :client_identifier, presence: true
validates :client_secret, presence: true
validates :client_host, presence: true
validates :client_scheme, inclusion: { in: %w[http https] }
validates :client_port, numericality: { only_integer: true, greater_than: 0, less_than: 65_535 }
validates :response_type, inclusion: { in: %w[code id_token], allow_nil: true }
validates :response_mode, inclusion: { in: %w[query fragment form_post web_message], allow_nil: true }
validates :display, inclusion: { in: %w[page popup touch wap], allow_nil: true }
validates :prompt, inclusion: { in: %w[none login consent select_account], allow_nil: true }
def config
OpenIdConnectProvider.columns.map(&:name).filter { |n| !n.start_with?('client_') }.map do |n|
[n, send(n)]
end.push(['client_options', client_config]).to_h
end
def client_config
OpenIdConnectProvider.columns.map(&:name).filter { |n| n.start_with?('client_') }.map do |n|
[n.sub('client_', ''), send(n)]
end.to_h
end
end

View File

@ -234,6 +234,8 @@ Devise.setup do |config|
config.omniauth OmniAuth::Strategies::SsoOauth2Provider.name.to_sym,
active_provider.providable.client_id,
active_provider.providable.client_secret
elsif active_provider.providable_type == OpenIdConnectProvider.name
config.omniauth :openid_connect, active_provider.config
end
# ==> Warden configuration