warden-github 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/warden-github.rb CHANGED
@@ -9,5 +9,6 @@ module Warden
9
9
  end
10
10
 
11
11
  require 'warden-github/user'
12
+ require 'warden-github/proxy'
12
13
  require 'warden-github/version'
13
14
  require 'warden-github/strategy'
@@ -0,0 +1,33 @@
1
+ module Warden
2
+ module Github
3
+ module Oauth
4
+ class Proxy
5
+ def initialize(client_id, secret, callback_url)
6
+ @client_id, @secret, @callback_url = client_id, secret, callback_url
7
+ end
8
+
9
+ def client
10
+ @client ||= OAuth2::Client.new(@client_id, @secret,
11
+ :site => 'https://github.com',
12
+ :authorize_path => '/login/oauth/authorize',
13
+ :access_token_path => '/login/oauth/access_token')
14
+ end
15
+
16
+ def access_token_for(code)
17
+ web_server.get_access_token(code, :redirect_uri => @callback_url)
18
+ end
19
+
20
+ def authorize_url
21
+ web_server.authorize_url(
22
+ :scope => 'email,offline_access',
23
+ :redirect_uri => @callback_url
24
+ )
25
+ end
26
+
27
+ def web_server
28
+ client.web_server
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -8,28 +8,35 @@ Warden::Strategies.add(:github) do
8
8
  def authenticate!
9
9
  if params['code']
10
10
  begin
11
- access_token = oauth_client.web_server.get_access_token(params['code'], :redirect_uri => callback_url)
11
+ access_token = access_token_for(params['code'])
12
12
  user = JSON.parse(access_token.get('/api/v2/json/user/show'))
13
13
  success!(Warden::Github::Oauth::User.new(user['user'], access_token.token))
14
14
  rescue OAuth2::HTTPError
15
- %(<p>Outdated ?code=#{params[:code]}:</p><p>#{$!}</p><p><a href="/auth/github">Retry</a></p>)
15
+ %(<p>Outdated ?code=#{params['code']}:</p><p>#{$!}</p><p><a href="/auth/github">Retry</a></p>)
16
16
  end
17
17
  else
18
- url = oauth_client.web_server.authorize_url(
19
- :scope => 'email,offline_access',
20
- :redirect_uri => callback_url
21
- )
22
- throw(:halt, [ 302, {'Location' => url}, [ ]])
18
+ throw(:halt, [ 302, {'Location' => authorize_url}, [ ]])
23
19
  end
24
20
  end
25
21
 
26
22
  private
23
+
27
24
  def oauth_client
28
- OAuth2::Client.new(env['warden'].config[:github_client_id],
29
- env['warden'].config[:github_secret],
30
- :site => 'https://github.com',
31
- :authorize_path => '/login/oauth/authorize',
32
- :access_token_path => '/login/oauth/access_token')
25
+ oauth_proxy.client
26
+ end
27
+
28
+ def authorize_url
29
+ oauth_proxy.authorize_url
30
+ end
31
+
32
+ def access_token_for(code)
33
+ oauth_proxy.access_token_for(code)
34
+ end
35
+
36
+ def oauth_proxy
37
+ @oauth_proxy ||= Warden::Github::Oauth::Proxy.new(env['warden'].config[:github_client_id],
38
+ env['warden'].config[:github_secret],
39
+ callback_url)
33
40
  end
34
41
 
35
42
  def callback_url
@@ -2,8 +2,6 @@ module Warden
2
2
  module Github
3
3
  module Oauth
4
4
  class User < Struct.new(:attribs, :token)
5
- extend Forwardable
6
-
7
5
  def name
8
6
  attribs['name']
9
7
  end
@@ -11,6 +9,10 @@ module Warden
11
9
  def email
12
10
  attribs['email']
13
11
  end
12
+
13
+ def company
14
+ attribs['company']
15
+ end
14
16
  end
15
17
  end
16
18
  end
@@ -1,5 +1,5 @@
1
1
  module Warden
2
2
  module Github
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
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: 2010-06-01 00:00:00 -07:00
18
+ date: 2010-06-03 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,7 @@ extra_rdoc_files:
76
76
  files:
77
77
  - LICENSE
78
78
  - README.md
79
+ - lib/warden-github/proxy.rb
79
80
  - lib/warden-github/strategy.rb
80
81
  - lib/warden-github/user.rb
81
82
  - lib/warden-github/version.rb