twilio / authy-ruby

**Deprecated** Ruby library to access the authy API
MIT License
156 stars 47 forks source link

Authy::API.register_user doesn't fetch my user #71

Closed diegopolido closed 2 years ago

diegopolido commented 3 years ago

I created a new user in Authy App and then I'm trying to enable it in my rails app using https://github.com/twilio/authy-devise gem (also I opened an issue there too https://github.com/twilio/authy-devise/issues/158).

I tried to run on rails console, but it returns a blank object:

    @authy_user = Authy::API.register_user(
      :email => "my-valid@email.com",
      :cellphone => "myvalidnumber",
      :country_code => "validcountrycode"
    )

    => {}

What should I do?

It seems there isn't a API for "check" existing users by phone and email (maybe the /users/new API is expecting to create a new user before I set it up on Authy App?). I'm stuck with this and blocking users to use my app (strongly considering to change the 2FA method).

philnash commented 3 years ago

Hey @diegopolido, sorry you're having trouble with this gem and the devise plugin. I want to help you out with this as soon as I can!

The thing is, that is a weird result. When I run Authy::API.register_user with a valid user, I get back an Authy::User object with the user's Authy ID.

You may have errors with your request though. The thing is that an Authy::User object inherits from Authy::Response which in turn inherits from Hash. So, when you print the result out, it looks like a Hash and when you print out a result with an error, it looks like {}.

Devise Authy is actually not very good at showing you what the error was, which is why you are experiencing this redirect issue. However, since you are running this in the Rails console, you can more easily inspect the errors. Try running this in the console:

 @authy_user = Authy::API.register_user(
      :email => "my-valid@email.com",
      :cellphone => "myvalidnumber",
      :country_code => "validcountrycode"
    )

puts @authy_user.errors

Hopefully that should shed some light on the issue and let you fix it. In my experience in the past, a misconfigured Authy API key was the cause. Hopefully it is something similar for you.

Let me know how you get on with that.

st3v3odom commented 3 years ago

Same exact thing happened to me. My account was suspended for lack of funds. The empty {} was confusing. I didn't realize the returned object had methods available on it - including .errors. Doing the @authy_user.errors revealed my issue.

philnash commented 2 years ago

I am closing this issue as this library is now deprecated. But I think we solved the issues too! Please see the README for updates on why this is being deprecated and what you can do about it.