twinslash / redmine_omniauth_google

This plugin is used to authenticate in redmine through Google.
http://www.redmine.org/plugins/redmine_omniauth_google
94 stars 103 forks source link

Failing to authenticate through Google #20

Closed mvange closed 9 years ago

mvange commented 9 years ago

Hi,

I have configured both google and redmine (bitnami distro) per description. Google set up went well, so passed their test. When I try to log in, either with an account that exists, or with a new one, in order to create account, I get an error 500.

Logs are below.

I'm at a loss. Help!?

Started GET "/oauth_google?back_url=http%3A%2F%2Fbitnami-redmine-4a6c.cloudapp.net%2F" for 70.184.92.15 at 2015-05-07 17:20:28 +0000 Processing by RedmineOauthController#oauth_google as HTML Parameters: {"back_url"=>"http://bitnami-redmine-4a6c.cloudapp.net/"} Current user: anonymous Redirected to https://accounts.google.com/o/oauth2/auth?client_id=359288106455-udlk87jasmbvnpv2r3trbv95p5iaufve.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Fbitnami-redmine-4a6c.cloudapp.net%2Foauth2callback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile Completed 302 Found in 7ms (ActiveRecord: 0.5ms) Started GET "/oauth2callback?code=4/QR4FYIPE2Di14FE5lPlk8dg6LLMU0PNj-dHM5ajnlL4.QhCHiw76Y5YREnp6UAPFm0FmSclemgI" for 70.184.92.15 at 2015-05-07 17:20:36 +0000 Processing by RedmineOauthController#oauth_google_callback as HTML Parameters: {"code"=>"4/QR4FYIPE2Di14FE5lPlk8dg6LLMU0PNj-dHM5ajnlL4.QhCHiw76Y5YREnp6UAPFm0FmSclemgI"} Current user: anonymous Completed 500 Internal Server Error in 380ms (ActiveRecord: 0.9ms)

NoMethodError (undefined method find_or_initialize_by_mail' for #<Class:0x007f897ea07788>): activerecord (4.2.1) lib/active_record/dynamic_matchers.rb:26:inmethod_missing' plugins/redmine_omniauth_google/app/controllers/redmine_oauth_controller.rb:41:in try_to_login' plugins/redmine_omniauth_google/app/controllers/redmine_oauth_controller.rb:26:inoauth_google_callback' actionpack (4.2.1) lib/action_controller/metal/implicit_render.rb:4:in send_action' actionpack (4.2.1) lib/abstract_controller/base.rb:198:inprocess_action' actionpack (4.2.1) lib/action_controller/metal/rendering.rb:10:in process_action' actionpack (4.2.1) lib/abstract_controller/callbacks.rb:20:inblock in process_action' activesupport (4.2.1) lib/active_support/callbacks.rb:117:in call' activesupport (4.2.1) lib/active_support/callbacks.rb:117:incall' activesupport (4.2.1) lib/active_support/callbacks.rb:555:in block (2 levels) in compile' activesupport (4.2.1) lib/active_support/callbacks.rb:505:incall' activesupport (4.2.1) lib/active_support/callbacks.rb:505:in call' activesupport (4.2.1) lib/active_support/callbacks.rb:92:in_run_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:776:in _run_process_action_callbacks' activesupport (4.2.1) lib/active_support/callbacks.rb:81:inrun_callbacks' actionpack (4.2.1) lib/abstract_controller/callbacks.rb:19:in process_action' actionpack (4.2.1) lib/action_controller/metal/rescue.rb:29:inprocess_action' actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:32:in block in process_action' activesupport (4.2.1) lib/active_support/notifications.rb:164:inblock in instrument' activesupport (4.2.1) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.2.1) lib/active_support/notifications.rb:164:ininstrument' actionpack (4.2.1) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.2.1) lib/action_controller/metal/params_wrapper.rb:250:inprocess_action' activerecord (4.2.1) lib/active_record/railties/controller_runtime.rb:18:in process_action' actionpack (4.2.1) lib/abstract_controller/base.rb:137:inprocess' actionview (4.2.1) lib/action_view/rendering.rb:30:in process' actionpack (4.2.1) lib/action_controller/metal.rb:196:indispatch' actionpack (4.2.1) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.2.1) lib/action_controller/metal.rb:237:inblock in action'

gotva commented 9 years ago

I see you use 4th rails. I think the problem is in obsolete rails method find_or_initialize_by_mail.

Not sure if the plugin is supported now but if it is so the code should be reviewed on obsolete methods and replaced on actual analogs.

luizduma commented 9 years ago

I´m using ruby 2.1.2p95, Rails 4.2.1 and Redmine 3.0.3 and I made a little change that fixed the problem in my environment. The method find_or_initialize_by_mail is obsolete in rails 4th and the table users was changed for Redmine 3.0.X. Now we have the table email_addresses to store user´s emails.

@ $REDMINE_ROOT/plugins/redmine_omniauth_google

diff --git a/app/controllers/redmine_oauth_controller.rb          b/app/controllers/redmine_oauth_controller.rb
index dfb32cf..a0d194c 100644
--- a/app/controllers/redmine_oauth_controller.rb
+++ b/app/controllers/redmine_oauth_controller.rb
@@ -38,7 +38,8 @@ class RedmineOauthController < AccountController
   def try_to_login info
    params[:back_url] = session[:back_url]
    session.delete(:back_url)
-   user = User.find_or_initialize_by_mail(info["email"])
+   user = User.joins(:email_addresses).where(:email_addresses => {:address =>    info["email"]}).first_or_create
    if user.new_record?
       # Self-registration off
       redirect_to(home_url) && return unless Setting.self_registration?
tsezgin commented 9 years ago

luizduma, thanks for the fix. it solved my problem too.