File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,10 @@ be present.
155155
156156* ` :uid_attribute ` - Attribute that uniquely identifies the user. If unset, the name identifier returned by the IdP is used.
157157
158+ * ` :store_request_uuid ` - Used to store the request's UUID for later verification of InReponseTo.
159+ By default it saves the request uuid in the session as "saml_transaction_id",
160+ but also accepts a proc that will then be called with the uuid for custom storage.
161+
158162* See the ` OneLogin::RubySaml::Settings ` class in the [ Ruby SAML gem] ( https://github.com/onelogin/ruby-saml ) for additional supported options.
159163
160164## IdP Metadata
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments