NoamB/sorcery — Issue #231: redirect_back_or_to does not work with externals
Author: yagitoshiro
Created: 2012-03-04 04:11:28+00:00
State: open

I made a small fix that enable redirect_back_or_to with externals. I'm not sure this makes sense so please take a look at it before I make a pull request.

First you have to escape redirect_to_url before reset_session:

```ruby
diff --git a/lib/sorcery/controller/submodules/external.rb b/lib/sorcery/control
index 63477d2..4080915 100644
--- a/lib/sorcery/controller/submodules/external.rb
+++ b/lib/sorcery/controller/submodules/external.rb
@@ -46,7 +46,9 @@ module Sorcery
@provider.process_callback(params,session)
@user_hash = @provider.get_user_hash
if user = user_class.load_from_provider(provider,@user_hash[:uid].t
+ return_to_url = session[:return_to_url]
reset_session
+ session[:return_to_url] = return_to_url
auto_login(user)
user
end
```

Second, prevent oauth related requests from being stored in session.

app/controllers/application_controller.rb

```ruby
protected

def session_store_url
if request.method == "GET"
session[:return_to_url] = request.url
end
end
```

app/controllers/oauths_controller.rb

```ruby
class OauthsController < ApplicationController
skip_before_filter :require_login, :session_store_url
```

app/controllers/user_sessions_controller.rb

```ruby
class UserSessionsController < ApplicationController
skip_before_filter :session_store_url
```

Looks like these fix works somehow but it breaks compatibility and even worse you have to take care of which requests are to be stored all by yourself. Do you have any idea?