omniauth-polaris 1.0.5 → 1.1.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
- SHA1:
3
- metadata.gz: 854ec536ec951da3a404a8fb0cff3afa47f4b2e1
4
- data.tar.gz: f275bc49cc3cf0798fb624e9a68eeda2766bb43a
2
+ SHA256:
3
+ metadata.gz: cdc6774680ba017d52076ea0e48f91c64c639398d68a6efc378e15f176cf7c41
4
+ data.tar.gz: ac1c47675fb06db77a9e889aaa905fe8dbc5b8ff493b95e7a2ce58fbe3c2b471
5
5
  SHA512:
6
- metadata.gz: 193cc616630ee2455da017cdb4dfedcbb560fa80aa5c4e5b4e6f2bf421c3575b4040a9f4082f893a66377ca68f145b6590e3e04b7f4511f2142d9b77b7c465df
7
- data.tar.gz: d83f04c7c4aff9a7af297661839eb869a4b924da6553b72ce02ce28d0095b4611d976cd89aa865f53d992134dbec970ab0b9f01fcc8eb6c050608b3c32b944b6
6
+ metadata.gz: 90668f491c693ed44cba53bb920e36f05b394d96e103b1f54dd1a55ef1dff87d090af930c01910a78d705083777613190e64542800c1f4a942290b4933b3d1e7
7
+ data.tar.gz: 02a9cf3dc5b6ab29db564ed28c63ac616b93572ea2ba4df72c388b5b9937bf535d1aebfe6d169154d563ac917121efb8cae87594bd89a7ed04a285a1e69b5540
data/.gitignore CHANGED
@@ -50,14 +50,14 @@ Icon?
50
50
  ehthumbs.db
51
51
  .idea # Rubymine config files
