sinatra_auth_github 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/auth/github.rb +22 -0
- data/sinatra_auth_github.gemspec +2 -1
- metadata +28 -12
data/lib/sinatra/auth/github.rb
CHANGED
@@ -85,6 +85,18 @@ module Sinatra
|
|
85
85
|
JSON.parse(github_raw_request(path))
|
86
86
|
end
|
87
87
|
|
88
|
+
# See if the user is a public member of the named organization
|
89
|
+
#
|
90
|
+
# name - the organization name
|
91
|
+
#
|
92
|
+
# Returns: true if the user is public access, false otherwise
|
93
|
+
def github_public_organization_access?(name)
|
94
|
+
orgs = github_request("orgs/#{name}/public_members")
|
95
|
+
orgs.map { |org| org["login"] }.include?(github_user.login)
|
96
|
+
rescue RestClient::Forbidden, RestClient::Unauthorized, RestClient::ResourceNotFound => e
|
97
|
+
false
|
98
|
+
end
|
99
|
+
|
88
100
|
# See if the user is a member of the named organization
|
89
101
|
#
|
90
102
|
# name - the organization name
|
@@ -114,6 +126,16 @@ module Sinatra
|
|
114
126
|
# name - the organization to test membership against
|
115
127
|
#
|
116
128
|
# Returns an execution halt if the user is not a member of the named org
|
129
|
+
def github_public_organization_authenticate!(name)
|
130
|
+
authenticate!
|
131
|
+
halt([401, "Unauthorized User"]) unless github_public_organization_access?(name)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Enforce user membership to the named organization if membership is publicized
|
135
|
+
#
|
136
|
+
# name - the organization to test membership against
|
137
|
+
#
|
138
|
+
# Returns an execution halt if the user is not a member of the named org
|
117
139
|
def github_organization_authenticate!(name)
|
118
140
|
authenticate!
|
119
141
|
halt([401, "Unauthorized User"]) unless github_organization_access?(name)
|
data/sinatra_auth_github.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "sinatra_auth_github"
|
6
|
-
s.version = "0.1.
|
6
|
+
s.version = "0.1.4"
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["Corey Donohoe"]
|
9
9
|
s.email = ["atmos@atmos.org"]
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency "rake"
|
21
21
|
s.add_development_dependency "rspec", "~>1.3.0"
|
22
22
|
s.add_development_dependency "shotgun"
|
23
|
+
s.add_development_dependency "ZenTest", "~>4.5.0"
|
23
24
|
s.add_development_dependency "bundler", "~>1.0"
|
24
25
|
s.add_development_dependency "randexp", "~>0.1.5"
|
25
26
|
s.add_development_dependency "rack-test", "~>0.5.3"
|
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
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: 2011-
|
18
|
+
date: 2011-09-20 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -110,9 +110,25 @@ dependencies:
|
|
110
110
|
type: :development
|
111
111
|
version_requirements: *id006
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
|
-
name:
|
113
|
+
name: ZenTest
|
114
114
|
prerelease: false
|
115
115
|
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ~>
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 43
|
121
|
+
segments:
|
122
|
+
- 4
|
123
|
+
- 5
|
124
|
+
- 0
|
125
|
+
version: 4.5.0
|
126
|
+
type: :development
|
127
|
+
version_requirements: *id007
|
128
|
+
- !ruby/object:Gem::Dependency
|
129
|
+
name: bundler
|
130
|
+
prerelease: false
|
131
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
116
132
|
none: false
|
117
133
|
requirements:
|
118
134
|
- - ~>
|
@@ -123,11 +139,11 @@ dependencies:
|
|
123
139
|
- 0
|
124
140
|
version: "1.0"
|
125
141
|
type: :development
|
126
|
-
version_requirements: *
|
142
|
+
version_requirements: *id008
|
127
143
|
- !ruby/object:Gem::Dependency
|
128
144
|
name: randexp
|
129
145
|
prerelease: false
|
130
|
-
requirement: &
|
146
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
131
147
|
none: false
|
132
148
|
requirements:
|
133
149
|
- - ~>
|
@@ -139,11 +155,11 @@ dependencies:
|
|
139
155
|
- 5
|
140
156
|
version: 0.1.5
|
141
157
|
type: :development
|
142
|
-
version_requirements: *
|
158
|
+
version_requirements: *id009
|
143
159
|
- !ruby/object:Gem::Dependency
|
144
160
|
name: rack-test
|
145
161
|
prerelease: false
|
146
|
-
requirement: &
|
162
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
147
163
|
none: false
|
148
164
|
requirements:
|
149
165
|
- - ~>
|
@@ -155,11 +171,11 @@ dependencies:
|
|
155
171
|
- 3
|
156
172
|
version: 0.5.3
|
157
173
|
type: :development
|
158
|
-
version_requirements: *
|
174
|
+
version_requirements: *id010
|
159
175
|
- !ruby/object:Gem::Dependency
|
160
176
|
name: ruby-debug
|
161
177
|
prerelease: false
|
162
|
-
requirement: &
|
178
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
163
179
|
none: false
|
164
180
|
requirements:
|
165
181
|
- - ">="
|
@@ -169,7 +185,7 @@ dependencies:
|
|
169
185
|
- 0
|
170
186
|
version: "0"
|
171
187
|
type: :development
|
172
|
-
version_requirements: *
|
188
|
+
version_requirements: *id011
|
173
189
|
description: A sinatra extension for easy oauth integration with github
|
174
190
|
email:
|
175
191
|
- atmos@atmos.org
|