Vonage / vonage-ruby-sdk

Vonage REST API client for Ruby. API support for SMS, Voice, Text-to-Speech, Numbers, Verify (2FA) and more.
https://developer.vonage.com
Apache License 2.0
216 stars 108 forks source link

I am suddenly getting a Vonage::AuthenticationError (it's been working fine before) #296

Closed the-bass closed 9 months ago

the-bass commented 9 months ago

I am using this gem for a few months by now in production and until November 1 everything has been working great. But then I suddenly started getting

Vonage::AuthenticationError - Vonage::AuthenticationError:
    /usr/local/bundle/gems/vonage-7.8.2/lib/vonage/namespace.rb:213:in `parse'
    /usr/local/bundle/gems/vonage-7.8.2/lib/vonage/namespace.rb:116:in `request'
    /usr/local/bundle/gems/vonage-7.8.2/lib/vonage/voice.rb:72:in `create'

when trying to start a call using vonage.voice.create.

I immediately confirmed that the api secret is still valid and also updated the private key for my Vonage application, but that didn't help. Only after updating the vonage gem it started working again.

Do you know what happened? Did Vonage change the API on November 1 and I missed the announcement?

Here's a complete list of the version changes:

--- a/server/Gemfile.lock
+++ b/server/Gemfile.lock
@@ -74,7 +74,7 @@ GEM
     os (1.1.4)
     pdfkit (0.8.6)
     phone (1.2.3)
-    phonelib (0.7.7)
+    phonelib (0.8.4)
     public_suffix (4.0.7)
     racc (1.6.0)
     rack (2.2.4)
@@ -142,19 +142,20 @@ GEM
     unf_ext (0.0.8.2)
     vcr (6.1.0)
     version_gem (1.1.0)
-    vonage (7.8.2)
+    vonage (7.18.0)
+      multipart-post (~> 2.0)
       phonelib
       rexml
       sorbet-runtime (~> 0.5)
-      vonage-jwt (~> 0.1.0)
+      vonage-jwt (~> 0.2.0)
       zeitwerk (~> 2, >= 2.2)
-    vonage-jwt (0.1.2)
+    vonage-jwt (0.2.0)
       jwt (~> 2)
     webmock (3.18.1)
       addressable (>= 2.8.0)
       crack (>= 0.3.2)
       hashdiff (>= 0.4.0, < 2.0.0)
-    zeitwerk (2.6.7)
+    zeitwerk (2.6.12)
superchilled commented 9 months ago

Hi @the-bass can I just double check -- you were previously using v7.8.2 of the SDK and you are now using 7.18.0 (the latest version)? ~Did you start experiencing the issues after you updated to the latest version?~ That's quite a few versions in between, but they've all been minor releases, so there shouldn't be any breaking changes.

Can you also let me know how you're instantiating the Client object? (i.e. which params you're passing into the Vonage::Client.new method invocation? -- I don't need the actual values, just would be useful to know which params you're setting on the Client object).

Edit: sorry, just noticed that you said updating to the latest version fixed the issue. Difficult to tell at this stage what the root cause was, but it could be due to issue with JWT token parsing, for which I released a bug fix in the Ruby JWT library (which is a dependency of the Ruby SDK).

the-bass commented 9 months ago

Hi @superchilled!

you were previously using v7.8.2 of the SDK and you are now using 7.18.0 (the latest version)?

That's correct.

Can you also let me know how you're instantiating the Client object?

I do

Vonage::Client.new(
    api_key: apiKey,
    api_secret: apiSecret,
    application_id: applicationId,
    private_key: File.read(privateKeyPath),
)

Thanks for your response!

superchilled commented 9 months ago

Hi @the-bass. So, the Client instantiation looks fine. Calling a method on the Voice object will create a JWT using the application_id and private_key, so the api_key and api_secret aren't technically required in this case (although setting them in the Client shouldn't affect anything).

I'm not 100% sure what the issue is tbh. As far as I know there haven't been any changes to the Voice API or to the API Gateway. I'll do a few tests and see if I can replicate the issue.

Quick question: did you regenerate your private key at any point, or are you using the same one both before and after the issue occurred?

the-bass commented 9 months ago

Quick question: did you regenerate your private key at any point, or are you using the same one both before and after the issue occurred?

@superchilled One of the first things I tried with the Vonage app I am using for development was creating a new private key, but that hadn't any effect. After updating the gem, it started working again for both, the development app as well as the production app, where the private key is still the same it has always been.

superchilled commented 9 months ago

@the-bass I've carried out some tests of the Vonage::Voice#create method, using a few different versions of the Gem (including 7.8.2), but have been unable to replicate the issue that you experienced. In all cases, I was able to interact with the Voice API successfully and didn't receive an AuthenticationError.

Based on my tests, I don't think there is an issue with the Vonage RubyGem or that the issue was caused by a change in the API. TBH, I'm not really sure what the cause of the issue could have been, given that you are using the same credentials as previously in production, and the only thing that's changed is the Gem version and its dependencies.

I don't usually like to close issues with "works on my machine", but given that updating the Gem has 'resolved' things at your end, are you happy for me to close this issue?

As a side-note, in the v7.16.0 release, I added some functionality to the exception handling to provide access to the actual HTTP response in the exception object (this is documented in the README here). Hopefully the issue doesn't re-occur, but if anything similar happens in the future this should hopefully make it a bit easier to debug.

the-bass commented 9 months ago

@superchilled I completely understand and appreciate that you've taken the time to look into it. Good to know about the additional information in the exception as well. I'll take a look at that should I ever run into this problem again. Thank you!