Class: MixinBot::BotAuth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mixin_bot/bot_auth.rb

Constant Summary collapse

PLATFORM_PREFIX =
'up_'

Instance Method Summary collapse

Constructor Details

#initialize(api, cache: MapCache.new) ⇒ Client

Returns a new instance of Client.



27
28
29
30
# File 'lib/mixin_bot/bot_auth.rb', line 27

def initialize(api, cache: MapCache.new)
  @api = api
  @cache = cache
end

Instance Method Details

#sign_request(timestamp, bot_user_id, method, uri, body = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/mixin_bot/bot_auth.rb', line 32

def sign_request(timestamp, bot_user_id, method, uri, body = nil)
  shared_key = shared_key_for(bot_user_id)
  data = "#{timestamp}#{method}#{uri}"
  data += body.to_s if body.present?
  digest = OpenSSL::HMAC.digest('SHA256', shared_key, data)
  Base64.urlsafe_encode64(@api.config.app_id.b + digest, padding: false)
end