class Twilio::JWT::BaseJWT

Public Class Methods

new(secret_key: nil, issuer: nil, subject: nil, nbf: nil, ttl: 3600, valid_until: nil) click to toggle source

valid_until overrides ttl if specified

   # File lib/twilio-ruby/jwt/jwt.rb
13 def initialize(secret_key: nil, issuer: nil, subject: nil, nbf: nil, ttl: 3600, valid_until: nil)
14   if secret_key.nil?
15     raise ArgumentError, 'JWT does not have a signing key'
16   end
17 
18   @secret_key = secret_key
19   @issuer = issuer
20   @subject = subject
21   @algorithm = 'HS256'
22   @nbf = nbf
23   @ttl = ttl
24   @valid_until = valid_until
25 end

Public Instance Methods

_generate_headers() click to toggle source
   # File lib/twilio-ruby/jwt/jwt.rb
27 def _generate_headers
28   {}
29 end
_generate_payload() click to toggle source
   # File lib/twilio-ruby/jwt/jwt.rb
31 def _generate_payload
32   raise NotImplementedError
33 end
headers() click to toggle source
   # File lib/twilio-ruby/jwt/jwt.rb
35 def headers
36   headers = _generate_headers.clone
37   headers['typ'] = 'JWT'
38   headers['alg'] = @algorithm
39   headers
40 end
payload() click to toggle source
   # File lib/twilio-ruby/jwt/jwt.rb
42 def payload
43   payload = _generate_payload.clone
44 
45   payload[:iss] = @issuer
46   payload[:nbf] = @nbf || Time.now.to_i
47   payload[:exp] = @valid_until.nil? ? Time.now.to_i + @ttl : @valid_until
48   payload[:sub] = @subject unless @subject.nil?
49 
50   payload
51 end
to_jwt() click to toggle source
   # File lib/twilio-ruby/jwt/jwt.rb
53 def to_jwt
54   ::JWT.encode payload, @secret_key, @algorithm, headers
55 end
Also aliased as: to_s
to_s()
Alias for: to_jwt