warden-github 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/warden-github.rb +1 -0
- data/lib/warden-github/proxy.rb +33 -0
- data/lib/warden-github/strategy.rb +19 -12
- data/lib/warden-github/user.rb +4 -2
- data/lib/warden-github/version.rb +1 -1
- metadata +5 -4
data/lib/warden-github.rb
CHANGED
@@ -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 =
|
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[
|
15
|
+
%(<p>Outdated ?code=#{params['code']}:</p><p>#{$!}</p><p><a href="/auth/github">Retry</a></p>)
|
16
16
|
end
|
17
17
|
else
|
18
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
data/lib/warden-github/user.rb
CHANGED
@@ -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
|
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
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-
|
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
|