Skip to content

Commit bb6501f

Browse files
committed
Merge pull request #143 from phene/support-force-authn
Add support for ForceAuthn on AuthRequests
2 parents 1f06df8 + d791a77 commit bb6501f

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/onelogin/ruby-saml/authrequest.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def create_authentication_xml_doc(settings)
4747
root.attributes['IsPassive'] = settings.passive unless settings.passive.nil?
4848
root.attributes['ProtocolBinding'] = settings.protocol_binding unless settings.protocol_binding.nil?
4949
root.attributes["AttributeConsumingServiceIndex"] = settings.attributes_index unless settings.attributes_index.nil?
50+
root.attributes['ForceAuthn'] = settings.force_authn unless settings.force_authn.nil?
5051

5152
# Conditionally defined elements based on settings
5253
if settings.assertion_consumer_service_url != nil

lib/onelogin/ruby-saml/settings.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def initialize(overrides = {})
2020
attr_accessor :passive
2121
attr_accessor :protocol_binding
2222
attr_accessor :attributes_index
23+
attr_accessor :force_authn
2324

2425
private
2526

test/request_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ class RequestTest < Test::Unit::TestCase
9696
assert_match /<samlp:AuthnRequest[^<]* AttributeConsumingServiceIndex='30'/, inflated
9797
end
9898

99+
should "create the SAMLRequest URL parameter with ForceAuthn" do
100+
settings = OneLogin::RubySaml::Settings.new
101+
settings.idp_sso_target_url = "http://example.com"
102+
settings.force_authn = true
103+
auth_url = OneLogin::RubySaml::Authrequest.new.create(settings)
104+
assert auth_url =~ /^http:\/\/example\.com\?SAMLRequest=/
105+
payload = CGI.unescape(auth_url.split("=").last)
106+
decoded = Base64.decode64(payload)
107+
108+
zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
109+
inflated = zstream.inflate(decoded)
110+
zstream.finish
111+
zstream.close
112+
assert_match /<samlp:AuthnRequest[^<]* ForceAuthn='true'/, inflated
113+
end
114+
99115
should "accept extra parameters" do
100116
settings = OneLogin::RubySaml::Settings.new
101117
settings.idp_sso_target_url = "http://example.com"

0 commit comments

Comments
 (0)