Skip to content

Commit f4cd947

Browse files
authored
supports params that can be used for re-authentication (#718)
1 parent ef997f0 commit f4cd947

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

lib/onelogin/ruby-saml/response.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,27 @@ def session_expires_at
198198
end
199199
end
200200

201+
# Gets the AuthnInstant from the AuthnStatement.
202+
# Could be used to require re-authentication if a long time has passed
203+
# since the last user authentication.
204+
# @return [String] AuthnInstant value
205+
#
206+
def authn_instant
207+
@authn_instant ||= begin
208+
node = xpath_first_from_signed_assertion('/a:AuthnStatement')
209+
node.nil? ? nil : node.attributes['AuthnInstant']
210+
end
211+
end
212+
213+
# Gets the AuthnContextClassRef from the AuthnStatement
214+
# Could be used to require re-authentication if the assertion
215+
# did not met the requested authentication context class.
216+
# @return [String] AuthnContextClassRef value
217+
#
218+
def authn_context_class_ref
219+
@authn_context_class_ref ||= Utils.element_text(xpath_first_from_signed_assertion('/a:AuthnStatement/a:AuthnContext/a:AuthnContextClassRef'))
220+
end
221+
201222
# Checks if the Status has the "Success" code
202223
# @return [Boolean] True if the StatusCode is Sucess
203224
#

test/response_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,18 @@ def generate_audience_error(expected, actual)
13571357
end
13581358
end
13591359

1360+
describe "#authn_instant" do
1361+
it "extract the value of the AuthnInstant attribute" do
1362+
assert_equal "2010-11-18T21:57:37Z", response.authn_instant
1363+
end
1364+
end
1365+
1366+
describe "#authn_context_class_ref" do
1367+
it "extract the value of the AuthnContextClassRef attribute" do
1368+
assert_equal "urn:oasis:names:tc:SAML:2.0:ac:classes:Password", response.authn_context_class_ref
1369+
end
1370+
end
1371+
13601372
describe "#success" do
13611373
it "find a status code that says success" do
13621374
response.success?

0 commit comments

Comments
 (0)