class Twilio::JWT::AccessToken

Attributes

account_sid[RW]
grants[RW]
identity[RW]
nbf[RW]
region[RW]
secret[RW]
signing_key_id[RW]
ttl[RW]
valid_until[RW]

Public Class Methods

new( account_sid, signing_key_sid, secret, grants = [], identity: nil, nbf: nil, ttl: 3600, valid_until: nil, region: nil ) click to toggle source
Calls superclass method
   # File lib/twilio-ruby/jwt/access_token.rb
26 def initialize(
27   account_sid,
28   signing_key_sid,
29   secret,
30   grants = [],
31   identity: nil,
32   nbf: nil,
33   ttl: 3600,
34   valid_until: nil,
35   region: nil
36 )
37   super(secret_key: secret,
38         issuer: signing_key_sid,
39         subject: account_sid,
40         nbf: nbf,
41         ttl: ttl,
42         valid_until: valid_until)
43   @account_sid = account_sid
44   @signing_key_sid = signing_key_sid
45   @secret = secret
46   @identity = identity
47   @nbf = nbf
48   @grants = grants
49   @ttl = ttl
50   @valid_until = valid_until
51   @region = region
52 end

Public Instance Methods

add_grant(grant) click to toggle source
   # File lib/twilio-ruby/jwt/access_token.rb
54 def add_grant(grant)
55   @grants.push(grant)
56 end

Protected Instance Methods

_generate_headers() click to toggle source
   # File lib/twilio-ruby/jwt/access_token.rb
77 def _generate_headers
78   headers = {
79     cty: 'twilio-fpa;v=1'
80   }
81 
82   headers[:twr] = region unless region&.nil?
83 
84   headers
85 end
_generate_payload() click to toggle source
   # File lib/twilio-ruby/jwt/access_token.rb
60 def _generate_payload
61   now = Time.now.to_i
62   grants = {}
63   grants[:identity] = @identity if @identity
64 
65   @grants.each { |grant| grants[grant._key] = grant._generate_payload } unless @grants.empty?
66 
67   payload = {
68     jti: "#{@signing_key_sid}-#{now}",
69     grants: grants
70   }
71 
72   payload
73 end