52
52
  /.idea/*
53
-
53
+ .ruby-version
54
54
  # Directories to ignore #
55
55
  #########################
56
56
  /public/data/*
57
57
  /jetty/*
58
58
  /solr_conf/*
59
59
  /fedora_conf/*
60
-
60
+ scratch.rb
61
61
  # Ignore edited Linux files #
62
62
  #############################
63
63
 
data/.rubocop.yml CHANGED
@@ -1 +1,25 @@
1
- require: rubocop-rspec
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
4
+ # configuration file. It makes it possible to enable/disable
5
+ # certain cops (checks) and to alter their behavior if they accept
6
+ # any parameters. The file can be placed either in your home
7
+ # directory or in some project directory.
8
+ #
9
+ # RuboCop will start looking for the configuration file in the directory
10
+ # where the inspected file is and continue its way up to the root directory.
11
+ #
12
+ # See https://docs.rubocop.org/rubocop/configuration
13
+
14
+ AllCops:
15
+ TargetRubyVersion: 2.7
16
+ NewCops: enable
17
+ Exclude:
18
+ - 'scratch.rb'
19
+
20
+ Gemspec/RequireMFA:
21
+ Enabled: false
22
+
23
+ RSpec/MultipleExpectations:
24
+ Enabled: true
25
+ Max: 5
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,300 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2023-01-11 17:46:34 UTC using RuboCop version 1.32.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ # This cop supports safe autocorrection (--autocorrect).
11
+ # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
12
+ # Include: **/*.gemfile, **/Gemfile, **/gems.rb
13
+ Bundler/OrderedGems:
14
+ Enabled: true
15
+
16
+ # Offense count: 2
17
+ # This cop supports safe autocorrection (--autocorrect).
18
+ # Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
19
+ # Include: **/*.gemspec
20
+ Gemspec/OrderedDependencies:
21
+ Enabled: true
22
+
23
+ # Offense count: 1
24
+ # Configuration parameters: Include.
25
+ # Include: **/*.gemspec
26
+ Gemspec/RequiredRubyVersion:
27
+ Exclude:
28
+ - 'omniauth-polaris.gemspec'
29
+
30
+ # Offense count: 2
31
+ # This cop supports safe autocorrection (--autocorrect).
32
+ Layout/EmptyLines:
33
+ Enabled: true
34
+ # Offense count: 1
35
+ # This cop supports safe autocorrection (--autocorrect).
36
+ # Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
37
+ Layout/ExtraSpacing:
38
+ Enabled: true
39
+ # Offense count: 2
40
+ # This cop supports safe autocorrection (--autocorrect).
41
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
42
+ # SupportedStyles: special_inside_parentheses, consistent, align_braces
43
+ Layout/FirstHashElementIndentation:
44
+ Enabled: true
45
+
46
+ # Offense count: 1
47
+ # This cop supports safe autocorrection (--autocorrect).
48
+ # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
49
+ # SupportedHashRocketStyles: key, separator, table
50
+ # SupportedColonStyles: key, separator, table
51
+ # SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
52
+ Layout/HashAlignment:
53
+ Enabled: true
54
+
55
+ # Offense count: 3
56
+ # This cop supports safe autocorrection (--autocorrect).
57
+ # Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment.
58
+ Layout/LeadingCommentSpace:
59
+ Enabled: true
60
+
61
+ # Offense count: 1
62
+ # This cop supports safe autocorrection (--autocorrect).
63
+ Layout/LeadingEmptyLines:
64
+ Enabled: true
65
+
66
+ # Offense count: 1
67
+ # This cop supports safe autocorrection (--autocorrect).
68
+ Layout/SpaceAfterComma:
69
+ Enabled: true
70
+
71
+ # Offense count: 2
72
+ # This cop supports safe autocorrection (--autocorrect).
73
+ # Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
74
+ # SupportedStylesForExponentOperator: space, no_space
75
+ Layout/SpaceAroundOperators:
76
+ Enabled: true
77
+
78
+ # Offense count: 3
79
+ # This cop supports safe autocorrection (--autocorrect).
80
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
81
+ # SupportedStyles: space, no_space
82
+ # SupportedStylesForEmptyBraces: space, no_space
83
+ Layout/SpaceBeforeBlockBraces:
84
+ Enabled: true
85
+
86
+ # Offense count: 1
87
+ # This cop supports safe autocorrection (--autocorrect).
88
+ Layout/SpaceBeforeComma:
89
+ Enabled: true
90
+
91
+ # Offense count: 4
92
+ # This cop supports safe autocorrection (--autocorrect).
93
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
94
+ # SupportedStyles: space, no_space
95
+ # SupportedStylesForEmptyBraces: space, no_space
96
+ Layout/SpaceInsideBlockBraces:
97
+ Enabled: true
98
+
99
+ # Offense count: 6
100
+ # This cop supports safe autocorrection (--autocorrect).
101
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
102
+ # SupportedStyles: space, no_space, compact
103
+ # SupportedStylesForEmptyBraces: space, no_space
104
+ Layout/SpaceInsideHashLiteralBraces:
105
+ Enabled: true
106
+
107
+ # Offense count: 1
108
+ # This cop supports safe autocorrection (--autocorrect).
109
+ # Configuration parameters: EnforcedStyle.
110
+ # SupportedStyles: space, compact, no_space
111
+ Layout/SpaceInsideParens:
112
+ Enabled: true
113
+
114
+ # Offense count: 1
115
+ Lint/RescueException:
116
+ Enabled: true
117
+
118
+ # Offense count: 1
119
+ # This cop supports safe autocorrection (--autocorrect).
120
+ Lint/ScriptPermission:
121
+ Enabled: true
122
+
123
+ # Offense count: 1
124
+ # This cop supports safe autocorrection (--autocorrect).
125
+ # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
126
+ Lint/UselessAccessModifier:
127
+ Enabled: true
128
+
129
+ # Offense count: 2
130
+ Lint/UselessAssignment:
131
+ Enabled: true
132
+
133
+ # Offense count: 3
134
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
135
+ Metrics/AbcSize:
136
+ Max: 39
137
+
138
+ # Offense count: 2
139
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
140
+ # IgnoredMethods: refine
141
+ Metrics/BlockLength:
142
+ Max: 63
143
+
144
+ # Offense count: 1
145
+ # Configuration parameters: IgnoredMethods.
146
+ Metrics/CyclomaticComplexity:
147
+ Max: 15
148
+
149
+ # Offense count: 3
150
+ # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
151
+ Metrics/MethodLength:
152
+ Max: 20
153
+
154
+ # Offense count: 1
155
+ # Configuration parameters: IgnoredMethods.
156
+ Metrics/PerceivedComplexity:
157
+ Max: 13
158
+
159
+ # Offense count: 1
160
+ # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
161
+ # CheckDefinitionPathHierarchyRoots: lib, spec, test, src
162
+ # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
163
+ Naming/FileName:
164
+ Exclude:
165
+ - 'lib/omniauth-polaris.rb'
166
+
167
+ # Offense count: 2
168
+ # Configuration parameters: AllowedConstants.
169
+ Style/Documentation:
170
+ Exclude:
171
+ - 'spec/**/*'
172
+ - 'test/**/*'
173
+ - 'lib/omniauth/polaris/adaptor.rb'
174
+ - 'lib/omniauth/strategies/polaris.rb'
175
+
176
+ # Offense count: 2
177
+ # This cop supports safe autocorrection (--autocorrect).
178
+ # Configuration parameters: EnforcedStyle.
179
+ # SupportedStyles: compact, expanded
180
+ Style/EmptyMethod:
181
+ Enabled: true
182
+ # Offense count: 1
183
+ # This cop supports safe autocorrection (--autocorrect).
184
+ Style/Encoding:
185
+ Enabled: true
186
+
187
+ # Offense count: 3
188
+ # This cop supports safe autocorrection (--autocorrect).
189
+ Style/ExpandPathArguments:
190
+ Enabled: true
191
+
192
+ # Offense count: 1
193
+ # This cop supports safe autocorrection (--autocorrect).
194
+ # Configuration parameters: EnforcedStyle.
195
+ # SupportedStyles: format, sprintf, percent
196
+ Style/FormatString:
197
+ Enabled: true
198
+
199
+ # Offense count: 1
200
+ # This cop supports unsafe autocorrection (--autocorrect-all).
201
+ # Configuration parameters: EnforcedStyle.
202
+ # SupportedStyles: always, always_true, never
203
+ Style/FrozenStringLiteralComment:
204
+ Enabled: true
205
+
206
+ # Offense count: 23
207
+ # This cop supports safe autocorrection (--autocorrect).
208
+ # Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
209
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
210
+ # SupportedShorthandSyntax: always, never, either
211
+ Style/HashSyntax:
212
+ Enabled: true
213
+
214
+ # Offense count: 1
215
+ # This cop supports safe autocorrection (--autocorrect).
216
+ # Configuration parameters: EnforcedStyle.
217
+ # SupportedStyles: both, prefix, postfix
218
+ Style/NegatedIf:
219
+ Enabled: true
220
+
221
+ # Offense count: 3
222
+ # This cop supports safe autocorrection (--autocorrect).
223
+ # Configuration parameters: PreferredDelimiters.
224
+ Style/PercentLiteralDelimiters:
225
+ Enabled: true
226
+
227
+ # Offense count: 2
228
+ # This cop supports safe autocorrection (--autocorrect).
229
+ # Configuration parameters: EnforcedStyle, AllowedCompactTypes.
230
+ # SupportedStyles: compact, exploded
231
+ Style/RaiseArgs:
232
+ Enabled: true
233
+
234
+ # Offense count: 2
235
+ # This cop supports unsafe autocorrection (--autocorrect-all).
236
+ Style/RedundantInterpolation:
237
+ Enabled: true
238
+
239
+ # Offense count: 2
240
+ # This cop supports safe autocorrection (--autocorrect).
241
+ Style/RedundantPercentQ:
242
+ Enabled: true
243
+
244
+ # Offense count: 1
245
+ # This cop supports safe autocorrection (--autocorrect).
246
+ # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
247
+ # SupportedStyles: slashes, percent_r, mixed
248
+ Style/RegexpLiteral:
249
+ Enabled: true
250
+ # Offense count: 5
251
+ # This cop supports safe autocorrection (--autocorrect).
252
+ # Configuration parameters: AllowAsExpressionSeparator.
253
+ Style/Semicolon:
254
+ Enabled: true
255
+
256
+ # Offense count: 3
257
+ # This cop supports unsafe autocorrection (--autocorrect-all).
258
+ # Configuration parameters: RequireEnglish.
259
+ # SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
260
+ Style/SpecialGlobalVars:
261
+ EnforcedStyle: use_perl_names
262
+
263
+ # Offense count: 1
264
+ # This cop supports safe autocorrection (--autocorrect).
265
+ Style/StderrPuts:
266
+ Enabled: true
267
+
268
+ # Offense count: 1
269
+ # This cop supports unsafe autocorrection (--autocorrect-all).
270
+ # Configuration parameters: Mode.
271
+ Style/StringConcatenation:
272
+ Enabled: true
273
+
274
+ # Offense count: 7
275
+ # This cop supports safe autocorrection (--autocorrect).
276
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
277
+ # SupportedStyles: single_quotes, double_quotes
278
+ Style/StringLiterals:
279
+ Enabled: true
280
+ # Offense count: 1
281
+ # This cop supports safe autocorrection (--autocorrect).
282
+ # Configuration parameters: .
283
+ # SupportedStyles: percent, brackets
284
+ Style/SymbolArray:
285
+ EnforcedStyle: percent
286
+ MinSize: 3
287
+
288
+ # Offense count: 1
289
+ # This cop supports unsafe autocorrection (--autocorrect-all).
290
+ # Configuration parameters: AllowMethodsWithArguments, IgnoredMethods, AllowComments.
291
+ # IgnoredMethods: respond_to, define_method
292
+ Style/SymbolProc:
293
+ Enabled: true
294
+
295
+ # Offense count: 16
296
+ # This cop supports safe autocorrection (--autocorrect).
297
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
298
+ # URISchemes: http, https
299
+ Layout/LineLength:
300
+ Max: 256
data/Gemfile CHANGED
@@ -1,13 +1,14 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
2
 
