From df7024121ca83b334e12e2014d4be03a0b32e050 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 4 Jun 2014 12:41:32 +0100 Subject: [PATCH] based openid plugin on general auth plugin --- lib/open_project/openid_connect/engine.rb | 28 ++++++++--------------- openproject-openid_connect.gemspec | 1 + 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/lib/open_project/openid_connect/engine.rb b/lib/open_project/openid_connect/engine.rb index fc5398f106..5f580a9d3b 100644 --- a/lib/open_project/openid_connect/engine.rb +++ b/lib/open_project/openid_connect/engine.rb @@ -19,7 +19,7 @@ module OpenProject::OpenIDConnect openid_connect/auth_provider-google.png ) - initializer "openid_connect.middleware" do |app| + def init_auth # Loading OpenID providers manually since rails doesn't do it automatically, # possibly due to non trivially module-name-convertible paths. require 'omniauth/openid_connect/provider' @@ -36,28 +36,20 @@ module OpenProject::OpenIDConnect end OmniAuth::OpenIDConnect::Provider.load_generic_providers + end - app.config.middleware.use OmniAuth::Builder do - OmniAuth::OpenIDConnect::Provider.all.each do |pro| - p = pro.new - settings_available = if pro.available? - "settings available" - else - "settings missing" - end + def omniauth_strategies + [:openid_connect] + end - Rails.logger.info "[OpenID Connect] Registering provider for #{p.name} (#{settings_available})" - provider :openid_connect, :name => p.name, :setup => lambda { |env| - Rails.logger.info "[OpenID Connect] Trying dynamic provider #{p.name}" - opt = env['omniauth.strategy'].options - p.to_hash.each do |key, value| - opt[key] = value - end - } - end + def providers_for_strategy(strategy) + if strategy == :openid_connect + OmniAuth::OpenIDConnect::Provider.available.map(&:new) end end + include OpenProject::Plugins::AuthPlugin + initializer 'openid_connect.register_hooks' do require 'open_project/openid_connect/hooks' end diff --git a/openproject-openid_connect.gemspec b/openproject-openid_connect.gemspec index ed71cddccb..e3605f6351 100644 --- a/openproject-openid_connect.gemspec +++ b/openproject-openid_connect.gemspec @@ -17,6 +17,7 @@ Gem::Specification.new do |s| s.add_dependency "rails", "~> 3.2.14" s.add_dependency "openproject-plugins", "~> 1.0" + s.add_dependency "openproject-auth_plugins" s.add_dependency "omniauth" s.add_development_dependency "rspec", "~> 2.14"