Skip to content

Commit

Permalink
Helper looks solid, notification to do
Browse files Browse the repository at this point in the history
  • Loading branch information
Epigene committed Sep 24, 2015
1 parent 01230d6 commit 695f26a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<AuthSystem>.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
Expand Down
5 changes: 3 additions & 2 deletions lib/sacps/auth/draugiem_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/sacps/auth/draugiem_id/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion lib/sacps/auth/draugiem_id/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/auth/helpers/sacps_auth_draugiem_id_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/config.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 695f26a

Please sign in to comment.