Class: SelfSDK::Messages::AuthenticationReq

Inherits:
AuthenticationMessage show all
Defined in:
lib/messages/authentication_req.rb

Constant Summary collapse

MSG_TYPE =
"identities.authenticate.req"
DEFAULT_EXP_TIMEOUT =
300

Instance Attribute Summary

Attributes inherited from Base

#description, #exp_timeout, #expires, #fields, #from, #from_device, #id, #input, #intermediary, #payload, #status, #sub, #to, #to_device, #typ

Instance Method Summary collapse

Methods inherited from AuthenticationMessage

#parse

Methods inherited from Base

#accepted?, #encrypt_message, #errored?, #rejected?, #request, #send_message, #unauthorized?, #validate!

Constructor Details

#initialize(messaging) ⇒ AuthenticationReq

Returns a new instance of AuthenticationReq.

[View source]

15
16
17
18
# File 'lib/messages/authentication_req.rb', line 15

def initialize(messaging)
  @typ = MSG_TYPE
  super
end

Instance Method Details

#bodyObject

[View source]

30
31
32
33
34
35
36
37
38
39
# File 'lib/messages/authentication_req.rb', line 30

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) ⇒ Object

[View source]

20
21
22
23
24
25
26
27
28
# File 'lib/messages/authentication_req.rb', line 20

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