Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] Allow IdP set reference ID for SAML response #21

Merged
merged 4 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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