omniauth-suomifi 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: 3bba7a20e137303ea20efd3d2d829c9e37e103b5c47d864188b50a16cce7d758
4
- data.tar.gz: 481a5fe89956132db550b05d7ffd9e997ae377b6dafb4ba096c4e011edaf0fed
3
+ metadata.gz: 29541d8a6b97e782ec1714090cf213e0d8d7d3a439ed687c626bb0150a40b0d8
4
+ data.tar.gz: 6fc90b20d63255872a8993190ace3ab2f083270cfb78885bb1727f12268360ad
5
5
  SHA512:
6
- metadata.gz: 5e58186eca6d49643657a3e421a5417b9caf988d212c78230224ca1e0e7e0819a46c04adf19f3e94554730cb7090c1cdc786cc4e6cdac61cffe96b9ab3cccd5e
7
- data.tar.gz: 4cac68f67dab309856e7919c2b894322dcb90370968ec2772b5b19d738486afd0b8977ec4ece944c653e65fc862372e881f9553e94ea64afceaa77cd7bd6b876
6
+ metadata.gz: 4e906f7e048944692417c877ef345526cc0f93d9ce3f367d75a8841d0e85b80960f76c2388689fa0b98db96cb29ca5df84432d01c5b4ed1b642111b5187d83a5
7
+ data.tar.gz: b3e33e543d3a058a581d8cd5d524431afcd01d47ca724182cf36d82435bf9402aac2555f1a59bb145462900ec850104c57890173fe7f8809fa85d89aa0bf5366
@@ -16,6 +16,29 @@ module OmniAuth
16
16
  # The private key file to define the private key.
17
17
  option :private_key_file, nil
18
18
 
19
+ # Defines the locale parameters to check from the request phase request
20
+ # parameters. A valid language will be added to the IdP sign in redirect
21
+ # URL as the last parameter (with the name `locale` as expected by
22
+ # Suomi.fi).
23
+ #
24
+ # Suomi.fi accepts `fi`, `sv` or `en` in this parameter. The language can
25
+ # be parsed from the following kind of strings:
26
+ # - fi
27
+ # - sv-SE
28
+ # - en_US
29
+ #
30
+ # In case a valid language cannot be parsed from the parameter, the locale
31
+ # parameter will default to `:idp_sso_target_url_default_locale`.
32
+ #
33
+ # Note that the locale parameter is always added as the last parameter in
34
+ # in the redirect URL as expected by Suomi.fi.
35
+ option :idp_sso_target_url_locale_params, %w[locale language lang]
36
+
37
+ # This is the default locale to be passed to IdP sign in redirect URL as
38
+ # defined above. In case a valid locale is not found from the request
39
+ # parameters, this will be used instead.
40
+ option :idp_sso_target_url_default_locale, 'fi'
41
+
19
42
  # The request attributes for Suomi.fi
20
43
  option :possible_request_attributes, [
21
44
  ##############################
@@ -493,6 +516,20 @@ module OmniAuth
493
516
  )
494
517
  end
495
518
 
519
+ # Override the request phase to be able to pass the locale parameter to
520
+ # the redirect URL. Note that this needs to be the last parameter to
521
+ # be passed to the redirect URL.
522
+ def request_phase
523
+ authn_request = OneLogin::RubySaml::Authrequest.new
524
+ locale = locale_for_authn_request
525
+
526
+ with_settings do |settings|
527
+ url = authn_request.create(settings, additional_params_for_authn_request)
528
+ url += "&locale=#{CGI.escape(locale)}" unless locale.nil?
529
+ redirect(url)
530
+ end
531
+ end
532
+
496
533
  # This method can be used externally to fetch information about the
497
534
  # response, e.g. in case of failures.
498
535
  def response_object
@@ -508,6 +545,13 @@ module OmniAuth
508
545
  end
509
546
  end
510
547
 
548
+ # Override the callback URL so that it always matches the one expected by
549
+ # Suomi.fi. No additional query string parameters can be included in the
550
+ # string.
551
+ def callback_url
552
+ full_host + script_name + callback_path
553
+ end
554
+
511
555
  private
512
556
 
513
557
  # Suomi.fi requires that the service provider needs to end the local user
@@ -603,6 +647,25 @@ module OmniAuth
603
647
  end
604
648
  end
605
649
  end
650
+
651
+ def locale_for_authn_request
652
+ if options.idp_sso_target_url_locale_params.is_a?(Array)
653
+ options.idp_sso_target_url_locale_params.each do |param|
654
+ next unless request.params.key?(param.to_s)
655
+
656
+ locale = parse_language_value(request.params[param.to_s])
657
+ return locale unless locale.nil?
658
+ end
659
+ end
660
+
661
+ options.idp_sso_target_url_default_locale
662
+ end
663
+
664
+ def parse_language_value(string)
665
+ language = string.sub('_', '-').split('-').first
666
+
667
+ language if language =~ /^(fi|sv|en)$/
668
+ end
606
669
  end
607
670
  end
608
671
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module Suomifi
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-suomifi
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