lib/warden-github/strategy.rb in warden-github-0.6.1 vs lib/warden-github/strategy.rb in warden-github-0.7.0
- old
+ new
@@ -8,16 +8,11 @@
def authenticate!
if params['code']
begin
api = api_for(params['code'])
- resp = api.get '/api/v2/json/user/show' 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(Yajl.load(user_info_for(api.token)), 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']
@@ -43,9 +38,13 @@
@oauth_proxy ||= Warden::Github::Oauth::Proxy.new(env['warden'].config[:github_client_id],
env['warden'].config[:github_secret],
env['warden'].config[:github_scopes],
env['warden'].config[:github_oauth_domain],
callback_url)
+ end
+
+ def user_info_for(token)
+ @user_info ||= RestClient.get("https://api.github.com/user", :params => {:access_token => token})
end
def callback_url
absolute_url(request, env['warden'].config[:github_callback_url], env['HTTP_X_FORWARDED_PROTO'])
end