Skip to content

Commit 7bbef08

Browse files
author
Peter Karman
committed
Support multiple settings.auth_context
**Why**: SAML supports multiple AuthnContextClassRef elements in an Authn request.
1 parent 7d48ca8 commit 7bbef08

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/onelogin/ruby-saml/authrequest.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ def create_xml_document(settings)
136136
}
137137

138138
if settings.authn_context != nil
139-
class_ref = requested_context.add_element "saml:AuthnContextClassRef"
140-
class_ref.text = settings.authn_context
139+
authn_contexts = settings.authn_context.is_a?(Array) ? settings.authn_context : [settings.authn_context]
140+
authn_contexts.each do |authn_context|
141+
class_ref = requested_context.add_element "saml:AuthnContextClassRef"
142+
class_ref.text = authn_context
143+
end
141144
end
142145
# add saml:AuthnContextDeclRef element
143146
if settings.authn_context_decl_ref != nil

test/request_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ class RequestTest < Minitest::Test
152152
assert_match /<saml:AuthnContextClassRef>secure\/name\/password\/uri<\/saml:AuthnContextClassRef>/, auth_doc.to_s
153153
end
154154

155+
it "create multiple saml:AuthnContextClassRef elements correctly" do
156+
settings.authn_context = ['foo', 'bar']
157+
auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)
158+
assert_match /<saml:AuthnContextClassRef>foo<\/saml:AuthnContextClassRef>/, auth_doc.to_s
159+
assert_match /<saml:AuthnContextClassRef>bar<\/saml:AuthnContextClassRef>/, auth_doc.to_s
160+
end
161+
155162
it "create the saml:AuthnContextClassRef with comparison exact" do
156163
settings.authn_context = 'secure/name/password/uri'
157164
auth_doc = OneLogin::RubySaml::Authrequest.new.create_authentication_xml_doc(settings)

0 commit comments

Comments
 (0)