3
+ source 'https://rubygems.org'
3
4
 
4
- gem "rubocop", ">= 0.47", require: false
5
+ gem 'rubocop', '~> 1.31', require: false
6
+ gem 'rubocop-performance', '~> 1.15', require: false
7
+ gem 'rubocop-rspec', '~> 2.12', require: false
5
8
 
6
- #TODO create a coveralls repo token for this
7
9
  gemspec
8
10
 
9
11
  group :test do
12
+ gem 'rack-test'
10
13
  gem 'simplecov', require: false
11
- gem 'rubocop-rspec', require: false
12
- gem 'rack-test', '~> 1.1.0'
13
14
  end
data/Rakefile CHANGED
@@ -1,8 +1,21 @@
1
- #!/usr/bin/env rake
2
- # Add your own tasks in files placed in lib/tasks ending in .rake,
3
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
1
+ # frozen_string_literal: true
4
2
 
5
- unless Dir[File.expand_path('../config/application', __FILE__)].empty?
6
- require File.expand_path('../config/application', __FILE__)
7
- OmniauthPolaris::Application.load_tasks
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ begin
9
+ require 'rubocop/rake_task'
10
+ RuboCop::RakeTask.new(:rubocop) do |task|
11
+ task.requires << 'rubocop-rspec'
12
+ task.requires << 'rubocop-performance'
13
+ task.fail_on_error = true
14
+ end
15
+ rescue LoadError
16
+ task :rubocop do
17
+ warn 'Rubocop is disabled'
18
+ end
8
19
  end
20
+
21
+ task default: [:rubocop, :spec]
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'pry'
7
+ require 'omniauth-polaris'
8
+
9
+ Pry.start
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Polaris
5
+ class Adaptor
6
+ REQUIRED_ADAPTER_CONFIG_KEYS = %i[access_id access_key method http_uri].freeze
7
+ BASIC_USER_DATA_KEYS = %w[NameFirst NameLast NameMiddle PhoneNumber EmailAddress].freeze
8
+ METHOD = { POST: :GET }.freeze
9
+
10
+ attr_reader :config
11
+
12
+ def self.validate!(configuration = {})
13
+ message = REQUIRED_ADAPTER_CONFIG_KEYS.each_with_object([]) do |name, msg|
14
+ next msg if configuration[name].present?
15
+
16
+ msg << name
17
+ end
18
+
19
+ raise Polaris::ConfigurationError, "#{message.join(' ,')} MUST be provided" unless message.blank?
20
+ end
21
+
22
+ def initialize(configuration = {})
23
+ self.class.validate!(configuration)
24
+
25
+ @configuration = configuration.dup
26
+
27
+ @logger = @configuration.delete(:logger)
28
+
29
+ REQUIRED_ADAPTER_CONFIG_KEYS.each do |name|
30
+ instance_variable_set("@#{name}", @configuration[name])
31
+ end
32
+
33
+ @config = {
34
+ http_uri: @http_uri,
35
+ method: @method,
36
+ access_key: @access_key,
37
+ access_id: @access_id
38
+ }
39
+
40
+ ensure_method!(@method)
41
+ @polaris_method = METHOD[@method]
42
+ end
43
+
44
+ def authenticate_patron(pin:, barcode:)
45
+ # According to the polaris api docs "Date must be within +/- 30 minutes of current time or request will fail"
46
+ http_date = 15.minutes.from_now.in_time_zone('GMT').strftime('%a, %d %b %Y %H:%M:%S %Z')
47
+
48
+ # Authorization hash component
49
+ authorization_hash = authorization_response(pin, barcode, http_date)
50
+
51
+ return if authorization_hash.blank?
52
+
53
+ # Details hash component
54
+ details_hash = details_response(pin, barcode, http_date)
55
+
56
+ return if details_hash.blank? || details_hash.dig('PatronBasicDataGetResult', 'PatronBasicData').blank?
57
+
58
+ patron_user_hash = authorization_hash['PatronValidateResult'].dup
59
+
60
+ patron_user_hash.merge(details_hash.dig('PatronBasicDataGetResult', 'PatronBasicData').slice(*BASIC_USER_DATA_KEYS))
61
+ end
62
+
63
+ protected
64
+
65
+ def authorization_response(pin, barcode, request_date)
66
+ patron_validate_uri = "#{@http_uri}/patron/#{barcode}"
67
+ validation_concated_string = "#{@polaris_method}#{patron_validate_uri}#{request_date}#{pin}"
68
+ polaris_get_xml_response(patron_validate_uri, request_date, validation_concated_string)
69
+ end
70
+
71
+ def details_response(pin, barcode, request_date)
72
+ patron_basic_data_uri = "#{@http_uri}#{barcode}/basicdata"
73
+ details_concated_string = "#{@polaris_method}#{http_basic_data_uri}#{request_date}#{pin}"
74
+ polaris_get_xml_response(patron_basic_data_uri, request_date, details_concated_string)
75
+ end
76
+
77
+ private
78
+
79
+ def polaris_request_headers(request_date, concated_string)
80
+ { 'Date' => request_date, 'Authorization' => "PWS #{@access_id}:#{sha1_sig(concated_string)}" }
81
+ end
82
+
83
+ def polaris_get_xml_response(uri, request_date, concated_string)
84
+ xml_response = HTTP.get(uri, headers: polaris_request_headers(request_date, concated_string))
85
+
86
+ return {} unless xml_response.status.success?
87
+
88
+ Hash.from_xml(xml_response.body.to_s)
89
+ rescue HTTP::Error, OpenSSL::SSL::SSLError => e
90
+ raise Polaris::ConnectionError, "Could not connect to polaris due to the following error\n #{e.class.name}: #{e.message}"
91
+ end
92
+
93
+ def sha1_sig(concated_string)
94
+ Base64.strict_encode64(OpenSSL::HMAC.digest('sha1', @access_key, concated_string).to_s)
95
+ end
96
+
97
+ def ensure_method!(method = 'post')
98
+ normalized_method = method.to_s.upcase.to_sym
99
+
100
+ return normalized_method if METHOD.key?(normalized_method)
101
+
102
+ available_methods = METHOD.keys.collect(&:inspect).join(', ')
103
+
104
+ raise Polaris::ConfigurationError, "#{method} is not one of the available connect methods: #{available_methods}"
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Polaris
5
+ VERSION = '1.1.0'
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext/object/blank'
5
+ require 'active_support/core_ext/time'
6
+ require 'active_support/core_ext/integer/time'
7
+ require 'active_support/core_ext/hash/conversions'
8
+ require 'base64'
9
+ require 'cgi'
10
+ require 'openssl'
11
+ require 'http'
12
+ require 'omniauth'
13
+ require 'omniauth/strategies/polaris'
14
+
15
+ module OmniAuth
16
+ module Polaris
17
+ class PolarisError < StandardError; end
18
+ class ConfigurationError < StandardError; end
19
+ class AuthenticationError < StandardError; end
20
+ class ConnectionError < StandardError; end
21
+ end
22
+ end
23
+
24
+ require 'omniauth/polaris/adaptor'
@@ -1,108 +1,76 @@
1
- require 'omniauth' unless defined? OmniAuth
1
+ # frozen_string_literal: true
2
2
 
