Module: Currentuser::Services
- Includes:
- GemConfig::Base
- Defined in:
- lib/currentuser/services.rb,
lib/currentuser/services/engine.rb,
lib/currentuser/services/controllers/authenticates.rb
Defined Under Namespace
Modules: Authenticates
Classes: Engine
Constant Summary
collapse
- Error =
Class.new(StandardError)
- TimestampTooOld =
Class.new(Error)
- SignatureNotAuthentic =
Class.new(Error)
Class Method Summary
collapse
Class Method Details
.check_authentication_params!(params) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/currentuser/services/controllers/authenticates.rb', line 30
def self.check_authentication_params!(params)
raise unless params[:currentuser_id] && params[:timestamp] && params[:signature]
unless timestamp_recent?(params[:timestamp].to_i)
raise TimestampTooOld, 'Timestamp is more than 10 minutes old'
end
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) ⇒ Object
45
46
47
|
# 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) ⇒ Object
49
50
51
52
53
54
|
# 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) ⇒ Boolean
64
65
66
67
|
# 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) ⇒ Boolean
60
61
62
|
# File 'lib/currentuser/services/controllers/authenticates.rb', line 60
def self.timestamp_recent?(timestamp)
return (Time.now - Time.at(timestamp)).abs < 10 * 60
end
|