diff options
author | Stan Hu <stanhu@gmail.com> | 2019-05-23 11:50:06 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-05-23 12:17:56 -0700 |
commit | bf8f4c135a0d893defb6dd97e07b84184f5270a7 (patch) | |
tree | 4d732d03feecdc9f6f183535994ca61071d6bc4b /lib/gitlab/omniauth_initializer.rb | |
parent | dd454852bc941130820b1c647a8580d56acb2a4f (diff) | |
download | gitlab-ce-bf8f4c135a0d893defb6dd97e07b84184f5270a7.tar.gz |
Fix OmniAuth OAuth2Generic strategy not loading
In https://github.com/rails/rails/commit/83b767ce, Rails 5.1 removed
support for using a String to specify a middleware. When the
strategy_class argument is passed from the GitLab YAML config to Devise,
Devise passes the string value straight through to Rails, and GitLab
would crash with a NoMethodError inside ActionDispatch::MiddlewareStack.
To make this OmniAuth strategy work again, we normalize the arguments by
converting the strategy_class value into an actual Class.
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/62216
Diffstat (limited to 'lib/gitlab/omniauth_initializer.rb')
-rw-r--r-- | lib/gitlab/omniauth_initializer.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/gitlab/omniauth_initializer.rb b/lib/gitlab/omniauth_initializer.rb index e0ac9eec1f2..2a2083ebae0 100644 --- a/lib/gitlab/omniauth_initializer.rb +++ b/lib/gitlab/omniauth_initializer.rb @@ -36,12 +36,25 @@ module Gitlab hash_arguments = provider['args'].merge(provider_defaults(provider)) # A Hash from the configuration will be passed as is. - provider_arguments << hash_arguments.symbolize_keys + provider_arguments << normalize_hash_arguments(hash_arguments) end provider_arguments end + def normalize_hash_arguments(args) + args.symbolize_keys! + + # Rails 5.1 deprecated the use of string names in the middleware + # (https://github.com/rails/rails/commit/83b767ce), so we need to + # pass in the actual class to Devise. + if args[:strategy_class].is_a?(String) + args[:strategy_class] = args[:strategy_class].constantize + end + + args + end + def provider_defaults(provider) case provider['name'] when 'cas3' |