3
3
  module OmniAuth
4
4
  module Strategies
5
5
  class Polaris
6
6
  class MissingCredentialsError < StandardError; end
7
+ class InvalidCredentialsError < StandardError; end
8
+
7
9
  include OmniAuth::Strategy
8
- @@config = {
9
- 'barcode' => 'barcode',
10
- 'valid_patron' => 'ValidPatron',
11
- 'patron_id' => 'PatronID',
12
- 'assigned_branch_id' => 'AssignedBranchID',
13
- 'assigned_branch_name' => 'AssignedBranchName',
14
- 'first_name' => 'NameFirst',
15
- 'last_name' => 'NameLast',
16
- 'middle_name' => 'NameMiddle',
17
- 'phone_number' => 'PhoneNumber',
18
- 'email' => 'EmailAddress'
19
- }
20
- option :title, "Polaris Authentication" #default title for authentication form
21
10
 
11
+ USER_MAP = {
12
+ 'barcode' => 'Barcode',
13
+ 'valid_patron' => 'ValidPatron',
14
+ 'patron_id' => 'PatronID',
15
+ 'assigned_branch_id' => 'AssignedBranchID',
16
+ 'assigned_branch_name' => 'AssignedBranchName',
17
+ 'first_name' => 'NameFirst',
18
+ 'last_name' => 'NameLast',
19
+ 'middle_name' => 'NameMiddle',
20
+ 'phone_number' => 'PhoneNumber',
21
+ 'email' => 'EmailAddress'
22
+ }.freeze
23
+
24
+ def self.map_user(polaris_user_info)
25
+ USER_MAP.each_with_object({}) do |(user_key, polaris_user_key), user_hash|
26
+ user_hash[user_key.to_sym] = polaris_user_info[polaris_user_key] if polaris_user_info[polaris_user_key].present?
27
+ end
28
+ end
29
+
30
+ option :title, 'Polaris Authentication' # default title for authentication form
22
31
 
23
32
  def request_phase
24
- OmniAuth::Polaris::Adaptor.validate @options
25
- f = OmniAuth::Form.new(:title => (options[:title] || "Polaris Authentication"), :url => callback_path)
26
- f.text_field 'Barcode', 'barcode'
27
- f.password_field 'PIN', 'pin'
28
- f.button "Sign In"
29
- f.to_response
33
+ OmniAuth::Polaris::Adaptor.validate!(@options)
34
+
35
+ OmniAuth::Form.build(title: options.fetch(:title, 'Polaris Authentication'), url: callback_path) do |f|
36
+ f.text_field 'Barcode', 'barcode'
37
+ f.password_field 'PIN', 'pin'
38
+ f.button 'Sign In'
39
+ end.to_response
30
40
  end
31
41
 
42
+ # rubocop:disable Style/SignalException
32
43
  def callback_phase
33
- @adaptor = OmniAuth::Polaris::Adaptor.new @options
44
+ @adaptor = OmniAuth::Polaris::Adaptor.new(@options)
34
45
 
35
- raise MissingCredentialsError.new("Missing login credentials") if request['barcode'].nil? || request['pin'].nil?
36
- begin
37
- @polaris_user_info = @adaptor.bind_as(:barcode => request['barcode'], :pin => request['pin'])
38
- return fail!(:invalid_credentials) if !@polaris_user_info
46
+ fail(MissingCredentialsError, 'Missing login credentials') if %w[barcode pin].any? { |request_key| request.params[request_key].blank? }
39
47
 
40
- @user_info = self.class.map_user(@@config, @polaris_user_info)
41
- super
42
- rescue Exception => e
43
- return fail!(:polaris_error, e)
44
- end
48
+ @polaris_user_info = @adaptor.authenticate_patron(pin: request.params['pin'], barcode: request.params['barcode'])
49
+
50
+ fail(InvalidCredentialsError, 'Invalid User Credentials!') if @polaris_user_info.blank?
51
+
52
+ @user_info = self.class.map_user(@polaris_user_info)
53
+
54
+ super
55
+ rescue MissingCredentialsError => e
56
+ fail!(:missing_credentials, e)
57
+ rescue InvalidCredentialsError => e
58
+ fail!(:invalid_credentials, e)
59
+ rescue StandardError => e
60
+ fail!(:polaris_error, e)
61
+ end
62
+ # rubocop:enable Style/SignalException
63
+
64
+ uid do
65
+ @user_info[:barcode]
45
66
  end
46
67
 
