omniauth-mpassid 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ee0bd0d81ad7593a430bdb8ee94ab733d7b396231ac284b7b99b1914d28ff84
4
- data.tar.gz: 6e1ef387f6e6f96e8557ced45f60817f8bb6536f7b2e53d5a1da471b82041829
3
+ metadata.gz: d20db7b39bbaa982cf5e05417c903cc08f3b543d7eac10ba621e8c5868aa1c45
4
+ data.tar.gz: 2c54ae01ece53cccc2d3f323c46e0d876a87443b38d306ce6ee9656fda8c1a3b
5
5
  SHA512:
6
- metadata.gz: e4c92ca00791f451b3a86cd8415abd1b45876e3c1515e0d4b6c038a4b293da544ffebef5b43e2c068af8991d3d22384454453b1e3b2f596f2cf129fc41148634
7
- data.tar.gz: cf982a1632ee51213463d30ac7d4c1d8f6c06d6e7a499004840b84f85ae731eac46add9d13280953009f1a7294af7659a2b136e8a7bb0975c19d04d6f1f9388b
6
+ metadata.gz: acd40c82d1dd81d7e4a9184c014dd0797930a2743327e61ab54319b9bebf2dc0726990386670ff94c4f216a27f910635daed878513dcd87fcbfc3a74180e5369
7
+ data.tar.gz: c1b6d98478a1c39c1aabb7cafd2d1631f92613897936ac497661271da0b848fa3a2740a9910d091dcae4e6c470490bc5571d9f3310b81743bc88e347a9d7b5fb
@@ -10,6 +10,27 @@ module OmniAuth
10
10
  # :test - MPASSid test environment
11
11
  option :mode, :production
12
12
 
13
+ # Defines the lang parameters to check from the request phase request
14
+ # parameters. A valid language will be added to the IdP sign in redirect
15
+ # URL as the last parameter (with the name `lang` as expected by
16
+ # MPASSid).
17
+ #
18
+ # MPASSid generally accepts `fi` or `sv` in this parameter but it can
19
+ # depend on the underlying service. The language can be parsed from the
20
+ # following kind of strings:
21
+ # - fi
22
+ # - sv-SE
23
+ # - fi_FI
24
+ #
25
+ # In case a valid language cannot be parsed from the parameter, the lang
26
+ # parameter will default to `:idp_sso_target_url_default_lang`.
27
+ option :idp_sso_target_url_lang_params, %w[locale language lang]
28
+
29
+ # This is the default language to be passed to IdP sign in redirect URL as
30
+ # defined above. In case a valid language is not found from the request
31
+ # parameters, this will be used instead.
32
+ option :idp_sso_target_url_default_lang, 'fi'
33
+
13
34
  # The request attributes for MPASSid
14
35
  option :request_attributes, [
15
36
  # The unique identifier of the authenticated user. Currently recommended
@@ -236,6 +257,20 @@ module OmniAuth
236
257
  )
237
258
  end
238
259
 
260
+ # Override the request phase to be able to pass the lang parameter to
261
+ # the redirect URL. Note that this needs to be the last parameter to
262
+ # be passed to the redirect URL.
263
+ def request_phase
264
+ authn_request = OneLogin::RubySaml::Authrequest.new
265
+ lang = lang_for_authn_request
266
+
267
+ with_settings do |settings|
268
+ url = authn_request.create(settings, additional_params_for_authn_request)
269
+ url += "&lang=#{CGI.escape(lang)}" unless lang.nil?
270
+ redirect(url)
271
+ end
272
+ end
273
+
239
274
  # This method can be used externally to fetch information about the
240
275
  # response, e.g. in case of failures.
241
276
  def response_object
@@ -251,6 +286,13 @@ module OmniAuth
251
286
  end
252
287
  end
253
288
 
289
+ # Override the callback URL so that it always matches the one expected by
290
+ # MPASSid. No additional query string parameters can be included in the
291
+ # string.
292
+ def callback_url
293
+ full_host + script_name + callback_path
294
+ end
295
+
254
296
  private
255
297
 
256
298
  def idp_metadata_url
@@ -302,6 +344,25 @@ module OmniAuth
302
344
  end
303
345
  end
304
346
  end
347
+
348
+ def lang_for_authn_request
349
+ if options.idp_sso_target_url_lang_params.is_a?(Array)
350
+ options.idp_sso_target_url_lang_params.each do |param|
351
+ next unless request.params.key?(param.to_s)
352
+
353
+ lang = parse_language_value(request.params[param.to_s])
354
+ return lang unless lang.nil?
355
+ end
356
+ end
357
+
358
+ options.idp_sso_target_url_default_lang
359
+ end
360
+
361
+ def parse_language_value(string)
362
+ language = string.sub('_', '-').split('-').first
363
+
364
+ language if language =~ /^(fi|sv)$/
365
+ end
305
366
  end
306
367
  end
307
368
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module MPASSid
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-mpassid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antti Hukkanen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-15 00:00:00.000000000 Z
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth-saml