class SelfSDK::Messages::AuthenticationReq

Constants

DEFAULT_EXP_TIMEOUT
MSG_TYPE

Public Class Methods

new(messaging) click to toggle source
Calls superclass method
# File lib/messages/authentication_req.rb, line 16
def initialize(messaging)
  @typ = MSG_TYPE
  super
end

Public Instance Methods

body() click to toggle source
# File lib/messages/authentication_req.rb, line 31
def body
  { typ: MSG_TYPE,
    iss: @jwt.id,
    sub: @to,
    aud: @to,
    iat: SelfSDK::Time.now.strftime('%FT%TZ'),
    exp: (SelfSDK::Time.now + @exp_timeout).strftime('%FT%TZ'),
    cid: @id,
    jti: SecureRandom.uuid }
end
populate(selfid, opts) click to toggle source
# File lib/messages/authentication_req.rb, line 21
def populate(selfid, opts)
  @id = SecureRandom.uuid
  @from = @client.jwt.id
  @to = selfid

  @id = opts[:cid] if opts.include?(:cid)
  @description = opts.include?(:description) ? opts[:description] : nil
  @exp_timeout = opts.fetch(:exp_timeout, DEFAULT_EXP_TIMEOUT)
end

Protected Instance Methods

proto(to_device) click to toggle source
# File lib/messages/authentication_req.rb, line 44
def proto(to_device)
  m = SelfMsg::Message.new
  m.id = SecureRandom.uuid
  m.sender = "#{@jwt.id}:#{@messaging.device_id}"
  m.recipient = "#{@to}:#{to_device}"
  m.ciphertext = encrypt_message(@jwt.prepare(body), @to, to_device)
  m
end