Vonage/vonage-ruby-sdk

Cannot set a token.

brendt-ujet opened this issue · 3 comments

If you pass a token to the client as the readme documentation indicates:
client = Vonage::Client.new(token: token)

An error is thrown:

Uncaught exception: No application_id provided. Either provide an application_id, or set an auth token. You can add new applications from the Vonage dashboard.

If you pass in the application_id and private_key and the token, then the token parameter is ignored and a new token is generated. I would like to be able to set a token. If you do not want the user to be able to set a token, then you should remove that parameter or throw an error.

Gem version:
vonage 7.7.2

This is also issue form me. I'm not able to setup authentication.

I get the token like this and that works:

 claims = {
      application_id: app_id,
      private_key: private_key,
      nbf: 1483315200,
      ttl: 800
    }

token  = Vonage::JWT.generate(claims)
client = Vonage::Client.new(token: token)

When I try to send the message I get this error:
No application_id provided. Either provide an application_id, or set an auth token. You can add new applications from the Vonage dashboard. See https://developer.nexmo.com/concepts/guides/applications for details, or email support@nexmo.com if you have any questions. (Vonage::AuthenticationError)


Initially I didn't want to go with JWT route at all, but other route also doesn't work for me:

client = Vonage::Client.new(application_id: app_id, private_key: private_key)

message = Vonage::Messaging::Message.whatsapp(type: 'text', message: message)
response = client.messaging.send(to: to, from: from, **message)

Error I get is:

{"title":"Unauthorised","detail":"Invalid Token"}
/Users/dixpac/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/vonage-7.7.2/lib/vonage/namespace.rb:213:in `parse': Vonage::AuthenticationError (Vonage::AuthenticationError)

I don't understand why I get the error, when same app_id and private_key gets me a token with a JWT approach.

@brendt-ujet thanks for raising this. I feel that this is a feature that should be in the SDK. At this stage I'm not sure whether the behaviour you've described is due to a bug or because the feature hasn't been fully/correctly implemented. I'll investigate and make any fixes necessary.


@dixpac what you're describing sounds like it might be a separate issue. Instantiating a client with app ID and private key should work (and was tested when implementing Messages API in the Ruby SDK):

client = Vonage::Client.new(application_id: app_id, private_key: private_key)

Can I just check, the Vonage Application to which the application_id and private_key relate:

  • Has been enabled for Messages v1?
  • Has a WhatsApp Business Account (WABA) number linked to the Application? (to check, go to External Accounts in the Dashboard, and see in the 'Application Usage' column for the WABA number if the Application name for the Application identified by the app id and private key is listed there.

This should now be fixed as part of the latest release. Closing this issue, but please re-open if you experience any further problems with this.