diff --git a/README.md b/README.md index ae23583..0cade8e 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,29 @@ Start by creating .env file in root and defining some environmental variables. When ready, do `rspec` to run the test suite. +## Standarts +Authentification system functionalities are packed in two namespaces - `helper` and `notification` + +#### Helper +Does everything leading up to sending the request to remote service. +Usually this means request url and data setup + +#### Notification +Does everything after receiving response from remote service. +Usually there is a create controller action where notification object is instatiated: + +```ruby +notification = SacPS::Auth::.notification(params[:some_param]) +create_and_or_login_user notification +``` + +Notification object _must_ define `user_identifier` and `user_name` as a minimum. + +```ruby +notification.user_identifier #=> "311299-11111" +notification.user_name #=> "Askolds Buksis" +``` + ### Swedbank usage 1. Configure defaults diff --git a/lib/sacps/auth/draugiem_id.rb b/lib/sacps/auth/draugiem_id.rb index 1ccc1f3..0a7e7af 100644 --- a/lib/sacps/auth/draugiem_id.rb +++ b/lib/sacps/auth/draugiem_id.rb @@ -4,16 +4,17 @@ module SacPS module Auth module DraugiemId - mattr_accessor :app_id, :return_url + mattr_accessor :app_id, :app_key, :return_url, :api_url def self.set_default_values - # SacPS::Auth::DraugiemId.app_id ||= "1" + SacPS::Auth::DraugiemId.api_url ||= "http://api.draugiem.lv/json" end def self.validate_config! self.set_default_values message = [] message << "No app_id!" if SacPS::Auth::DraugiemId.app_id.blank? + message << "No app_key!" if SacPS::Auth::DraugiemId.app_key.blank? message << "No return_url!" if SacPS::Auth::DraugiemId.return_url.blank? raise "DraugiemId init contains blank values, review README. Errors:\n#{message.join("\n")}" if message.any? diff --git a/lib/sacps/auth/draugiem_id/helper.rb b/lib/sacps/auth/draugiem_id/helper.rb index e913f0c..6b6d271 100644 --- a/lib/sacps/auth/draugiem_id/helper.rb +++ b/lib/sacps/auth/draugiem_id/helper.rb @@ -17,7 +17,7 @@ def build_authentication_url end def build_control_code - Digest::MD5.hexdigest("#{SacPS::Auth::DraugiemId.app_id}#{SacPS::Auth::DraugiemId.return_url}") + Digest::MD5.hexdigest("#{SacPS::Auth::DraugiemId.app_key}#{SacPS::Auth::DraugiemId.return_url}") end end diff --git a/lib/sacps/auth/draugiem_id/notification.rb b/lib/sacps/auth/draugiem_id/notification.rb index 3c0105a..05eb8e1 100644 --- a/lib/sacps/auth/draugiem_id/notification.rb +++ b/lib/sacps/auth/draugiem_id/notification.rb @@ -2,7 +2,22 @@ module SacPS module Auth module DraugiemId class Notification - attr_reader :fields + attr_accessor :user_identifier, :user_name + + def initialize(dr_auth_code) + SacPS::Auth::DraugiemId.validate_config! + authorize! + request_user_data! + end + + def authorize! + + end + + def request_user_data! + + end + end end diff --git a/spec/auth/helpers/sacps_auth_draugiem_id_helper_spec.rb b/spec/auth/helpers/sacps_auth_draugiem_id_helper_spec.rb index d063a12..96d485d 100644 --- a/spec/auth/helpers/sacps_auth_draugiem_id_helper_spec.rb +++ b/spec/auth/helpers/sacps_auth_draugiem_id_helper_spec.rb @@ -9,6 +9,7 @@ describe "initialization" do it "should have @authentication_url" do + # pr @helper.authentication_url expect(@helper.authentication_url.present?).to eq true end end diff --git a/spec/config.rb b/spec/config.rb index 9dbb36e..a41947f 100644 --- a/spec/config.rb +++ b/spec/config.rb @@ -1,4 +1,5 @@ -SacPS::Auth::DraugiemId.app_id = '7c437d28be62b492151788f6c827afd6' +SacPS::Auth::DraugiemId.app_id = '15019482' +SacPS::Auth::DraugiemId.app_key = 'a84e9ab56ab161f1dbe323c457c8c87a' SacPS::Auth::DraugiemId.return_url = 'http://example.com/draugiem_auth/' SacPS::Auth::Swedbank.identifier = 'ACC1'