47
- uid {
48
- request['barcode']
49
- }
50
- info {
68
+ info do
51
69
  @user_info
52
- }
53
- extra {
54
- { :raw_info => @polaris_user_info }
55
- }
56
-
57
- # def map_user(mapper, object)
58
- # Ben 12/24/2018 Doesnt appear this method is in use
59
- # user = {}
60
- # mapper.each do |key, value|
61
- # case value
62
- # when String
63
- # #user[key] = object[value.downcase.to_sym].first if object[value.downcase.to_sym]
64
- # user[key.to_sym] = object[value] if object[value]
65
- # when Array
66
- # #value.each {|v| (user[key] = object[v.downcase.to_sym].first; break;) if object[v.downcase.to_sym]}
67
- # value.each {|v| (user[key] = object[v.downcase.to_sym]; break;) if object[v.downcase.to_sym]}
68
- # when Hash
69
- # value.map do |key1, value1|
70
- # pattern = key1.dup
71
- # value1.each_with_index do |v,i|
72
- # #part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1].first; break;) if object[v1]}
73
- # part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1]; break;) if object[v1]}
74
- # pattern.gsub!("%#{i}", part || '')
75
- # end
76
- # user[key] = pattern
77
- # end
78
- # end
79
- # end
80
- # user
81
- # end
82
-
83
-
84
- def self.map_user(mapper, object)
85
- user = {}
86
- mapper.each do |key, value|
87
- case value.class.to_s
88
- when String
89
- user[key.to_sym] = object[value.to_sym] if object[value.to_sym]
90
- when Array
91
- #value.each {|v| (user[key] = object[v.downcase.to_sym].first; break;) if object[v.downcase.to_sym]}
92
- value.each {|v| (user[key] = object[v.downcase.to_sym]; break;) if object[v.downcase.to_sym]}
93
- when Hash
94
- value.map do |key1, value1|
95
- pattern = key1.dup
96
- value1.each_with_index do |v,i|
97
- #part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1].first; break;) if object[v1]}
98
- part = ''; v.collect(&:downcase).collect(&:to_sym).each {|v1| (part = object[v1]; break;) if object[v1]}
99
- pattern.gsub!("%#{i}", part || '')
100
- end
101
- user[key] = pattern
102
- end
103
- end
104
- end
105
- user
70
+ end
71
+
72
+ extra do
73
+ { raw_info: @polaris_user_info }
106
74
  end
107
75
  end
108
76
  end
@@ -1,3 +1,3 @@
1
- require 'omniauth-polaris/version'
2
- require 'omniauth-polaris/adaptor'
3
- require 'omniauth/strategies/polaris'
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/polaris'
@@ -1,29 +1,30 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'omniauth-polaris/version'
5
- Gem::Specification.new do |gem|
6
- gem.name = "omniauth-polaris"
7
- gem.version = OmniAuth::Polaris::VERSION
8
- gem.authors = ["Steven Anderson", "Ben Barber"]
9
- gem.email = ["sanderson@bpl.org", "bbarber@bpl.org"]
10
- gem.description = %q{A Polaris API strategy for OmniAuth.}
11
- gem.summary = %q{A Polaris API strategy for OmniAuth.}
12
- gem.homepage = "https://github.com/boston-library/omniauth-polaris"
1
+ # frozen_string_literal: true
2
+
3
+ $:.push File.expand_path('lib', __dir__)
4
+ require 'omniauth/polaris/version'
13
5
 
14
- gem.required_ruby_version = '~> 2.4'
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'omniauth-polaris'
8
+ gem.version = OmniAuth::Polaris::VERSION.dup
9
+ gem.authors = ['Steven Anderson', 'Ben Barber']
10
+ gem.email = ['digital@bpl.org', 'bbarber@bpl.org']
11
+ gem.description = 'A Polaris API strategy for OmniAuth.'
12
+ gem.summary = 'A Polaris API strategy for OmniAuth.'
13
+ gem.homepage = 'https://github.com/boston-library/omniauth-polaris'
15
14
 
15
+ gem.required_ruby_version = '>= 2.6.10'
16
16
 
17
- gem.add_dependency 'rest-client', '~> 2.0.2'
17
+ gem.add_dependency 'activesupport', '< 7'
18
+ gem.add_dependency 'http', '~> 5.1'
19
+ gem.add_dependency 'omniauth', '~> 2.1.0'
18
20
 
19
- gem.add_development_dependency 'omniauth', '~> 1.8.1'
21
+ gem.add_development_dependency 'awesome_print', '~> 1.9.2'
20
22
  gem.add_development_dependency 'bundler', '>= 1.3.0'
21
- gem.add_development_dependency 'awesome_print'
22
- gem.add_development_dependency 'rspec', '~> 3.8'
23
23
  gem.add_development_dependency 'libnotify', '~> 0.9.3'
24
+ gem.add_development_dependency 'pry', '~> 0.14'
25
+ gem.add_development_dependency 'rspec', '~> 3.12'
24
26
 
25
27
  gem.files = `git ls-files -z`.split("\x0")
26
28
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
28
29
  gem.require_paths = ['lib']
29
30
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'OmniAuth::Polaris::Adaptor' do
6
+ describe 'initialize' do
7
+ let!(:patron_url) { 'http://blah.org/PAPIService/REST/public/v1/1000/100/1/patron/' }
8
+
9
+ it 'is expected to throw exception when must have field is not set' do
10
+ expect { OmniAuth::Polaris::Adaptor.new({ http_uri: patron_url, method: 'POST' }) }.to raise_error(OmniAuth::Polaris::ConfigurationError)
11
+ end
12
+
13
+ it 'is expected to throw exception when method is not supported' do
14
+ expect { OmniAuth::Polaris::Adaptor.new({ http_uri: patron_url, method: 'GET', access_key: 'F9998888-A000-1111-C22C-CC3333BB4444', access_id: 'API' }) }.to raise_error(OmniAuth::Polaris::ConfigurationError)
15
+ end
16
+ end
17
+ end
@@ -1,77 +1,100 @@
1
- require 'spec_helper'
2
- describe "OmniAuth::Strategies::Polaris" do
1
+ # frozen_string_literal: true
3
2
 
3
+ require 'spec_helper'
4
4
 
5
- class MyPolarisProvider < OmniAuth::Strategies::Polaris; end
5
+ describe 'OmniAuth::Strategies::Polaris' do
6
6
  def app
