File tree 3 files changed +38
-0
lines changed
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,10 @@ be present.
155
155
156
156
* ` :uid_attribute ` - Attribute that uniquely identifies the user. If unset, the name identifier returned by the IdP is used.
157
157
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
+
158
162
* See the ` OneLogin::RubySaml::Settings ` class in the [ Ruby SAML gem] ( https://github.com/onelogin/ruby-saml ) for additional supported options.
159
163
160
164
## IdP Metadata
Original file line number Diff line number Diff line change @@ -30,15 +30,26 @@ def self.inherited(subclass)
30
30
option :slo_default_relay_state
31
31
option :uid_attribute
32
32
option :idp_slo_session_destroy , proc { |_env , session | session . clear }
33
+ option :store_request_uuid
33
34
34
35
def request_phase
35
36
authn_request = OneLogin ::RubySaml ::Authrequest . new
36
37
38
+ store_request_uuid ( authn_request . uuid )
39
+
37
40
with_settings do |settings |
38
41
redirect ( authn_request . create ( settings , additional_params_for_authn_request ) )
39
42
end
40
43
end
41
44
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
+
42
53
def callback_phase
43
54
raise OmniAuth ::Strategies ::SAML ::ValidationError . new ( "SAML response missing" ) unless request . params [ "SAMLResponse" ]
44
55
Original file line number Diff line number Diff line change @@ -115,6 +115,29 @@ def post_xml(xml=:example_response, opts = {})
115
115
expect ( query [ 'SigAlg' ] ) . to eq XMLSecurity ::Document ::RSA_SHA256
116
116
end
117
117
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
118
141
end
119
142
120
143
describe 'POST /auth/saml/callback' do
You can’t perform that action at this time.
0 commit comments