lib/warden-github/strategy.rb in warden-github-0.2.1 vs lib/warden-github/strategy.rb in warden-github-0.3.0
- old
+ new
@@ -6,13 +6,18 @@
end
def authenticate!
if params['code']
begin
- access_token = access_token_for(params['code'])
- user = JSON.parse(access_token.get('/api/v2/json/user/show'))
- success!(Warden::Github::Oauth::User.new(user['user'], access_token.token))
+ 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))
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']
@@ -28,11 +33,11 @@
def authorize_url
oauth_proxy.authorize_url
end
- def access_token_for(code)
- oauth_proxy.access_token_for(code)
+ def api_for(code)
+ oauth_proxy.api_for(code)
end
def oauth_proxy
@oauth_proxy ||= Warden::Github::Oauth::Proxy.new(env['warden'].config[:github_client_id],
env['warden'].config[:github_secret],