Class: OmniAuth::Yubikey::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth/yubikey/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(otp, response) ⇒ Result

Returns a new instance of Result.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/omniauth/yubikey/result.rb', line 9

def initialize(otp, response)
  @otp       = otp
  @id        = otp[0, otp.length-32] if otp.length > 32

  response.gsub!("\r\n", "\n")

  hashes     = response.scan(/^h=([\w_\=\/\+]+)$/)[0]
  statuses   = response.scan(/^status=([a-zA-Z0-9_]+)$/)[0]
  timestamps = response.scan(/^t=(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z(\d{4})$/)[0]

  @hash      = hashes[0] if hashes && hashes[0]
  @status    = statuses[0] if statuses && statuses[0]

  if timestamps
    parts = timestamps.map(&:to_i)
    @timestamp = Time.utc(*parts)
  end
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



7
8
9
# File 'lib/omniauth/yubikey/result.rb', line 7

def hash
  @hash
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/omniauth/yubikey/result.rb', line 7

def id
  @id
end

#infoObject (readonly)

Returns the value of attribute info.



7
8
9
# File 'lib/omniauth/yubikey/result.rb', line 7

def info
  @info
end

#otpObject (readonly)

Returns the value of attribute otp.



7
8
9
# File 'lib/omniauth/yubikey/result.rb', line 7

def otp
  @otp
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/omniauth/yubikey/result.rb', line 7

def status
  @status
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



7
8
9
# File 'lib/omniauth/yubikey/result.rb', line 7

def timestamp
  @timestamp
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/omniauth/yubikey/result.rb', line 28

def valid?
  status == "OK"
end