2

I'm using oauth to try and login through venmo based on this guide. This isn't official and venmo docs don't even show code example with ruby.

At first, I couldn't even see the venmo login. I removed the ENV and brackets around the id and secret in the initializer and then I could see the login. When I submit and it hits the call back I get this error: (and I think it retries endlessly...I have to manually shut down server)

{"error": {"message": "Missing argument: client_id.", "code": 241}}
I, [2014-04-16T11:49:48.124423 #47700]  INFO -- omniauth: (venmo) Callback phase initiated.
E, [2014-04-16T11:49:48.345202 #47700] ERROR -- omniauth: (venmo) Authentication failure!       invalid_credentials: OAuth2::Error, {"message"=>"Missing argument: client_id.", "code"=>241}: 

Here is my route:

get 'users/auth/venmo/callback' => 'omniauth_callbacks_controller#create'

Gems:

gem 'devise'
gem 'omniauth'
gem 'omniauth-venmo'

I have this in my initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
   provider :venmo, 'id', 'secret', :scope => 'access_feed,access_profile,access_friends,make_payments'   
end

This is my callback controller

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def venmo
    @user = User.find_for_oauth(env["omniauth.auth"], current_user)
    raise
    if @user.persisted?
        sign_in_and_redirect root_path, :event => :authentication
        set_flash_message(:notice, :success, :kind => "Venmo") if is_navigational_format?
    else
        session["devise.venmo_uid"] = env["omniauth.auth"]
        redirect_to new_user_registration_url
    end
end

protected

def auth_hash
    request.env['omniauth.auth']
end 

end

and I have initializers/devise.rb

   require 'omniauth-venmo'
   config.omniauth :venmo, "KEY", "SECRET"

-- with the values filled in of course. I would appreciate the help... Thank you!!

UPDATE: I've pushed this to a github repository and one of my peers pulled it. He did not get the same error. What would the reason for this be..? here is the output

Peege151
  • 1,562
  • 2
  • 21
  • 45
  • If you add back `ENV['VENMO_CLIENT_ID']` and `ENV['VENMO_CLIENT_SECRET']` then set the environmental variables before you run your rails process (i.e. `export VENMO_CLIENT_ID=whatever` in the same terminal) then does it work? – agf Apr 16 '14 at 18:10
  • i've tried using $export, and yeah. Still no dice – Peege151 Apr 16 '14 at 18:17
  • What error do you get then? – agf Apr 16 '14 at 18:19
  • the same one.. it's strange – Peege151 Apr 16 '14 at 18:43
  • @agf any ideas? I had a friend pull from our github and he didn't even get the same error. He had an SSL error, which is closer I think towards functional. – Peege151 Apr 16 '14 at 21:59
  • I work at Braintree (who owns Venmo) and reached out to them for help. I'll check this again tomorrow morning and if they haven't got back to you I'll bother them again. – agf Apr 16 '14 at 22:00
  • I saw that! Thank you. My setup looks proper though, right? – Peege151 Apr 16 '14 at 22:01
  • AFAICT. I don't know OmniAuth very well or the Venmo plugin at all though, so I think your best bet may be the issue you opened on Github. – agf Apr 16 '14 at 22:03
  • Yeah the Venmo guys I guess are still developng docs for ruby. Maybe this will help them. -- Anyway, thanks. – Peege151 Apr 16 '14 at 22:04
  • Hey @Peege151, I just noticed this thread. I'm the author of omniauth-venmo. – Tom May 20 '14 at 21:45
  • Hey @Peege151, I just noticed this thread. While I'm not a Venmo employee, I am the author of omniauth-venmo. If you're using Devise, you shouldn't need config/initializers/omniauth.rb, just the Devise config. That said, if the Devise config you shared is all that's in that file then the file is not properly put together. Sorry for the delay. Github issues is your friend. ;-) – Tom May 20 '14 at 21:52

2 Answers2

4

@Peege151... I created a working solution with devise integration as said by you..here is my code below, use it for reference purpose. I don't say this is the exact solution for the raised question but this may help since i got it working

Gems:

gem 'rails 3.2.14' # Important~
gem 'devise'
gem 'omniauth'
gem 'omniauth-venmo'

I have not created omniauth.rb in initializers .... instead i added configuration in devise.rb as u wanted it with devise

my devise.rb :

require "omniauth-venmo"
config.omniauth :venmo, '--Your APP KEY -- ', '-- App Secret--',{:client_options => {:ssl => {:verify => false}}}

above line i have set SSL verification to false,, if u want enable SSL with (:verify => true).

This is my callback controller code:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def venmo 
   @user = User.find_for_oauth(request.env["omniauth.auth"], current_user) 
   if @user.persisted? 
     sign_in_and_redirect @user, :event => :authentication 
     set_flash_message(:notice, :success, :kind => "Venmo") if is_navigational_format? 
   else 
     session["devise.twitter_uid"] = request.env["omniauth.auth"] 
     redirect_to new_user_registration_url
   end
  end  
end

User.rb code:

class User < ActiveRecord::Base
  TEMP_EMAIL = 'change@me.com'
  TEMP_EMAIL_REGEX = /change@me.com/ 
  devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :provider , :uid 
  devise :omniauthable

  def self.find_for_oauth(auth, signed_in_resource=nil) 
      user = User.where(:provider => auth.provider, :uid => auth.uid).first
      if user 
        return user
      else 
        registered_user = User.where(:email => auth.info.email).first 
        if registered_user 
          return registered_user
        else 
          user = User.create(name:auth.extra.raw_info.name,
                          provider:auth.provider,
                          uid:auth.uid,
                          email:auth.info.email.blank? ? TEMP_EMAIL : auth.info.email,
                          password:Devise.friendly_token[0,20],
                        )        
         end          
      end
      user
    end
  end

Here is my for devise and callback routes.rb:

 devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }
 get '/auth/venmo/callback' => 'users/omniauth_callbacks#venmo'

login page link:

<%= link_to "Sign in with Venmo", user_omniauth_authorize_path(:venmo) %> 

screenshot:

enter image description here

Peege151
  • 1,562
  • 2
  • 21
  • 45
Dave
  • 4,376
  • 3
  • 24
  • 37
  • The problem here appears to be that Devise is not up-to-date. The Devise config that is being shared isn't correct per recent standards. – Tom May 20 '14 at 21:53
2

I'm not sure the exact issue here, but one thing to be cognizant of is it looks you're hitting a naked URL instead of api.venmo.com/v1/, which is our latest version. Try that first, Then we can work from there.

diogeneshamilton
  • 568
  • 1
  • 5
  • 12
  • 2
    The problem was the gem I was using wasn't compatible with rails 4, only rails 3.2 which I should have figured out sooner. – Peege151 Apr 19 '14 at 14:11