7
- Rack::Builder.new {
7
+ Rack::Builder.new do
8
8
  use OmniAuth::Test::PhonySession
9
- use MyPolarisProvider, :name => 'polaris', :title => 'MyPolaris Form', :http_uri => 'http://blah.org/PAPIService/REST/public/v1/1000/100/1/patron/', :access_key => 'F9998888-A000-1111-C22C-CC3333BB4444', :access_id => 'API', :method => 'GET'
10
- run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
11
- }.to_app
9
+ use OmniAuth::Builder do
10
+ provider OmniAuth::Strategies::Polaris, name: 'polaris', title: 'MyPolaris Form', http_uri: 'https://blah.org/PAPIService/REST/public/v1/1000/100/1/patron/', access_key: 'F9998888-A000-1111-C22C-CC3333BB4444', access_id: 'API', method: 'POST'
11
+ end
12
+ run ->(env) { [404, { 'Content-Type' => 'text/plain' }, [env.key?('omniauth.auth').to_s]] }
13
+ end.to_app
12
14
  end
13
15
 
14
16
  def session
15
17
  last_request.env['rack.session']
16
18
  end
17
19
 
18
- it 'should add a camelization for itself' do
19
- expect( OmniAuth::Utils.camelize('polaris') ).to eq('Polaris')
20
+ it 'is expected to add a camelization for itself' do
21
+ expect(OmniAuth::Utils.camelize('polaris')).to eq('Polaris')
20
22
  end
21
23
 
22
24
  describe '/auth/polaris' do
23
- before(:each){ get '/auth/polaris' }
25
+ before { post '/auth/polaris' }
24
26
 
25
- it 'should display a form' do
26
- expect(last_response.status).to eql(200)
27
- expect(last_response.body).to include("<form")
27
+ it 'is expected to display a form' do
28
+ expect(last_response.status).to be(200)
29
+ expect(last_response.body).to include('<form')
28
30
  end
29
31
 
30
- it 'should have the callback as the action for the form' do
31
- expect(last_response.body).to include("action='/auth/polaris/callback'")
32
+ it 'is expected to have the callback as the action for the form' do
33
+ expect(last_response.body).to include('/auth/polaris/callback')
32
34
  end
33
35
 
34
- it 'should have a text field for each of the fields' do
36
+ it 'is expected to have a text field for each of the fields' do
35
37
  expect(last_response.body.scan('<input').size).to eq(2)
36
38
  end
37
- it 'should have a label of the form title' do
39
+
40
+ it 'is expected to have a label of the form title' do
38
41
  expect(last_response.body.scan('MyPolaris Form').size).to be > 1
39
42
  end
40
-
41
43
  end
42
44
 
43
45
  describe 'post /auth/polaris/callback' do
44
- before(:each) do
45
- @adaptor = double(OmniAuth::Polaris::Adaptor, {:barcode => '29999999999999'})
46
- allow(OmniAuth::Polaris::Adaptor).to receive(:new).and_return(@adaptor)
46
+ before do
47
+ allow(OmniAuth::Polaris::Adaptor).to receive(:new).and_return(adaptor)
47
48
  end
48
- context 'failure' do
49
- before(:each) do
50
- allow(@adaptor).to receive(:bind_as).and_return(false)
49
+
50
+ let!(:adaptor) { instance_double(OmniAuth::Polaris::Adaptor) }
51
+
52
+ context 'when failure' do
53
+ before do
54
+ allow(adaptor).to receive(:authenticate_patron).and_return(nil)
51
55
  end
52
- it 'should raise MissingCredentialsError' do
53
- expect{ post('/auth/polaris/callback', {}) }.to raise_error OmniAuth::Strategies::Polaris::MissingCredentialsError
56
+
57
+ it 'is expected to fail! with :missing_credentials' do
58
+ post('/auth/polaris/callback', {})
59
+ expect(last_request.env['omniauth.error']).to be_a_kind_of(OmniAuth::Strategies::Polaris::MissingCredentialsError)
60
+ expect(last_request.env['omniauth.error.type']).to be(:missing_credentials)
54
61
  end
55
- it 'should redirect to error page' do
56
- post('/auth/polaris/callback', {:barcode => 'ping', :pin => 'password'})
62
+
63
+ it 'is expected to redirect to error page' do
64
+ post('/auth/polaris/callback', { barcode: 'ping', pin: 'password' })
57
65
  expect(last_response).to be_redirect
58
- expect(last_response.headers['Location']).to match(%r{invalid_credentials})
66
+ expect(last_response.headers['Location']).to match(/invalid_credentials/)
59
67
  end
60
68
  end
61
69
 
62
- context 'success' do
63
- let(:auth_hash){ last_request.env['omniauth.auth'] }
64
- before(:each) do
65
- allow(@adaptor).to receive(:bind_as).and_return({:PAPIErrorCode => "0", :barcode => '29999999999999', :ValidPatron => 'true', :PatronID => '111111', :PatronCodeID => '27',
66
- :AssignedBranchID => '3', :PatronBarcode => '29999999999999', :AssignedBranchName => 'BPL - Central', :ExpirationDate => '2015-09-20T00:00:00', :OverridePasswordUsed =>'false'})
67
- #
68
- post('/auth/polaris/callback', {:barcode => '29999021413588', :pin => '0407'})
70
+ context 'when successful' do
71
+ let(:auth_hash) { last_request.env['omniauth.auth'] }
72
+ let(:patron_user_hash) do
73
+ {
74
+ 'PAPIErrorCode' => '0',
75
+ 'Barcode' => '29999999999999',
76
+ 'ValidPatron' => 'true',
77
+ 'PatronID' => '111111',
78
+ 'PatronCodeID' => '27',
79
+ 'AssignedBranchID' => '3',
80
+ 'PatronBarcode' => '29999999999999',
81
+ 'AssignedBranchName' => 'BPL - Central',
82
+ 'ExpirationDate' => '2026-02-19T00:00:00',
83
+ 'OverridePasswordUsed' => 'false',
84
+ 'NameFirst' => 'Test',
85
+ 'NameLast' => 'Patron',
86
+ 'NameMiddle' => '',
87
+ 'EmailAddress' => 'test.patron@example.com',
88
+ 'PhoneNumber' => '555-555-5555'
89
+ }
90
+ end
91
+
92
+ before do
93
+ allow(adaptor).to receive(:authenticate_patron).and_return(patron_user_hash)
94
+ post('/auth/polaris/callback', { barcode: '29999999999999', pin: '12345678' })
69
95
  end
70
96
 
71
- # it 'should raise MissingCredentialsError' do
72
- # should_not raise_error OmniAuth::Strategies::Polaris::MissingCredentialsError
73
- # end
74
- it 'should map user info' do
97
+ it 'is expected to map user info' do
75
98
  expect(auth_hash.info.barcode).to eq('29999999999999')
