Skip to content

Commit

Permalink
[fix] Allow IdP set reference ID for SAML response (#21)
Browse files Browse the repository at this point in the history
* Pass ref id as Session Index

* Official Rails 8 is not released yet to RubyGem until that let's stick official older version

---------

Co-authored-by: zogoo <[email protected]>
  • Loading branch information
Zogoo and zogoo authored Oct 25, 2024
1 parent d95a9d6 commit fcb331b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gemfiles/rails_dev.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "rails", github: "rails/rails", branch: "main"
gem "rails", "~> 7.2.1"
gem "activeresource", github: "rails/activeresource", branch: "main"

gemspec path: "../"
4 changes: 2 additions & 2 deletions lib/saml_idp/saml_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def response_builder

def assertion_builder
@assertion_builder ||=
AssertionBuilder.new SecureRandom.uuid,
AssertionBuilder.new(reference_id || SecureRandom.uuid,
issuer_uri,
principal,
audience_uri,
Expand All @@ -110,7 +110,7 @@ def assertion_builder
encryption_opts,
session_expiry,
name_id_formats_opts,
asserted_attributes_opts
asserted_attributes_opts)
end
private :assertion_builder
end
Expand Down
19 changes: 19 additions & 0 deletions spec/lib/saml_idp/saml_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ module SamlIdp
expect(saml_resp.is_valid?).to eq(true)
end

it "will pass reference_id as SessionIndex" do
expect { subject.build }.not_to raise_error
signed_encoded_xml = subject.build
resp_settings = saml_settings(saml_acs_url)
resp_settings.private_key = Default::SECRET_KEY
resp_settings.issuer = audience_uri
saml_resp = OneLogin::RubySaml::Response.new(signed_encoded_xml, settings: resp_settings)

expect(
Nokogiri::XML(saml_resp.response).at_xpath(
"//saml:AuthnStatement/@SessionIndex",
{
"samlp" => "urn:oasis:names:tc:SAML:2.0:protocol",
"saml" => "urn:oasis:names:tc:SAML:2.0:assertion"
}
).value
).to eq("_#{reference_id}")
end

it "sets session expiration" do
saml_resp = OneLogin::RubySaml::Response.new(subject.build)
expect(saml_resp.session_expires_at).to eq Time.local(1990, "jan", 2).iso8601
Expand Down

0 comments on commit fcb331b

Please sign in to comment.