Class: Twilio::Util::AccessToken
- Inherits:
-
Object
- Object
- Twilio::Util::AccessToken
- Defined in:
- lib/twilio-ruby/util/access_token.rb
Defined Under Namespace
Classes: ConversationsGrant, IpMessagingGrant
Instance Attribute Summary collapse
-
#account_sid ⇒ Object
Returns the value of attribute account_sid.
-
#identity ⇒ Object
Returns the value of attribute identity.
-
#nbf ⇒ Object
Returns the value of attribute nbf.
-
#secret ⇒ Object
Returns the value of attribute secret.
-
#signing_key_id ⇒ Object
Returns the value of attribute signing_key_id.
-
#ttl ⇒ Object
Returns the value of attribute ttl.
Instance Method Summary collapse
- #add_grant(grant) ⇒ Object
-
#initialize(account_sid, signing_key_id, secret, ttl = 3600, identity = nil, nbf = nil) ⇒ AccessToken
constructor
A new instance of AccessToken.
- #to_jwt(algorithm = 'HS256') ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(account_sid, signing_key_id, secret, ttl = 3600, identity = nil, nbf = nil) ⇒ AccessToken
Returns a new instance of AccessToken.
11 12 13 14 15 16 17 18 19 |
# File 'lib/twilio-ruby/util/access_token.rb', line 11 def initialize(account_sid, signing_key_id, secret, ttl=3600, identity=nil, nbf=nil) @account_sid = account_sid @signing_key_sid = signing_key_id @secret = secret @ttl = ttl @identity = identity @nbf = nbf @grants = [] end |
Instance Attribute Details
#account_sid ⇒ Object
Returns the value of attribute account_sid.
4 5 6 |
# File 'lib/twilio-ruby/util/access_token.rb', line 4 def account_sid @account_sid end |
#identity ⇒ Object
Returns the value of attribute identity.
4 5 6 |
# File 'lib/twilio-ruby/util/access_token.rb', line 4 def identity @identity end |
#nbf ⇒ Object
Returns the value of attribute nbf.
4 5 6 |
# File 'lib/twilio-ruby/util/access_token.rb', line 4 def nbf @nbf end |
#secret ⇒ Object
Returns the value of attribute secret.
4 5 6 |
# File 'lib/twilio-ruby/util/access_token.rb', line 4 def secret @secret end |
#signing_key_id ⇒ Object
Returns the value of attribute signing_key_id.
4 5 6 |
# File 'lib/twilio-ruby/util/access_token.rb', line 4 def signing_key_id @signing_key_id end |
#ttl ⇒ Object
Returns the value of attribute ttl.
4 5 6 |
# File 'lib/twilio-ruby/util/access_token.rb', line 4 def ttl @ttl end |
Instance Method Details
#add_grant(grant) ⇒ Object
21 22 23 |
# File 'lib/twilio-ruby/util/access_token.rb', line 21 def add_grant(grant) @grants.push(grant) end |
#to_jwt(algorithm = 'HS256') ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/twilio-ruby/util/access_token.rb', line 25 def to_jwt(algorithm='HS256') now = Time.now.to_i - 1 headers = { 'cty' => 'twilio-fpa;v=1', 'typ' => 'JWT' } grants = {} if @identity grants['identity'] = @identity end @grants.each { |grant| grants[grant.key] = grant.payload } payload = { 'jti' => "#{@signing_key_sid}-#{now}", 'iss' => @signing_key_sid, 'sub' => @account_sid, 'exp' => now + @ttl, 'grants' => grants } payload['nbf'] = @nbf unless @nbf.nil? JWT.encode payload, @secret, algorithm, headers end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/twilio-ruby/util/access_token.rb', line 51 def to_s to_jwt end |