76
99
  expect(auth_hash.info.valid_patron).to eq('true')
77
100
  expect(auth_hash.info.patron_id).to eq('111111')
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,32 @@
1
- $:.unshift File.expand_path('..', __FILE__)
2
- $:.unshift File.expand_path('../../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $:.unshift File.expand_path(__dir__)
4
+ $:.unshift File.expand_path('../lib', __dir__)
5
+
6
+ ENV['RACK_ENV'] ||= 'test'
7
+
3
8
  require 'simplecov'
4
9
  SimpleCov.start
10
+
11
+ require 'pry'
12
+ require 'awesome_print'
5
13
  require 'rspec'
6
14
  require 'rack/test'
7
- require 'omniauth'
8
15
  require 'omniauth-polaris'
9
- require 'awesome_print'
16
+
17
+ OmniAuth.config.request_validation_phase = nil
10
18
 
11
19
  RSpec.configure do |config|
12
20
  config.include Rack::Test::Methods
13
- config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
21
+ config.extend OmniAuth::Test::StrategyMacros, type: :strategy
22
+ config.mock_with :rspec do |mocks|
23
+ # Prevents you from mocking or stubbing a method that does not exist on
24
+ # a real object. This is generally recommended, and will default to
25
+ # `true` in RSpec 4.
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+
29
+ config.expect_with :rspec do |c|
30
+ c.syntax = :expect
31
+ end
14
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-polaris
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Anderson
@@ -9,36 +9,64 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-03 00:00:00.000000000 Z
12
+ date: 2023-01-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rest-client
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "<"
19
+ - !ruby/object:Gem::Version
20
+ version: '7'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "<"
26
+ - !ruby/object:Gem::Version
27
+ version: '7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: http
16
30
  requirement: !ruby/object:Gem::Requirement
17
31
  requirements:
18
32
  - - "~>"
19
33
  - !ruby/object:Gem::Version
20
- version: 2.0.2
34
+ version: '5.1'
21
35
  type: :runtime
22
36
  prerelease: false
23
37
  version_requirements: !ruby/object:Gem::Requirement
24
38
  requirements:
25
39
  - - "~>"
26
40
  - !ruby/object:Gem::Version
27
- version: 2.0.2
41
+ version: '5.1'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: omniauth
30
44
  requirement: !ruby/object:Gem::Requirement
31
45
  requirements:
32
46
  - - "~>"
33
47
  - !ruby/object:Gem::Version
34
- version: 1.8.1
48
+ version: 2.1.0
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 2.1.0
56
+ - !ruby/object:Gem::Dependency
57
+ name: awesome_print
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.9.2
35
63
  type: :development
36
64
  prerelease: false
37
65
  version_requirements: !ruby/object:Gem::Requirement
38
66
  requirements:
39
67
  - - "~>"
40
68
  - !ruby/object:Gem::Version
41
- version: 1.8.1
69
+ version: 1.9.2
42
70
  - !ruby/object:Gem::Dependency
43
71
  name: bundler
44
72
  requirement: !ruby/object:Gem::Requirement
@@ -54,66 +82,70 @@ dependencies:
54
82
  - !ruby/object:Gem::Version
55
83
  version: 1.3.0
56
84
  - !ruby/object:Gem::Dependency
57
- name: awesome_print
85
+ name: libnotify
58
86
  requirement: !ruby/object:Gem::Requirement
59
87
  requirements:
60
- - - ">="
88
+ - - "~>"
61
89
  - !ruby/object:Gem::Version
62
- version: '0'
90
+ version: 0.9.3
63
91
  type: :development
64
92
  prerelease: false
65
93
  version_requirements: !ruby/object:Gem::Requirement
66
94
  requirements:
67
- - - ">="
95
+ - - "~>"
68
96
  - !ruby/object:Gem::Version
69
- version: '0'
97
+ version: 0.9.3
70
98
  - !ruby/object:Gem::Dependency
71
- name: rspec
99
+ name: pry
72
100
  requirement: !ruby/object:Gem::Requirement
73
101
  requirements:
74
102
  - - "~>"
75
103
  - !ruby/object:Gem::Version
76
- version: '3.8'
104
+ version: '0.14'
77
105
  type: :development
78
106
  prerelease: false
79
107
  version_requirements: !ruby/object:Gem::Requirement
80
108
  requirements:
81
109
  - - "~>"
82
110
  - !ruby/object:Gem::Version
83
- version: '3.8'
111
+ version: '0.14'
84
112
  - !ruby/object:Gem::Dependency
85
- name: libnotify
113
+ name: rspec
86
114
  requirement: !ruby/object:Gem::Requirement
87
115
  requirements:
88
116
  - - "~>"
89
117
  - !ruby/object:Gem::Version
90
- version: 0.9.3
118
+ version: '3.12'
91
119
  type: :development
92
120
  prerelease: false
93
121
  version_requirements: !ruby/object:Gem::Requirement
94
122
  requirements:
95
123
  - - "~>"
96
124
  - !ruby/object:Gem::Version
97
- version: 0.9.3
125
+ version: '3.12'
98
126
  description: A Polaris API strategy for OmniAuth.
99
127
  email:
100
- - sanderson@bpl.org
128
+ - digital@bpl.org
101
129
  - bbarber@bpl.org
102
- executables: []
130
+ executables:
131
+ - console
103
132
  extensions: []
104
133
  extra_rdoc_files: []
105
134
  files:
106
135
  - ".gitignore"
107
136
  - ".rubocop.yml"
137
+ - ".rubocop_todo.yml"
108
138
  - Gemfile
109
139
  - README.rdoc
110
140
  - Rakefile
141
+ - bin/console
111
142
  - lib/omniauth-polaris.rb
112
- - lib/omniauth-polaris/adaptor.rb
113
- - lib/omniauth-polaris/version.rb
143
+ - lib/omniauth/polaris.rb
144
+ - lib/omniauth/polaris/adaptor.rb
145
+ - lib/omniauth/polaris/version.rb
114
146
  - lib/omniauth/strategies/polaris.rb
115
147
  - omniauth-polaris.gemspec
116
- - spec/omniauth-ldap/adaptor_spec.rb
148
+ - spec/omniauth/polaris/adaptor_spec.rb
117
149
  - spec/omniauth/strategies/polaris_spec.rb
118
150
  - spec/spec_helper.rb
119
151
  homepage: https://github.com/boston-library/omniauth-polaris
@@ -125,21 +157,17 @@ require_paths:
125
157
  - lib
126
158
  required_ruby_version: !ruby/object:Gem::Requirement
127
159
  requirements:
128
- - - "~>"
160
+ - - ">="
129
161
  - !ruby/object:Gem::Version
130
- version: '2.4'
162
+ version: 2.6.10
131
163
  required_rubygems_version: !ruby/object:Gem::Requirement
132
164
  requirements:
133
165
  - - ">="
134
166
  - !ruby/object:Gem::Version
135
167
  version: '0'
136
168
  requirements: []
137
- rubyforge_project:
138
- rubygems_version: 2.6.14.3
169
+ rubygems_version: 3.3.26
139
170
  signing_key:
140
171
  specification_version: 4
141
172
  summary: A Polaris API strategy for OmniAuth.
142
- test_files:
143
- - spec/omniauth-ldap/adaptor_spec.rb
144
- - spec/omniauth/strategies/polaris_spec.rb
145
- - spec/spec_helper.rb
173
+ test_files: []
@@ -1,96 +0,0 @@
1
- require 'base64'
2
- require 'cgi'
3
- require 'openssl'
4
- require 'rest_client'
5
-
6
- module OmniAuth
7
- module Polaris
8
- class Adaptor
9
- class PolarisError < StandardError; end
10
- class ConfigurationError < StandardError; end
11
- class AuthenticationError < StandardError; end
12
- class ConnectionError < StandardError; end
13
-
14
- VALID_ADAPTER_CONFIGURATION_KEYS = [:access_id, :access_key, :method, :http_uri]
15
-
16
- MUST_HAVE_KEYS = [:access_id, :access_key, :method, :http_uri]
17
-
18
- METHOD = {
19
- :GET => :GET
20
- }
21
-
22
- attr_reader :config
23
-
24
- def self.validate(configuration={})
25
- message = []
26
- MUST_HAVE_KEYS.each do |name|
27
- message << name if configuration[name].nil?
28
- end
29
- raise ArgumentError.new(message.join(",") +" MUST be provided") unless message.empty?
30
- end
31
-
32
- def initialize(configuration={})
33
- Adaptor.validate(configuration)
34
- @configuration = configuration.dup
35
- @logger = @configuration.delete(:logger)
36
- VALID_ADAPTER_CONFIGURATION_KEYS.each do |name|
37
- instance_variable_set("@#{name}", @configuration[name])
38
- end
39
-
40
- @config = {
41
- :http_uri => @http_uri,
42
- :method => @method,
43
- :access_key => @access_key,
44
- :access_id => @access_id
45
- }
46
-
47
- method = ensure_method(@method)
48
-
49
- end
50
-
51
- public
52
- def bind_as(args = {})
53
- response = false
54
-
55
- #Basic shared input variables
56
- pin = args[:pin]
57
- barcode = args[:barcode]
58
- http_date = Time.now.in_time_zone("GMT").strftime("%a, %d %b %Y %H:%M:%S %Z")
59
-
60
- #Authorization hash component
61
- http_uri_with_barcode = @http_uri + barcode
62
- concated_string = @method + @http_uri + barcode + http_date + pin
63
- sha1_sig = Base64.strict_encode64("#{OpenSSL::HMAC.digest('sha1',@access_key, concated_string)}")
64
- xml_response = RestClient.get http_uri_with_barcode, {'PolarisDate' => http_date, 'Authorization' => "PWS " + @access_id + ":" + sha1_sig}
65
- authorization_response = Hash.from_xml xml_response
66
-
67
- #Details hash component
68
- http_basic_data_get = @http_uri + barcode + '/basicdata'
69
- concated_string = @method + http_basic_data_get + http_date + pin
70
- sha1_sig = Base64.strict_encode64("#{OpenSSL::HMAC.digest('sha1',@access_key, concated_string)}")
71
- xml_response = RestClient.get http_basic_data_get, {'PolarisDate' => http_date, 'Authorization' => "PWS " + @access_id + ":" + sha1_sig}
72
- details_response = Hash.from_xml xml_response
73
-
74
- #Add some of the basic details to a single hash, using the authorization as the base.
75
- authorization_response["PatronValidateResult"]["NameFirst"] = details_response["PatronBasicDataGetResult"]["PatronBasicData"]["NameFirst"]
76
- authorization_response["PatronValidateResult"]["NameLast"] = details_response["PatronBasicDataGetResult"]["PatronBasicData"]["NameLast"]
77
- authorization_response["PatronValidateResult"]["NameMiddle"] = details_response["PatronBasicDataGetResult"]["PatronBasicData"]["NameMiddle"]
78
- authorization_response["PatronValidateResult"]["PhoneNumber"] = details_response["PatronBasicDataGetResult"]["PatronBasicData"]["PhoneNumber"]
79
- authorization_response["PatronValidateResult"]["EmailAddress"] = details_response["PatronBasicDataGetResult"]["PatronBasicData"]["EmailAddress"]
80
-
81
- authorization_response["PatronValidateResult"]
82
- end
83
-
84
- private
85
-
86
- def ensure_method(method="get")
87
- normalized_method = method.to_s.upcase.to_sym
88
- return METHOD[normalized_method] if METHOD.key?(normalized_method)
89
-
90
- available_methods = METHOD.keys.collect {|m| m.inspect}.join(", ")
91
- format = "%s is not one of the available connect methods: %s"
92
- raise ConfigurationError, format % [method.inspect, available_methods]
93
- end
94
- end
95
- end
96
- end
@@ -1,5 +0,0 @@
1
- module OmniAuth
2
- module Polaris
3
- VERSION = '1.0.5'.freeze
4
- end
5
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
- describe "OmniAuth::Polaris::Adaptor" do
3
-
4
- describe 'initialize' do
5
- it 'should throw exception when must have field is not set' do
6
- #[:host, :port, :method, :bind_dn]
7
- expect{ OmniAuth::Polaris::Adaptor.new({http_uri: "http://blah.org/PAPIService/REST/public/v1/1000/100/1/patron/", method: 'GET'})}.to raise_error(ArgumentError)
8
- end
9
-
10
- it 'should throw exception when method is not supported' do
11
- expect { OmniAuth::Polaris::Adaptor.new({http_uri: "http://blah.org/PAPIService/REST/public/v1/1000/100/1/patron/", method: 'POST', access_key: 'F9998888-A000-1111-C22C-CC3333BB4444', access_id: 'API'})}.to raise_error(OmniAuth::Polaris::Adaptor::ConfigurationError)
12
- end
13
- end
14
-
15
- end