module Currentuser::Services

Constants

Error
SignatureNotAuthentic
TimestampTooOld

Public Class Methods

check_authentication_params!(params) click to toggle source
# File lib/currentuser/services/controllers/authenticates.rb, line 30
def self.check_authentication_params!(params)
  raise unless params[:currentuser_id] && params[:timestamp] && params[:signature]

  # Check timestamp
  unless timestamp_recent?(params[:timestamp].to_i)
    raise TimestampTooOld, 'Timestamp is more than 10 minutes old'
  end

  # Check signature
  auth_string = [params[:currentuser_id], params[:timestamp]].join
  unless signature_authentic?(params[:signature], auth_string)
    raise SignatureNotAuthentic, 'Signature verification failed'
  end
end
currentuser_url(action) click to toggle source
# File lib/currentuser/services/controllers/authenticates.rb, line 45
def self.currentuser_url(action)
  return currentuser_url_for_project_id(configuration.project_id, action)
end
currentuser_url_for_project_id(project_id, action) click to toggle source
# File lib/currentuser/services/controllers/authenticates.rb, line 49
def self.currentuser_url_for_project_id(project_id, action)
  host = configuration.currentuser_services_host
  raise 'project_id should be set'  unless project_id
  raise 'action should be :sign_up or :sign_in'  unless action.in?([:sign_up, :sign_in])
  return "#{host}/#{project_id}/#{action}"
end
signature_authentic?(signature, auth_string) click to toggle source
# File lib/currentuser/services/controllers/authenticates.rb, line 64
def self.signature_authentic?(signature, auth_string)
  public_key = Services.configuration.currentuser_services_public_key
  return EncryptoSigno.verify(public_key, signature, auth_string)
end
timestamp_recent?(timestamp) click to toggle source
# File lib/currentuser/services/controllers/authenticates.rb, line 60
def self.timestamp_recent?(timestamp)
  return (Time.now - Time.at(timestamp)).abs < 10 * 60
end