lib/warden-github/strategy.rb in warden-github-0.0.9 vs lib/warden-github/strategy.rb in warden-github-0.1.0
- old
+ new
@@ -13,10 +13,11 @@
success!(Warden::Github::Oauth::User.new(user['user'], access_token.token))
rescue OAuth2::HTTPError
%(<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
private
@@ -39,18 +40,28 @@
env['warden'].config[:github_scopes],
callback_url)
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)
port_part = case request.scheme
when "http"
request.port == 80 ? "" : ":#{request.port}"
when "https"
request.port == 443 ? "" : ":#{request.port}"
end
"#{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