Class: Vonage::JWT
- Inherits:
-
Object
- Object
- Vonage::JWT
- Defined in:
- lib/vonage/jwt.rb
Class Method Summary collapse
-
.generate(payload, private_key = nil) ⇒ String
Generate an encoded JSON Web Token.
-
.verify_hs256_signature(token:, signature_secret:) ⇒ Boolean
Validate a JSON Web Token from a Vonage Webhook.
Class Method Details
.generate(payload, private_key = nil) ⇒ String
Generate an encoded JSON Web Token.
By default the Vonage Ruby SDK generates a short lived JWT per request.
To generate a long lived JWT for multiple requests or to specify JWT claims directly call generate to generate a token, and set the token attribute on the client object.
Documentation for the Vonage Ruby JWT generator gem can be found at https://www.rubydoc.info/github/Vonage/vonage-jwt-ruby
36 37 38 39 40 41 |
# File 'lib/vonage/jwt.rb', line 36 def self.generate(payload, private_key = nil) raise "Expecting 'private_key' in either the payload or as a separate parameter" if !payload[:private_key] && !private_key payload[:private_key] = private_key if private_key && !payload[:private_key] @token = Vonage::JWTBuilder.new(payload).jwt.generate end |
.verify_hs256_signature(token:, signature_secret:) ⇒ Boolean
Validate a JSON Web Token from a Vonage Webhook.
Certain Vonage APIs include a JWT signed with a user's account signature secret in the Authorization header of Webhook requests. This method can be used to verify that those requests originate from the Vonage API.
56 57 58 |
# File 'lib/vonage/jwt.rb', line 56 def self.verify_hs256_signature(token:, signature_secret:) verify_signature(token, signature_secret, 'HS256') end |