Class: Bankid::Secret

Inherits:
Object
  • Object
show all
Defined in:
lib/bankid/secret.rb

Constant Summary collapse

RESOLUTION =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(orderRef:, autoStartToken:, qrStartToken:, qrStartSecret:, created_at:) ⇒ Secret

Returns a new instance of Secret.



9
10
11
12
13
14
15
# File 'lib/bankid/secret.rb', line 9

def initialize(orderRef:, autoStartToken:, qrStartToken:, qrStartSecret:, created_at:)
  @order_ref = orderRef
  @auto_start_token = autoStartToken
  @qr_start_token = qrStartToken
  @qr_start_secret = qrStartSecret
  @created_at = created_at
end

Instance Attribute Details

#order_refObject (readonly)

Returns the value of attribute order_ref.



7
8
9
# File 'lib/bankid/secret.rb', line 7

def order_ref
  @order_ref
end

#resultObject (readonly)

Returns the value of attribute result.



7
8
9
# File 'lib/bankid/secret.rb', line 7

def result
  @result
end

Instance Method Details



17
18
19
20
21
22
23
# File 'lib/bankid/secret.rb', line 17

def autostart_link(return_url = nil)
  if return_url
    "https://app.bankid.com/?autostarttoken=#{@auto_start_token}&redirect=#{return_url}"
  else
    "https://app.bankid.com/?autostarttoken=#{@auto_start_token}"
  end
end


25
26
27
# File 'lib/bankid/secret.rb', line 25

def desktop_link(return_url)
  "bankid:///?autostarttoken=#{@auto_start_token}&redirect=#{CGI.escape(return_url)}"
end

#elapsed_secondsObject



29
30
31
# File 'lib/bankid/secret.rb', line 29

def elapsed_seconds
  ((Time.zone.now - @created_at).to_f / RESOLUTION).floor * RESOLUTION
end

#qr_codeObject



33
34
35
36
# File 'lib/bankid/secret.rb', line 33

def qr_code
  auth_code = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("SHA256"), @qr_start_secret, elapsed_seconds.to_s)
  RQRCode::QRCode.new("bankid.#{@qr_start_token}.#{elapsed_seconds}.#{auth_code}")
end