Class: AgoraDynamicKey::AccessToken
- Inherits:
-
Object
- Object
- AgoraDynamicKey::AccessToken
- Defined in:
- lib/dynamic_key/access_token.rb
Constant Summary collapse
- VERSION =
"006"
- ONE_DAY =
864_00
- SEED =
2 ** 32 - 1
Instance Attribute Summary collapse
-
#app_certificate ⇒ Object
Returns the value of attribute app_certificate.
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#channel_name ⇒ Object
Returns the value of attribute channel_name.
-
#expired_ts ⇒ Object
Returns the value of attribute expired_ts.
-
#privilege_expired_ts ⇒ Object
Returns the value of attribute privilege_expired_ts.
-
#privileges ⇒ Object
Returns the value of attribute privileges.
-
#salt ⇒ Object
Returns the value of attribute salt.
-
#uid ⇒ Object
Returns the value of attribute uid.
Class Method Summary collapse
Instance Method Summary collapse
- #add_privilege(privilege, ts) ⇒ Object (also: #grant)
- #build ⇒ Object
- #build! ⇒ Object
- #from_string(token) ⇒ Object
-
#initialize(args = {}) ⇒ AccessToken
constructor
A new instance of AccessToken.
Constructor Details
#initialize(args = {}) ⇒ AccessToken
Returns a new instance of AccessToken.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dynamic_key/access_token.rb', line 20 def initialize args={} @app_id = args[:app_id] @channel_name = args.fetch(:channel_name, "") @app_certificate = args[:app_certificate] @uid = "#{args.fetch(:uid, "")}" @privileges = {} @privilege_expired_ts = args[:privilege_expired_ts] @salt = SecureRandom.rand(SEED) @expired_ts = Time.now.to_i + ONE_DAY end |
Instance Attribute Details
#app_certificate ⇒ Object
Returns the value of attribute app_certificate.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def app_certificate @app_certificate end |
#app_id ⇒ Object
Returns the value of attribute app_id.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def app_id @app_id end |
#channel_name ⇒ Object
Returns the value of attribute channel_name.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def channel_name @channel_name end |
#expired_ts ⇒ Object
Returns the value of attribute expired_ts.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def expired_ts @expired_ts end |
#privilege_expired_ts ⇒ Object
Returns the value of attribute privilege_expired_ts.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def privilege_expired_ts @privilege_expired_ts end |
#privileges ⇒ Object
Returns the value of attribute privileges.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def privileges @privileges end |
#salt ⇒ Object
Returns the value of attribute salt.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def salt @salt end |
#uid ⇒ Object
Returns the value of attribute uid.
16 17 18 |
# File 'lib/dynamic_key/access_token.rb', line 16 def uid @uid end |
Class Method Details
.generate!(payload = {}, &block) ⇒ Object
49 50 51 52 53 |
# File 'lib/dynamic_key/access_token.rb', line 49 def self.generate! payload={}, &block token = AccessToken.new payload block.call token token.build! end |
Instance Method Details
#add_privilege(privilege, ts) ⇒ Object Also known as: grant
31 32 33 |
# File 'lib/dynamic_key/access_token.rb', line 31 def add_privilege privilege, ts privileges[privilege] = ts end |
#build ⇒ Object
37 38 39 |
# File 'lib/dynamic_key/access_token.rb', line 37 def build Sign.encode self end |