warden-github 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,4 +11,4 @@ The Extension in Action
11
11
  =======================
12
12
  % gem install bundler
13
13
  % bundle install
14
- % GITHUB_CLIENT_ID="<from GH>" GITHUB_CLIENT_SECRET="<from GH>" bundle exec rackup
14
+ % GITHUB_CLIENT_ID="<from GH>" GITHUB_CLIENT_SECRET="<from GH>" bundle exec rackup -p9393 -E none
@@ -18,26 +18,22 @@ module Warden
18
18
 
19
19
  def client
20
20
  @client ||= OAuth2::Client.new(@client_id, @secret,
21
- :ssl => ssl_options,
22
- :site => 'https://github.com',
23
- :authorize_path => '/login/oauth/authorize',
24
- :access_token_path => '/login/oauth/access_token')
21
+ :ssl => ssl_options,
22
+ :site => 'https://github.com',
23
+ :token_url => '/login/oauth/access_token',
24
+ :authorize_url => '/login/oauth/authorize')
25
25
  end
26
26
 
27
- def access_token_for(code)
28
- web_server.get_token(code, :redirect_uri => callback_url)
27
+ def api_for(code)
28
+ client.auth_code.get_token(code, :redirect_uri => callback_url)
29
29
  end
30
30
 
31
31
  def authorize_url
32
- web_server.authorize_url(
32
+ client.auth_code.authorize_url(
33
33
  :scope => scopes,
34
34
  :redirect_uri => callback_url
35
35
  )
36
36
  end
37
-
38
- def web_server
39
- client.auth_code
40
- end
41
37
  end
42
38
  end
43
39
  end
@@ -8,9 +8,14 @@ Warden::Strategies.add(:github) do
8
8
  def authenticate!
9
9
  if params['code']
10
10
  begin
11
- access_token = access_token_for(params['code'])
12
- user = JSON.parse(access_token.get('/api/v2/json/user/show'))
13
- success!(Warden::Github::Oauth::User.new(user['user'], access_token.token))
11
+ api = api_for(params['code'])
12
+
13
+ resp = api.get '/api/v2/json/user/show' do |request|
14
+ request.params['access_token'] = api.token
15
+ end.body
16
+
17
+ user = JSON.load(resp)
18
+ success!(Warden::Github::Oauth::User.new(user['user'], api.token))
14
19
  rescue OAuth2::Error
15
20
  %(<p>Outdated ?code=#{params['code']}:</p><p>#{$!}</p><p><a href="/auth/github">Retry</a></p>)
16
21
  end
@@ -30,8 +35,8 @@ Warden::Strategies.add(:github) do
30
35
  oauth_proxy.authorize_url
31
36
  end
32
37
 
33
- def access_token_for(code)
34
- oauth_proxy.access_token_for(code)
38
+ def api_for(code)
39
+ oauth_proxy.api_for(code)
35
40
  end
36
41
 
37
42
  def oauth_proxy
@@ -1,5 +1,5 @@
1
1
  module Warden
2
2
  module Github
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/spec/app.rb CHANGED
@@ -2,7 +2,7 @@ require 'sinatra'
2
2
 
3
3
  module Example
4
4
  class App < Sinatra::Base
5
- use Rack::Session::Cookie, :key => 'rack.session',
5
+ use Rack::Session::Cookie, :key => 'rack.session',
6
6
  :secret => 'warden-github-auth',
7
7
  :expire_after => 2592000
8
8
  enable :raise_errors
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "warden", "~>1.0.4"
20
20
  s.add_dependency "oauth2", "~>0.5.2"
21
21
 
22
- s.add_development_dependency "rack", "~>1.3.0"
22
+ s.add_development_dependency "rack", "~>1.4.0"
23
23
  s.add_development_dependency "rake"
24
24
  s.add_development_dependency "rspec", "~>1.3.0"
25
25
  s.add_development_dependency "webrat"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warden-github
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Corey Donohoe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-07 00:00:00 -08:00
18
+ date: 2012-01-08 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,12 +73,12 @@ dependencies:
73
73
  requirements:
74
74
  - - ~>
75
75
  - !ruby/object:Gem::Version
76
- hash: 27
76
+ hash: 7
77
77
  segments:
78
78
  - 1
79
- - 3
79
+ - 4
80
80
  - 0
81
- version: 1.3.0
81
+ version: 1.4.0
82
82
  type: :development
83
83
  version_requirements: *id004
84
84
  - !ruby/object:Gem::Dependency