sinatra_auth_github 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/auth/github.rb +5 -23
- data/lib/sinatra/auth/github/version.rb +1 -1
- data/sinatra_auth_github.gemspec +1 -1
- data/spec/app.rb +11 -6
- metadata +7 -7
data/lib/sinatra/auth/github.rb
CHANGED
@@ -58,15 +58,6 @@ module Sinatra
|
|
58
58
|
warden.user
|
59
59
|
end
|
60
60
|
|
61
|
-
def github_api_uri
|
62
|
-
if ENV['GITHUB_OAUTH_API_DOMAIN']
|
63
|
-
ENV['GITHUB_OAUTH_API_DOMAIN']
|
64
|
-
else
|
65
|
-
uri = URI.parse(env['warden'].config[:github_oauth_domain])
|
66
|
-
"#{uri.scheme}://api.#{uri.host}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
61
|
# Send a V3 API GET request to path
|
71
62
|
#
|
72
63
|
# path - the path on api.github.com to hit
|
@@ -77,7 +68,7 @@ module Sinatra
|
|
77
68
|
# github_raw_request("/user")
|
78
69
|
# # => RestClient::Response
|
79
70
|
def github_raw_request(path)
|
80
|
-
|
71
|
+
github_user.github_raw_request(path)
|
81
72
|
end
|
82
73
|
|
83
74
|
# Send a V3 API GET request to path and parse the response body
|
@@ -90,7 +81,7 @@ module Sinatra
|
|
90
81
|
# github_request("/user")
|
91
82
|
# # => { 'login' => 'atmos', ... }
|
92
83
|
def github_request(path)
|
93
|
-
|
84
|
+
github_user.github_request(path)
|
94
85
|
end
|
95
86
|
|
96
87
|
# See if the user is a public member of the named organization
|
@@ -99,10 +90,7 @@ module Sinatra
|
|
99
90
|
#
|
100
91
|
# Returns: true if the user is public access, false otherwise
|
101
92
|
def github_public_organization_access?(name)
|
102
|
-
|
103
|
-
orgs.map { |org| org["login"] }.include?(github_user.login)
|
104
|
-
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
105
|
-
false
|
93
|
+
github_user.publicized_organization_member?(name)
|
106
94
|
end
|
107
95
|
|
108
96
|
# See if the user is a member of the named organization
|
@@ -111,10 +99,7 @@ module Sinatra
|
|
111
99
|
#
|
112
100
|
# Returns: true if the user has access, false otherwise
|
113
101
|
def github_organization_access?(name)
|
114
|
-
|
115
|
-
orgs.map { |org| org["login"] }.include?(github_user.login)
|
116
|
-
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
117
|
-
false
|
102
|
+
github_user.organization_member?(name)
|
118
103
|
end
|
119
104
|
|
120
105
|
# See if the user is a member of the team id
|
@@ -123,10 +108,7 @@ module Sinatra
|
|
123
108
|
#
|
124
109
|
# Returns: true if the user has access, false otherwise
|
125
110
|
def github_team_access?(team_id)
|
126
|
-
|
127
|
-
members.map { |user| user["login"] }.include?(github_user.login)
|
128
|
-
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
129
|
-
false
|
111
|
+
github_user.team_member?(team_id)
|
130
112
|
end
|
131
113
|
|
132
114
|
# Enforce user membership to the named organization
|
data/sinatra_auth_github.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.add_dependency "sinatra", "~>1.0"
|
18
18
|
s.add_dependency "yajl-ruby", "~>1.1"
|
19
19
|
s.add_dependency "rest-client", "~>1.6.1"
|
20
|
-
s.add_dependency "warden-github", "~>0.
|
20
|
+
s.add_dependency "warden-github", "~>0.5.0"
|
21
21
|
|
22
22
|
s.add_development_dependency "rake"
|
23
23
|
s.add_development_dependency "rspec", "~>2.0.0"
|
data/spec/app.rb
CHANGED
@@ -6,6 +6,7 @@ module Example
|
|
6
6
|
enable :sessions
|
7
7
|
|
8
8
|
set :github_options, {
|
9
|
+
:scopes => "user",
|
9
10
|
:secret => ENV['GITHUB_CLIENT_SECRET'],
|
10
11
|
:client_id => ENV['GITHUB_CLIENT_ID'],
|
11
12
|
}
|
@@ -24,15 +25,19 @@ module Example
|
|
24
25
|
end
|
25
26
|
|
26
27
|
get '/orgs/:id' do
|
27
|
-
|
28
|
+
github_organization_authenticate!(params['id'])
|
28
29
|
"Hello There, #{github_user.name}! You have access to the #{params['id']} organization."
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
get '/publicized_orgs/:id' do
|
33
|
+
github_publicized_organization_authenticate!(params['id'])
|
34
|
+
"Hello There, #{github_user.name}! You are publicly a member of the #{params['id']} organization."
|
35
|
+
end
|
36
|
+
|
37
|
+
get '/teams/:id' do
|
38
|
+
github_team_authenticate!(params['id'])
|
39
|
+
"Hello There, #{github_user.name}! You have access to the #{params['id']} team."
|
40
|
+
end
|
36
41
|
|
37
42
|
get '/logout' do
|
38
43
|
logout!
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra_auth_github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 4
|
10
|
+
version: 0.5.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Corey Donohoe
|
@@ -72,12 +72,12 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
hash:
|
75
|
+
hash: 11
|
76
76
|
segments:
|
77
77
|
- 0
|
78
|
-
-
|
79
|
-
-
|
80
|
-
version: 0.
|
78
|
+
- 5
|
79
|
+
- 0
|
80
|
+
version: 0.5.0
|
81
81
|
type: :runtime
|
82
82
|
version_requirements: *id004
|
83
83
|
- !ruby/object:Gem::Dependency
|