initial commit

pull/6827/head
Markus Kahl 11 years ago
commit 1e83e58297
  1. 3
      CHANGELOG.md
  2. 9
      README.md
  3. 7
      lib/omniauth/flexible_builder.rb
  4. 67
      lib/omniauth/flexible_strategy.rb
  5. 8
      lib/open_project/auth_plugins.rb
  6. 26
      lib/open_project/auth_plugins/engine.rb
  7. 5
      lib/open_project/auth_plugins/hooks.rb
  8. 5
      lib/open_project/auth_plugins/version.rb
  9. 47
      lib/open_project/plugins/auth_plugin.rb
  10. 1
      lib/openproject-auth_plugins.rb
  11. 23
      openproject-auth_plugins.gemspec

@ -0,0 +1,3 @@
# Changelog
* `#5555` Multi-Provider login screens

@ -0,0 +1,9 @@
# OpenProject AuthPlugins Plugin
Adds support for easy integration of OmniAuth strategy providers as a means to authenticate users in OpenProject.
## Dependencies
This plugin depends on the OpenProject Plugins Plugin, so insert it into your `Gemfile.plugins`:
gem "openproject-plugins", :git => "git@github.com:opf/openproject-plugins.git", :branch => "dev"

@ -0,0 +1,7 @@
module OmniAuth
class FlexibleBuilder < Builder
def use(middleware, *args, &block)
super FlexibleStrategyClass.new(middleware), *args, &block
end
end
end

@ -0,0 +1,67 @@
require 'delegate'
module OmniAuth
class FlexibleStrategyClass < SimpleDelegator
def new(app, *args, &block)
if args.last.is_a?(Hash) && args.last.include?(:providers)
opts = args.pop
providers[__getobj__] << opts.delete(:providers)
end
__getobj__.new(app, *args, &block).tap do |strategy|
strategy.extend FlexibleStrategy
strategy.providers = providers[__getobj__].map(&:call).flatten
end
end
def providers
@@providers ||= Hash.new([])
end
end
module FlexibleStrategy
def providers=(providers)
@providers = providers
end
def on_auth_path?
(match_provider! || false) && super
end
##
# Tries to match the request path of the current request with one of the registered providers.
# If a match is found the strategy is intialised with that provider to handle the request.
def match_provider!
return false unless @providers
@provider = providers.find do |p|
(current_path =~ /#{path_for_provider(p.to_hash[:name])}/) == 0
end
if @provider
options.merge! provider.to_hash
end
@provider
end
def path_for_provider(name)
"#{path_prefix}/#{name}"
end
def providers
@providers
end
def provider
@provider
end
def dup
super.tap do |s|
s.extend FlexibleStrategy
s.providers = providers
end
end
end
end

@ -0,0 +1,8 @@
module OpenProject
module AuthPlugins
require "open_project/plugins/auth_plugin"
require "omniauth/flexible_builder"
require "omniauth/flexible_strategy"
require "open_project/auth_plugins/engine"
end
end

@ -0,0 +1,26 @@
# Prevent load-order problems in case openproject-plugins is listed after a plugin in the Gemfile
# or not at all
require 'open_project/plugins'
module OpenProject::OpenIDConnect
class Engine < ::Rails::Engine
engine_name :openproject_auth_plugins
include OpenProject::Plugins::ActsAsOpEngine
register 'openproject-auth_plugins',
:author_url => 'http://finn.de',
:requires_openproject => '>= 3.1.0pre1'#,
# :global_assets => { css: 'openid_connect/openid_connect.css' },
# :settings => { 'default' => { 'providers' => {} } }
# assets %w(
# openid_connect/openid_connect.css
# openid_connect/auth_provider-google.png
# )
initializer 'auth_plugins.register_hooks' do
require 'open_project/auth_plugins/hooks'
end
end
end

@ -0,0 +1,5 @@
module OpenProject::OpenIDConnect
class Hooks < Redmine::Hook::ViewListener
render_on :view_account_login_auth_provider, :partial => 'hooks/login/providers'
end
end

@ -0,0 +1,5 @@
module OpenProject
module AuthPlugins
VERSION = "0.0.1"
end
end

@ -0,0 +1,47 @@
#-- copyright
# OpenProject AuthPlugins
#
# Copyright (C) 2014 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.md for more details.
#++
module OpenProject::Plugins
module AuthPlugin
def self.included(base)
base.class_eval do
initializer "#{engine_name}.middleware" do |app|
init_auth
strategies = omniauth_strategies
providers = lambda do |strategy|
lambda { providers_for_strategy(strategy) }
end
app.config.middleware.use OmniAuth::FlexibleBuilder do
strategies.each do |strategy|
provider strategy, :providers => providers.call(strategy)
end
end
end
end
end
def init_auth; end
def omniauth_strategies
raise "subclass responsiblity"
end
def providers_for_strategy(strategy)
raise "subclass responsiblity"
end
end
end

@ -0,0 +1 @@
require 'open_project/auth_plugins'

@ -0,0 +1,23 @@
# encoding: UTF-8
$:.push File.expand_path("../lib", __FILE__)
require 'open_project/auth_plugins/version'
Gem::Specification.new do |s|
s.name = "openproject-auth_plugins"
s.version = OpenProject::AuthPlugins::VERSION
s.authors = "Finn GmbH"
s.email = "info@finn.de"
s.homepage = "https://www.openproject.org/projects/auth_plugins" # TODO check this URL
s.summary = 'OpenProject Auth Plugins'
s.description = "Integration of OmniAuth strategy providers for authentication in Openproject."
s.license = "GPLv3"
s.files = Dir["{app,config,db,lib}/**/*"] + %w(CHANGELOG.md README.md)
s.add_dependency "rails", "~> 3.2.14"
s.add_dependency "openproject-plugins", "~> 1.0"
s.add_dependency "omniauth"
s.add_development_dependency "rspec", "~> 2.14"
end
Loading…
Cancel
Save