Permalink
Browse files

support return_to automatically

  • Loading branch information...
atmos committed Jun 22, 2011
1 parent 076424b commit 4d8b200bce8c787a15a89f65585c6557095d8dc2
Showing with 21 additions and 3 deletions.
  1. +2 −0 .gitignore
  2. +12 −1 lib/warden-github/strategy.rb
  3. +1 −1 lib/warden-github/version.rb
  4. +5 −0 spec/app.rb
  5. +1 −1 warden-github.gemspec
View
@@ -3,3 +3,5 @@ coverage
pkg
.DS_Store
Gemfile.lock
+vendor/gems
+*.gem
@@ -15,6 +15,7 @@ def authenticate!
%(<p>Outdated ?code=#{params['code']}:</p><p>#{$!}</p><p><a href="/auth/github">Retry</a></p>)
end
else
+ env['rack.session']['return_to'] = env['REQUEST_URI']
throw(:halt, [ 302, {'Location' => authorize_url}, [ ]])
end
end
@@ -41,7 +42,7 @@ def oauth_proxy
end
def callback_url
- absolute_url(request, env['warden'].config[:github_callback_url])
+ absolute_url(request, env['warden'].config[:github_callback_url])
end
def absolute_url(request, suffix = nil)
@@ -54,3 +55,13 @@ def absolute_url(request, suffix = nil)
"#{request.scheme}://#{request.host}#{port_part}#{suffix}"
end
end
+
+Warden::Manager.after_authentication do |user, proxy, opts|
+ redirect_to = proxy.env['rack.session']['return_to']
+ proxy.env['rack.session'].delete('return_to')
+ if redirect_to
+ response = Rack::Response.new
+ response.redirect redirect_to
+ throw :warden, response.finish
+ end
+end
@@ -1,5 +1,5 @@
module Warden
module Github
- VERSION = "0.0.9"
+ VERSION = "0.1.0"
end
end
View
@@ -32,6 +32,11 @@ def user
"Hello There, #{user.name}!"
end
+ get '/redirect_to' do
+ ensure_authenticated
+ "Hello There, #{user.name}! return_to is working!"
+ end
+
get '/auth/github/callback' do
ensure_authenticated
redirect '/'
View
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "warden-github"
- s.version = "0.0.9"
+ s.version = "0.1.0"
s.platform = Gem::Platform::RUBY
s.authors = ["Corey Donohoe"]
s.email = ["atmos@atmos.org"]

0 comments on commit 4d8b200

Please sign in to comment.