Skip to content

Commit 586bf89

Browse files
committed
feat: Support for configurable IdP SLO session destruction
1 parent 958adef commit 586bf89

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ The service provider metadata used to ease configuration of the SAML SP in the I
8989
* `:idp_slo_target_url` - The URL to which the single logout request and response should
9090
be sent. This would be on the identity provider. Optional.
9191

92+
* `:idp_slo_session_destroy` - A proc that accepts up to two parameters (the rack environment, and the session),
93+
and performs whatever tasks are necessary to log out the current user from your application.
94+
See the example listed under "Single Logout." Defaults to calling `#clear` on the session. Optional.
95+
9296
* `:slo_default_relay_state` - The value to use as default `RelayState` for single log outs. The
9397
value can be a string, or a `Proc` (or other object responding to `call`). The `request`
9498
instance will be passed to this callable if it has an arity of 1. If the value is a string,
@@ -184,6 +188,18 @@ class SessionsController < Devise::SessionsController
184188
end
185189
```
186190

191+
By default, omniauth-saml attempts to log the current user out of your application by clearing the session.
192+
This may not be enough for some authentication solutions (e.g. [Clearance](https://github.com/thoughtbot/clearance/)).
193+
Instead, you may set the `:idp_slo_session_destroy` option to a proc that performs the necessary logout tasks.
194+
195+
Example `:idp_slo_session_destroy` setting for Clearance compatibility:
196+
197+
```ruby
198+
Rails.application.config.middleware.use OmniAuth::Builder do
199+
provider :saml, idp_slo_session_destroy: proc { |env, _session| env[:clearance].sign_out }, ...
200+
end
201+
```
202+
187203
## Authors
188204

189205
Authored by [Rajiv Aaron Manglani](http://www.rajivmanglani.com/), Raecoo Cao, Todd W Saxton, Ryan Wilcox, Steven Anderson, Nikos Dimitrakopoulos, Rudolf Vriend and [Bruno Pedro](http://brunopedro.com/).

lib/omniauth/strategies/saml.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def self.inherited(subclass)
2929
}
3030
option :slo_default_relay_state
3131
option :uid_attribute
32+
option :idp_slo_session_destroy, proc { |_env, session| session.clear }
3233

3334
def request_phase
3435
options[:assertion_consumer_service_url] ||= callback_url
@@ -230,7 +231,7 @@ def handle_logout_request(raw_request, settings)
230231
logout_request.name_id == session["saml_uid"]
231232

232233
# Actually log out this session
233-
session.clear
234+
options[:idp_slo_session_destroy].call @env, session
234235

235236
# Generate a response to the IdP.
236237
logout_request_id = logout_request.id

0 commit comments

Comments
 (0)