Class: Stream::Signer
- Inherits:
-
Object
- Object
- Stream::Signer
- Defined in:
- lib/stream/signer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key) ⇒ Signer
constructor
A new instance of Signer.
- #sign(feed_slug, user_id) ⇒ Object
- #sign_message(message) ⇒ Object
- #urlsafe_encodeb64(value) ⇒ Object
Constructor Details
#initialize(key) ⇒ Signer
Returns a new instance of Signer.
8 9 10 11 |
# File 'lib/stream/signer.rb', line 8 def initialize(key) @key = key.to_s @sha1 = OpenSSL::Digest.new('sha1') end |
Class Method Details
.create_jwt_token(resource, action, api_secret, feed_id = nil, user_id = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/stream/signer.rb', line 27 def self.create_jwt_token(resource, action, api_secret, feed_id = nil, user_id = nil) payload = { resource: resource, action: action } payload['feed_id'] = feed_id if feed_id payload['user_id'] = user_id if user_id JWT.encode(payload, api_secret, 'HS256') end |
Instance Method Details
#sign(feed_slug, user_id) ⇒ Object
23 24 25 |
# File 'lib/stream/signer.rb', line 23 def sign(feed_slug, user_id) ("#{feed_slug}#{user_id}") end |
#sign_message(message) ⇒ Object
17 18 19 20 21 |
# File 'lib/stream/signer.rb', line 17 def () key = Digest::SHA1.digest @key.to_s token = Base64.strict_encode64(OpenSSL::HMAC.digest(@sha1, key, )) urlsafe_encodeb64(token) end |
#urlsafe_encodeb64(value) ⇒ Object
13 14 15 |
# File 'lib/stream/signer.rb', line 13 def urlsafe_encodeb64(value) value.tr('+', '-').tr('/', '_').gsub(/^=+/, '').gsub(/=+$/, '') end |