Class: Mach::Nonce

Inherits:
Object
  • Object
show all
Defined in:
lib/mach/nonce.rb

Class Method Summary collapse

Class Method Details

.exists?(credential_id, nonce_value) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/mach/nonce.rb', line 12

def exists?(credential_id, nonce_value)
  Mach.configuration.data_store.find_nonce_by(credential_id, nonce_value)
end

.for(timestamp) ⇒ Object



7
8
9
10
# File 'lib/mach/nonce.rb', line 7

def for(timestamp)
  #17 byte string to make sure we don't get any padding after base64
  Base64.urlsafe_encode64("#{SecureRandom.random_bytes(17)}#{timestamp}")
end

.persist(credential_id, nonce_value, timestamp) ⇒ Object



16
17
18
19
# File 'lib/mach/nonce.rb', line 16

def persist(credential_id, nonce_value, timestamp)
  expires_in = Mach.configuration.stale_request_window
  Mach.configuration.data_store.add_nonce(credential_id, nonce_value, expires_in)
end