nemid 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfaf481277e75ca6856da3dc36e6659565bb1d8e6c7b4b7e508cae97674c989a
4
- data.tar.gz: 9310faf0c65697c0ff198bf01a026d717086df156fe27f15e119ee81d45d12e6
3
+ metadata.gz: 95b10293863f4158913ea934b0dc172ebc7905b5b4eb6da36a74c8aa8e455426
4
+ data.tar.gz: 547a2a295d5ceecd5c4fc9b2e7da0f8ae80ba6df378931cf289fbd99f68c7529
5
5
  SHA512:
6
- metadata.gz: 9d9a69c8e17494a32537d6341084f27b5c9a2c3011756124235198c27ff3b8f7371b83b89ffd10a9fc51ea97ad874fb29b0b85009008da7cc07f43b1ba359500
7
- data.tar.gz: e5c36741e8853791830acf1e1a3e4ed29dcace861b0afdff211d589fd2a4c0e699ae3c04963c6b8242b8958c9d1d997518bc4b07df9a45a9fb4a4276556177ca
6
+ metadata.gz: b7169496ee383c4048c466ffd78373afc8cb4ce8a229981eba7e756b1d3dd8a1b863191e7cd6a26fc7a93c63c4302d0cb54207349431f1c13dc2dc6639d00864
7
+ data.tar.gz: 16998607eabdc65786b253f2f14caf1b616b288b8118935d6f62fd130047338e7bb3428c8a9df92c537cd36228773e5659d6f96bb6ff0edc5d66a395de43c14e
data/README.md CHANGED
@@ -18,6 +18,31 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install nemid
20
20
 
21
+ ## Configuration
22
+
23
+ This gem can be configured through the following block:
24
+
25
+ ```ruby
26
+ NemID.configure do |config|
27
+ # NemID has two URLs to call the PID-CPR service. The env configuration determines
28
+ # which should be used. Production URL (PR) is used when the value is 'production' or
29
+ # 'staging'. Other cases will use the pre-production (PP) URL.
30
+ # Defaults to rails environment (if defined), to RACK_ENV, or to 'development'
31
+ config.env = "production"
32
+
33
+ # Your OCES Certificate in PEM format.
34
+ config.oces_cert = "abc"
35
+
36
+ # Your Private Key in PEM format.
37
+ config.private_key = "def"
38
+
39
+ # Your SPID
40
+ config.spid = "ghi"
41
+ end
42
+ ```
43
+
44
+ Check the end of this readme to know how to get your OCES certificate and Private Key in PEM format.
45
+
21
46
  ## Usage
22
47
 
23
48
  This gem implements the following modules:
@@ -1,6 +1,7 @@
1
1
  require 'base64'
2
2
  require "nemid/version"
3
3
  require "nemid/authentication"
4
+ require "nemid/configuration"
4
5
  require "nemid/crypto"
5
6
  require "nemid/errors"
6
7
  require "nemid/ocsp"
@@ -8,5 +9,21 @@ require "nemid/xmldsig"
8
9
  require 'nemid/pid_cpr'
9
10
 
10
11
  module NemID
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def self.configure
21
+ yield(configuration)
22
+ end
23
+
24
+ def self.reset
25
+ @configuration = Configuration.new
26
+ end
27
+
11
28
  class Error < StandardError; end
12
29
  end
@@ -43,6 +43,7 @@ module NemID
43
43
  def unsigned_params
44
44
  {
45
45
  "CLIENTFLOW": "OCESLOGIN2",
46
+ "ENABLE_AWAITING_APP_APPROVAL_EVENT": "TRUE",
46
47
  "SP_CERT": sp_cert,
47
48
  "TIMESTAMP": DateTime.now.new_offset(0).strftime('%F %T%z'),
48
49
  }
@@ -0,0 +1,17 @@
1
+ module NemID
2
+ class Configuration
3
+ attr_accessor :env, :oces_cert, :private_key, :spid
4
+
5
+ def initialize
6
+ @env = default_for_env
7
+ @oces_cert = nil
8
+ @private_key = nil
9
+ @spid = nil
10
+ end
11
+
12
+ def default_for_env
13
+ return Rails.env.to_s if defined?(Rails.env)
14
+ ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
15
+ end
16
+ end
17
+ end
@@ -2,7 +2,6 @@ require 'savon'
2
2
 
3
3
  module NemID
4
4
  class PIDCPR
5
- PID_SERVICE_URL = 'https://pidws.pp.certifikat.dk/pid_serviceprovider_server/pidws'
6
5
 
7
6
  def initialize(cert:, key:, spid:)
8
7
  @crypto = NemID::Crypto.new(cert: cert, key: key)
@@ -46,11 +45,20 @@ module NemID
46
45
  }
47
46
  end
48
47
 
48
+ def pid_service_url
49
+ case NemID.configuration.env
50
+ when 'production', 'staging'
51
+ 'https://pidws.certifikat.dk/pid_serviceprovider_server/pidws/'
52
+ else
53
+ 'https://pidws.pp.certifikat.dk/pid_serviceprovider_server/pidws'
54
+ end
55
+ end
56
+
49
57
  def soap_client
50
58
  options = {
51
- :wsdl => "#{PID_SERVICE_URL}?WSDL",
59
+ :wsdl => "#{pid_service_url}?WSDL",
52
60
  :soap_version => 1,
53
- :endpoint => PID_SERVICE_URL,
61
+ :endpoint => pid_service_url,
54
62
  :convert_request_keys_to => :none,
55
63
  :ssl_cert => @crypto.get_certificate,
56
64
  :ssl_cert_key => @crypto.get_key,
@@ -1,3 +1,3 @@
1
1
  module NemID
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nemid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cabeza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2020-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl
@@ -92,6 +92,7 @@ files:
92
92
  - lib/nemid/authentication.rb
93
93
  - lib/nemid/authentication/params.rb
94
94
  - lib/nemid/authentication/response.rb
95
+ - lib/nemid/configuration.rb
95
96
  - lib/nemid/crypto.rb
96
97
  - lib/nemid/errors.rb
97
98
  - lib/nemid/errors/app.rb
@@ -132,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
133
  - !ruby/object:Gem::Version
133
134
  version: '0'
134
135
  requirements: []
135
- rubygems_version: 3.1.2
136
+ rubygems_version: 3.1.4
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: Ruby gem that makes it easy to integrate the NemID JavaScript client