twilio / authy-ruby

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

If id or token are nil, the endpoint is wrong and users won't realize it. #4

Closed danpal closed 11 years ago

danpal commented 11 years ago

Please check and warn the person.


def self.verify(params)
      token = params.delete(:token) || params.delete('token')
      user_id = params.delete(:id) || params.delete('id')
      params[:force] = true if params[:force].nil? && params['force'].nil?

      url = "#{Authy.api_uri}/protected/json/verify/#{escape_for_url(token)}/#{escape_for_url(user_id)}"
      response = http_client.get(url, {:api_key => Authy.api_key}.merge(params))

      Authy::Response.new(response)
    end

From our chat:

[1:11 PM] XXXXX:

            When trying out the sandbox URL, I get the error: "Requested URL was not found. Please check         http://docs.authy.com/ to see the valid URLs"
    Using the ruby gem

[1:16 PM] Daniel Palacio:

            Try this one sec
    response = Authy::API.verify(:id => @user.authy_id.to_s,  :token => params[:authy_token].to_s)
    Make sure params[:authy_token] and authy_id are not nil
    What I think is happening is one of them is nil so you are hitting the wrong end-point

[1:17 PM] XXXX:

            ahh, that seems to be the case
    if you have an empty string as the token

[1:17 PM] Daniel Palacio:

           Yes, ok so what happens is the authy ruby gem is going to construct the URL
    but it won't be well constructed
    So the API router doesn't know the URL you are trying to hit
    We can modify the gem to Warn on nil values.
    But you still need to fix the code

[1:19 PM] XXXX:

           yeah, I didn't realize that was the cause
drewblas commented 11 years ago

+1 I'd like to see the gem validate the input to avoid constructing bad URLs.

sarcilav commented 11 years ago

Hey @drewblas, sorry for the delayed the response (-__-), I'll take care of this today