Skip to content

Commit cf08ad5

Browse files
author
James Edwards-Jones
committed
feat: allow request uuid to be stored
Introduces a :store_request_uuid option for later comparison with InResponseTo By default it saves the request uuid in the session as "saml_transaction_id", but also accepts a proc that will then be called with the uuid for custom storage.
1 parent a0eedd6 commit cf08ad5

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ Note that when [integrating with Devise](#devise-integration), the URL path will
143143

144144
* `:uid_attribute` - Attribute that uniquely identifies the user. If unset, the name identifier returned by the IdP is used.
145145

146+
* `:store_request_uuid` - Used to store the request's UUID for later verification of InReponseTo.
147+
By default it saves the request uuid in the session as "saml_transaction_id",
148+
but also accepts a proc that will then be called with the uuid for custom storage.
149+
146150
* See the `OneLogin::RubySaml::Settings` class in the [Ruby SAML gem](https://github.com/onelogin/ruby-saml) for additional supported options.
147151

148152
## IdP Metadata

lib/omniauth/strategies/saml.rb

+11
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,26 @@ def self.inherited(subclass)
3030
option :slo_default_relay_state
3131
option :uid_attribute
3232
option :idp_slo_session_destroy, proc { |_env, session| session.clear }
33+
option :store_request_uuid
3334

3435
def request_phase
3536
authn_request = OneLogin::RubySaml::Authrequest.new
3637

38+
store_request_uuid(authn_request.uuid)
39+
3740
with_settings do |settings|
3841
redirect(authn_request.create(settings, additional_params_for_authn_request))
3942
end
4043
end
4144

45+
def store_request_uuid(uuid)
46+
if options.store_request_uuid.respond_to?(:call)
47+
options.store_request_uuid.call(uuid)
48+
elsif options.store_request_uuid
49+
session["saml_transaction_id"] = uuid
50+
end
51+
end
52+
4253
def callback_phase
4354
raise OmniAuth::Strategies::SAML::ValidationError.new("SAML response missing") unless request.params["SAMLResponse"]
4455

spec/omniauth/strategies/saml_spec.rb

+23
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ def post_xml(xml=:example_response, opts = {})
115115
expect(query['SigAlg']).to eq XMLSecurity::Document::RSA_SHA256
116116
end
117117
end
118+
119+
context 'with store_request_uuid set' do
120+
let(:store_request_uuid) { true }
121+
let(:uuid_regex) { /_\w{8}-\w{4}-\w{4}-\w{4}-\w{11}/ }
122+
123+
before do
124+
saml_options[:store_request_uuid] = store_request_uuid
125+
126+
get '/auth/saml'
127+
end
128+
129+
it 'stores uuid as saml_transaction_id' do
130+
expect(session['saml_transaction_id']).to match(uuid_regex)
131+
end
132+
133+
context 'using a proc' do
134+
let(:store_request_uuid) { Proc.new { |uuid| @uuid_stored = uuid } }
135+
136+
it 'allows customized storage of request uuid' do
137+
expect(@uuid_stored).to match(uuid_regex)
138+
end
139+
end
140+
end
118141
end
119142

120143
describe 'POST /auth/saml/callback' do

0 commit comments

Comments
 (0)