lib/warden-github/strategy.rb in warden-github-0.4.0 vs lib/warden-github/strategy.rb in warden-github-0.4.1
- old
+ new
@@ -8,16 +8,16 @@
def authenticate!
if params['code']
begin
api = api_for(params['code'])
- resp = api.get '/api/v2/json/user/show' do |request|
+ resp = api.get '/api/v3/user' do |request|
request.params['access_token'] = api.token
end.body
user = JSON.load(resp)
- success!(Warden::Github::Oauth::User.new(user['user'], api.token))
+ success!(Warden::Github::Oauth::User.new(user, api.token))
rescue OAuth2::Error
%(<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']
@@ -46,18 +46,18 @@
env['warden'].config[:github_oauth_domain],
callback_url)
end
def callback_url
- absolute_url(request, env['warden'].config[:github_callback_url])
+ absolute_url(request, env['warden'].config[:github_callback_url], env['HTTP_X_FORWARDED_PROTO'])
end
- def absolute_url(request, suffix = nil)
+ def absolute_url(request, suffix = nil, proto = "http")
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}"
+ "#{proto}://#{request.host}#{port_part}#{suffix}"
end
end