Class: Masks::Credentials::Device

Inherits:
Masks::Credential show all
Defined in:
app/models/masks/credentials/device.rb

Overview

Checks for a known, valid :device.

If the device is not associated with the session’s actor, it will be. Identification is based on the user_agent and a few other facets.

Instance Method Summary collapse

Methods inherited from Masks::Credential

#backup!, #check, checks, #cleanup!, #mask!, #name, #patch_params, #slug

Instance Method Details

#backupObject



47
48
49
# File 'app/models/masks/credentials/device.rb', line 47

def backup
  session.extra(:device)&.touch(:accessed_at) if session&.passed?
end

#cleanupObject



51
52
53
54
55
56
# File 'app/models/masks/credentials/device.rb', line 51

def cleanup
  device = session.extra(:device)
  device&.reset_version

  session.data[:device_key] = nil
end

#lookupObject



12
13
14
15
16
17
18
19
20
# File 'app/models/masks/credentials/device.rb', line 12

def lookup
  return unless actor

  device = config.find_device(session, actor:)

  session.extras(device:)

  nil
end

#maskupObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/masks/credentials/device.rb', line 22

def maskup
  device = session.extra(:device)

  return deny! unless device

  session_key = session.data[:device_key]

  # ensure devices match across sessions, which would only happen if a
  # session cookie happened is shared across machines. this destroys
  # the entire session and cleans up everything involved.
  if session_key && device.session_key != session_key
    raise "invalid device"
  end

  # store devices that are found in a database of known devices
  if device.known?
    session.data[:device_key] = device.session_key
    actor.devices << device
    approve!
  else
    cleanup
    deny!
  end
end