simple_admin_auth 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile.lock +81 -77
- data/README.md +26 -1
- data/gemfiles/rack1.5.gemfile.lock +6 -6
- data/gemfiles/rails3.2.gemfile.lock +2 -2
- data/gemfiles/rails4.0.gemfile +11 -0
- data/gemfiles/rails4.0.gemfile.lock +139 -0
- data/gemfiles/rails4.1.gemfile +11 -0
- data/gemfiles/rails4.1.gemfile.lock +145 -0
- data/lib/simple_admin_auth/application.rb +1 -1
- data/lib/simple_admin_auth/authenticated.rb +15 -1
- data/lib/simple_admin_auth/configuration.rb +7 -0
- data/lib/simple_admin_auth/version.rb +1 -1
- data/lib/simple_admin_auth.rb +1 -0
- data/spec/application_spec.rb +4 -4
- data/spec/authenticate_spec.rb +54 -0
- data/spec/spec_helper.rb +4 -2
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a986cc9e5ccad0067a27efcb24d31decc3e7a12
|
4
|
+
data.tar.gz: fd798bfdf54add7433fa9310bf2c274e82b0446c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e077f215921a2a723d8f27dae8f91144f683921e020c438d0bde2fc6c0bb300a802ca4040e85931e1ed475ac6da67ca663710cc59907147b060b5a361d9ee429
|
7
|
+
data.tar.gz: a5e16f8d88a326d973e240e1960371b274225f36a3b45b737972fc97da1ddba10cb1d61bdb9a8e7403bb469d463968259e5340cc563a64f81a8b917e5b023756
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -8,12 +8,12 @@ PATH
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionmailer (3.2.
|
12
|
-
actionpack (= 3.2.
|
13
|
-
mail (~> 2.5.
|
14
|
-
actionpack (3.2.
|
15
|
-
activemodel (= 3.2.
|
16
|
-
activesupport (= 3.2.
|
11
|
+
actionmailer (3.2.19)
|
12
|
+
actionpack (= 3.2.19)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (3.2.19)
|
15
|
+
activemodel (= 3.2.19)
|
16
|
+
activesupport (= 3.2.19)
|
17
17
|
builder (~> 3.0.0)
|
18
18
|
erubis (~> 2.7.0)
|
19
19
|
journey (~> 1.0.4)
|
@@ -21,113 +21,117 @@ GEM
|
|
21
21
|
rack-cache (~> 1.2)
|
22
22
|
rack-test (~> 0.6.1)
|
23
23
|
sprockets (~> 2.2.1)
|
24
|
-
activemodel (3.2.
|
25
|
-
activesupport (= 3.2.
|
24
|
+
activemodel (3.2.19)
|
25
|
+
activesupport (= 3.2.19)
|
26
26
|
builder (~> 3.0.0)
|
27
|
-
activerecord (3.2.
|
28
|
-
activemodel (= 3.2.
|
29
|
-
activesupport (= 3.2.
|
27
|
+
activerecord (3.2.19)
|
28
|
+
activemodel (= 3.2.19)
|
29
|
+
activesupport (= 3.2.19)
|
30
30
|
arel (~> 3.0.2)
|
31
31
|
tzinfo (~> 0.3.29)
|
32
|
-
activeresource (3.2.
|
33
|
-
activemodel (= 3.2.
|
34
|
-
activesupport (= 3.2.
|
35
|
-
activesupport (3.2.
|
36
|
-
i18n (
|
32
|
+
activeresource (3.2.19)
|
33
|
+
activemodel (= 3.2.19)
|
34
|
+
activesupport (= 3.2.19)
|
35
|
+
activesupport (3.2.19)
|
36
|
+
i18n (~> 0.6, >= 0.6.4)
|
37
37
|
multi_json (~> 1.0)
|
38
|
-
arel (3.0.
|
38
|
+
arel (3.0.3)
|
39
39
|
builder (3.0.4)
|
40
40
|
daemons (1.1.9)
|
41
|
-
diff-lcs (1.2.
|
41
|
+
diff-lcs (1.2.5)
|
42
42
|
erubis (2.7.0)
|
43
43
|
eventmachine (1.0.3)
|
44
|
-
faraday (0.
|
45
|
-
multipart-post (
|
46
|
-
hashie (
|
47
|
-
hike (1.2.
|
48
|
-
|
49
|
-
i18n (0.6.1)
|
44
|
+
faraday (0.9.0)
|
45
|
+
multipart-post (>= 1.2, < 3)
|
46
|
+
hashie (3.3.1)
|
47
|
+
hike (1.2.3)
|
48
|
+
i18n (0.6.11)
|
50
49
|
journey (1.0.4)
|
51
|
-
json (1.
|
52
|
-
jwt (0.
|
53
|
-
|
54
|
-
mail (2.5.3)
|
55
|
-
i18n (>= 0.4.0)
|
50
|
+
json (1.8.1)
|
51
|
+
jwt (1.0.0)
|
52
|
+
mail (2.5.4)
|
56
53
|
mime-types (~> 1.16)
|
57
54
|
treetop (~> 1.4.8)
|
58
|
-
mime-types (1.
|
59
|
-
multi_json (1.
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
jwt (~>
|
65
|
-
multi_json (~> 1.
|
55
|
+
mime-types (1.25.1)
|
56
|
+
multi_json (1.10.1)
|
57
|
+
multi_xml (0.5.5)
|
58
|
+
multipart-post (2.0.0)
|
59
|
+
oauth2 (1.0.0)
|
60
|
+
faraday (>= 0.8, < 0.10)
|
61
|
+
jwt (~> 1.0)
|
62
|
+
multi_json (~> 1.3)
|
63
|
+
multi_xml (~> 0.5)
|
66
64
|
rack (~> 1.2)
|
67
|
-
omniauth (1.
|
68
|
-
hashie (>= 1.2, <
|
69
|
-
rack
|
70
|
-
omniauth-google-oauth2 (0.
|
71
|
-
omniauth (
|
72
|
-
omniauth-oauth2
|
73
|
-
omniauth-oauth2 (1.
|
74
|
-
|
75
|
-
|
76
|
-
|
65
|
+
omniauth (1.2.2)
|
66
|
+
hashie (>= 1.2, < 4)
|
67
|
+
rack (~> 1.0)
|
68
|
+
omniauth-google-oauth2 (0.2.5)
|
69
|
+
omniauth (> 1.0)
|
70
|
+
omniauth-oauth2 (~> 1.1)
|
71
|
+
omniauth-oauth2 (1.2.0)
|
72
|
+
faraday (>= 0.8, < 0.10)
|
73
|
+
multi_json (~> 1.3)
|
74
|
+
oauth2 (~> 1.0)
|
75
|
+
omniauth (~> 1.2)
|
76
|
+
polyglot (0.3.5)
|
77
77
|
rack (1.4.5)
|
78
78
|
rack-cache (1.2)
|
79
79
|
rack (>= 0.4)
|
80
|
-
rack-protection (1.5.
|
80
|
+
rack-protection (1.5.3)
|
81
81
|
rack
|
82
|
-
rack-ssl (1.3.
|
82
|
+
rack-ssl (1.3.4)
|
83
83
|
rack
|
84
84
|
rack-test (0.6.2)
|
85
85
|
rack (>= 1.0)
|
86
|
-
rails (3.2.
|
87
|
-
actionmailer (= 3.2.
|
88
|
-
actionpack (= 3.2.
|
89
|
-
activerecord (= 3.2.
|
90
|
-
activeresource (= 3.2.
|
91
|
-
activesupport (= 3.2.
|
86
|
+
rails (3.2.19)
|
87
|
+
actionmailer (= 3.2.19)
|
88
|
+
actionpack (= 3.2.19)
|
89
|
+
activerecord (= 3.2.19)
|
90
|
+
activeresource (= 3.2.19)
|
91
|
+
activesupport (= 3.2.19)
|
92
92
|
bundler (~> 1.0)
|
93
|
-
railties (= 3.2.
|
94
|
-
railties (3.2.
|
95
|
-
actionpack (= 3.2.
|
96
|
-
activesupport (= 3.2.
|
93
|
+
railties (= 3.2.19)
|
94
|
+
railties (3.2.19)
|
95
|
+
actionpack (= 3.2.19)
|
96
|
+
activesupport (= 3.2.19)
|
97
97
|
rack-ssl (~> 1.3.2)
|
98
98
|
rake (>= 0.8.7)
|
99
99
|
rdoc (~> 3.4)
|
100
100
|
thor (>= 0.14.6, < 2.0)
|
101
|
-
rake (10.
|
101
|
+
rake (10.3.2)
|
102
102
|
rdoc (3.12.2)
|
103
103
|
json (~> 1.4)
|
104
|
-
rspec (
|
105
|
-
rspec-core (~>
|
106
|
-
rspec-expectations (~>
|
107
|
-
rspec-mocks (~>
|
108
|
-
rspec-core (
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
104
|
+
rspec (3.1.0)
|
105
|
+
rspec-core (~> 3.1.0)
|
106
|
+
rspec-expectations (~> 3.1.0)
|
107
|
+
rspec-mocks (~> 3.1.0)
|
108
|
+
rspec-core (3.1.1)
|
109
|
+
rspec-support (~> 3.1.0)
|
110
|
+
rspec-expectations (3.1.0)
|
111
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
112
|
+
rspec-support (~> 3.1.0)
|
113
|
+
rspec-mocks (3.1.0)
|
114
|
+
rspec-support (~> 3.1.0)
|
115
|
+
rspec-support (3.1.0)
|
116
|
+
sinatra (1.4.5)
|
113
117
|
rack (~> 1.4)
|
114
|
-
rack-protection (~> 1.
|
115
|
-
tilt (~> 1.3, >= 1.3.
|
118
|
+
rack-protection (~> 1.4)
|
119
|
+
tilt (~> 1.3, >= 1.3.4)
|
116
120
|
sprockets (2.2.2)
|
117
121
|
hike (~> 1.2)
|
118
122
|
multi_json (~> 1.0)
|
119
123
|
rack (~> 1.0)
|
120
124
|
tilt (~> 1.1, != 1.3.0)
|
121
|
-
thin (1.
|
125
|
+
thin (1.6.2)
|
122
126
|
daemons (>= 1.0.9)
|
123
|
-
eventmachine (>= 0.
|
127
|
+
eventmachine (>= 1.0.0)
|
124
128
|
rack (>= 1.0.0)
|
125
|
-
thor (0.
|
126
|
-
tilt (1.4.
|
127
|
-
treetop (1.4.
|
129
|
+
thor (0.19.1)
|
130
|
+
tilt (1.4.1)
|
131
|
+
treetop (1.4.15)
|
128
132
|
polyglot
|
129
133
|
polyglot (>= 0.3.1)
|
130
|
-
tzinfo (0.3.
|
134
|
+
tzinfo (0.3.41)
|
131
135
|
|
132
136
|
PLATFORMS
|
133
137
|
ruby
|
data/README.md
CHANGED
@@ -31,9 +31,13 @@ Create an `config/initializers/admin_auth.rb` configuring your domain:
|
|
31
31
|
Rails.application.config.middleware.use SimpleAdminAuth::Builder do
|
32
32
|
# The name must be `admin`
|
33
33
|
provider :google_oauth2, 'YOUR_KEY', 'YOUR_SECRET', name: 'admin',
|
34
|
-
access_type: 'online', hd: '
|
34
|
+
access_type: 'online', hd: 'example.com', approval_prompt: 'auto'
|
35
35
|
end
|
36
36
|
|
37
|
+
If you would like to white list emails in your domain add the following:
|
38
|
+
|
39
|
+
SimpleAdminAuth::Configuration.email_white_list = ['admin@example.com', 'john@example.com']
|
40
|
+
|
37
41
|
Protect any routes that require authentication:
|
38
42
|
|
39
43
|
constraints SimpleAdminAuth::Authenticate do
|
@@ -100,8 +104,29 @@ Use this in the initializer:
|
|
100
104
|
|
101
105
|
Rack/Sinatra apps may be adapted similarly.
|
102
106
|
|
107
|
+
## Using in specific actions
|
108
|
+
|
109
|
+
The recommended method is to enable the authentication for a group of routes in routes.rb, or as middleware for a
|
110
|
+
specific Rack application. If however you need to use it for a specific page only, you can do the following:
|
111
|
+
|
112
|
+
|
113
|
+
if !request.session[:admin_user].nil?
|
114
|
+
true
|
115
|
+
else
|
116
|
+
request.session[:admin_login_return_url] = request.url
|
117
|
+
raise SimpleAdminAuth::RedirectException.new('/auth/admin/login')
|
118
|
+
end
|
119
|
+
|
120
|
+
In a Sinatra app, use `session` instead of `request.session`.
|
121
|
+
|
122
|
+
Note that this relies on internal behaviour of this gem, and might not be compatible with future versions.
|
123
|
+
|
103
124
|
## Changelog
|
104
125
|
|
126
|
+
### 0.1.1
|
127
|
+
|
128
|
+
* Allow whitelisting of emails. Contributed by @drubin.
|
129
|
+
|
105
130
|
### 0.1.0
|
106
131
|
|
107
132
|
* Recommend OAuth2 instead of OpenID.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
|
-
remote:
|
2
|
+
remote: ../
|
3
3
|
specs:
|
4
|
-
simple_admin_auth (0.0
|
4
|
+
simple_admin_auth (0.1.0)
|
5
5
|
omniauth
|
6
6
|
sinatra
|
7
7
|
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
oauth2 (~> 0.8.0)
|
36
36
|
omniauth (~> 1.0)
|
37
37
|
rack (1.5.2)
|
38
|
-
rack-protection (1.5.
|
38
|
+
rack-protection (1.5.3)
|
39
39
|
rack
|
40
40
|
rack-test (0.6.2)
|
41
41
|
rack (>= 1.0)
|
@@ -48,15 +48,15 @@ GEM
|
|
48
48
|
rspec-expectations (2.13.0)
|
49
49
|
diff-lcs (>= 1.1.3, < 2.0)
|
50
50
|
rspec-mocks (2.13.1)
|
51
|
-
sinatra (1.4.
|
52
|
-
rack (~> 1.
|
51
|
+
sinatra (1.4.5)
|
52
|
+
rack (~> 1.4)
|
53
53
|
rack-protection (~> 1.4)
|
54
54
|
tilt (~> 1.3, >= 1.3.4)
|
55
55
|
thin (1.5.1)
|
56
56
|
daemons (>= 1.0.9)
|
57
57
|
eventmachine (>= 0.12.6)
|
58
58
|
rack (>= 1.0.0)
|
59
|
-
tilt (1.4.
|
59
|
+
tilt (1.4.1)
|
60
60
|
|
61
61
|
PLATFORMS
|
62
62
|
ruby
|
@@ -0,0 +1,139 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
simple_admin_auth (0.1.0)
|
5
|
+
omniauth
|
6
|
+
sinatra
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.0.9)
|
12
|
+
actionpack (= 4.0.9)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (4.0.9)
|
15
|
+
activesupport (= 4.0.9)
|
16
|
+
builder (~> 3.1.0)
|
17
|
+
erubis (~> 2.7.0)
|
18
|
+
rack (~> 1.5.2)
|
19
|
+
rack-test (~> 0.6.2)
|
20
|
+
activemodel (4.0.9)
|
21
|
+
activesupport (= 4.0.9)
|
22
|
+
builder (~> 3.1.0)
|
23
|
+
activerecord (4.0.9)
|
24
|
+
activemodel (= 4.0.9)
|
25
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
26
|
+
activesupport (= 4.0.9)
|
27
|
+
arel (~> 4.0.0)
|
28
|
+
activerecord-deprecated_finders (1.0.3)
|
29
|
+
activesupport (4.0.9)
|
30
|
+
i18n (~> 0.6, >= 0.6.9)
|
31
|
+
minitest (~> 4.2)
|
32
|
+
multi_json (~> 1.3)
|
33
|
+
thread_safe (~> 0.1)
|
34
|
+
tzinfo (~> 0.3.37)
|
35
|
+
arel (4.0.2)
|
36
|
+
builder (3.1.4)
|
37
|
+
daemons (1.1.9)
|
38
|
+
diff-lcs (1.2.5)
|
39
|
+
erubis (2.7.0)
|
40
|
+
eventmachine (1.0.3)
|
41
|
+
faraday (0.9.0)
|
42
|
+
multipart-post (>= 1.2, < 3)
|
43
|
+
hashie (3.3.1)
|
44
|
+
hike (1.2.3)
|
45
|
+
i18n (0.6.11)
|
46
|
+
jwt (1.0.0)
|
47
|
+
mail (2.5.4)
|
48
|
+
mime-types (~> 1.16)
|
49
|
+
treetop (~> 1.4.8)
|
50
|
+
mime-types (1.25.1)
|
51
|
+
minitest (4.7.5)
|
52
|
+
multi_json (1.10.1)
|
53
|
+
multi_xml (0.5.5)
|
54
|
+
multipart-post (2.0.0)
|
55
|
+
oauth2 (1.0.0)
|
56
|
+
faraday (>= 0.8, < 0.10)
|
57
|
+
jwt (~> 1.0)
|
58
|
+
multi_json (~> 1.3)
|
59
|
+
multi_xml (~> 0.5)
|
60
|
+
rack (~> 1.2)
|
61
|
+
omniauth (1.2.2)
|
62
|
+
hashie (>= 1.2, < 4)
|
63
|
+
rack (~> 1.0)
|
64
|
+
omniauth-google-oauth2 (0.2.5)
|
65
|
+
omniauth (> 1.0)
|
66
|
+
omniauth-oauth2 (~> 1.1)
|
67
|
+
omniauth-oauth2 (1.2.0)
|
68
|
+
faraday (>= 0.8, < 0.10)
|
69
|
+
multi_json (~> 1.3)
|
70
|
+
oauth2 (~> 1.0)
|
71
|
+
omniauth (~> 1.2)
|
72
|
+
polyglot (0.3.5)
|
73
|
+
rack (1.5.2)
|
74
|
+
rack-protection (1.5.3)
|
75
|
+
rack
|
76
|
+
rack-test (0.6.2)
|
77
|
+
rack (>= 1.0)
|
78
|
+
rails (4.0.9)
|
79
|
+
actionmailer (= 4.0.9)
|
80
|
+
actionpack (= 4.0.9)
|
81
|
+
activerecord (= 4.0.9)
|
82
|
+
activesupport (= 4.0.9)
|
83
|
+
bundler (>= 1.3.0, < 2.0)
|
84
|
+
railties (= 4.0.9)
|
85
|
+
sprockets-rails (~> 2.0)
|
86
|
+
railties (4.0.9)
|
87
|
+
actionpack (= 4.0.9)
|
88
|
+
activesupport (= 4.0.9)
|
89
|
+
rake (>= 0.8.7)
|
90
|
+
thor (>= 0.18.1, < 2.0)
|
91
|
+
rake (10.3.2)
|
92
|
+
rspec (3.1.0)
|
93
|
+
rspec-core (~> 3.1.0)
|
94
|
+
rspec-expectations (~> 3.1.0)
|
95
|
+
rspec-mocks (~> 3.1.0)
|
96
|
+
rspec-core (3.1.1)
|
97
|
+
rspec-support (~> 3.1.0)
|
98
|
+
rspec-expectations (3.1.0)
|
99
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
100
|
+
rspec-support (~> 3.1.0)
|
101
|
+
rspec-mocks (3.1.0)
|
102
|
+
rspec-support (~> 3.1.0)
|
103
|
+
rspec-support (3.1.0)
|
104
|
+
sinatra (1.4.5)
|
105
|
+
rack (~> 1.4)
|
106
|
+
rack-protection (~> 1.4)
|
107
|
+
tilt (~> 1.3, >= 1.3.4)
|
108
|
+
sprockets (2.12.2)
|
109
|
+
hike (~> 1.2)
|
110
|
+
multi_json (~> 1.0)
|
111
|
+
rack (~> 1.0)
|
112
|
+
tilt (~> 1.1, != 1.3.0)
|
113
|
+
sprockets-rails (2.1.4)
|
114
|
+
actionpack (>= 3.0)
|
115
|
+
activesupport (>= 3.0)
|
116
|
+
sprockets (~> 2.8)
|
117
|
+
thin (1.6.2)
|
118
|
+
daemons (>= 1.0.9)
|
119
|
+
eventmachine (>= 1.0.0)
|
120
|
+
rack (>= 1.0.0)
|
121
|
+
thor (0.19.1)
|
122
|
+
thread_safe (0.3.4)
|
123
|
+
tilt (1.4.1)
|
124
|
+
treetop (1.4.15)
|
125
|
+
polyglot
|
126
|
+
polyglot (>= 0.3.1)
|
127
|
+
tzinfo (0.3.41)
|
128
|
+
|
129
|
+
PLATFORMS
|
130
|
+
ruby
|
131
|
+
|
132
|
+
DEPENDENCIES
|
133
|
+
omniauth-google-oauth2
|
134
|
+
rack-test
|
135
|
+
rails (~> 4.0.9)
|
136
|
+
rake
|
137
|
+
rspec
|
138
|
+
simple_admin_auth!
|
139
|
+
thin
|
@@ -0,0 +1,145 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
simple_admin_auth (0.1.0)
|
5
|
+
omniauth
|
6
|
+
sinatra
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.1.5)
|
12
|
+
actionpack (= 4.1.5)
|
13
|
+
actionview (= 4.1.5)
|
14
|
+
mail (~> 2.5.4)
|
15
|
+
actionpack (4.1.5)
|
16
|
+
actionview (= 4.1.5)
|
17
|
+
activesupport (= 4.1.5)
|
18
|
+
rack (~> 1.5.2)
|
19
|
+
rack-test (~> 0.6.2)
|
20
|
+
actionview (4.1.5)
|
21
|
+
activesupport (= 4.1.5)
|
22
|
+
builder (~> 3.1)
|
23
|
+
erubis (~> 2.7.0)
|
24
|
+
activemodel (4.1.5)
|
25
|
+
activesupport (= 4.1.5)
|
26
|
+
builder (~> 3.1)
|
27
|
+
activerecord (4.1.5)
|
28
|
+
activemodel (= 4.1.5)
|
29
|
+
activesupport (= 4.1.5)
|
30
|
+
arel (~> 5.0.0)
|
31
|
+
activesupport (4.1.5)
|
32
|
+
i18n (~> 0.6, >= 0.6.9)
|
33
|
+
json (~> 1.7, >= 1.7.7)
|
34
|
+
minitest (~> 5.1)
|
35
|
+
thread_safe (~> 0.1)
|
36
|
+
tzinfo (~> 1.1)
|
37
|
+
arel (5.0.1.20140414130214)
|
38
|
+
builder (3.2.2)
|
39
|
+
daemons (1.1.9)
|
40
|
+
diff-lcs (1.2.5)
|
41
|
+
erubis (2.7.0)
|
42
|
+
eventmachine (1.0.3)
|
43
|
+
faraday (0.9.0)
|
44
|
+
multipart-post (>= 1.2, < 3)
|
45
|
+
hashie (3.3.1)
|
46
|
+
hike (1.2.3)
|
47
|
+
i18n (0.6.11)
|
48
|
+
json (1.8.1)
|
49
|
+
jwt (1.0.0)
|
50
|
+
mail (2.5.4)
|
51
|
+
mime-types (~> 1.16)
|
52
|
+
treetop (~> 1.4.8)
|
53
|
+
mime-types (1.25.1)
|
54
|
+
minitest (5.4.1)
|
55
|
+
multi_json (1.10.1)
|
56
|
+
multi_xml (0.5.5)
|
57
|
+
multipart-post (2.0.0)
|
58
|
+
oauth2 (1.0.0)
|
59
|
+
faraday (>= 0.8, < 0.10)
|
60
|
+
jwt (~> 1.0)
|
61
|
+
multi_json (~> 1.3)
|
62
|
+
multi_xml (~> 0.5)
|
63
|
+
rack (~> 1.2)
|
64
|
+
omniauth (1.2.2)
|
65
|
+
hashie (>= 1.2, < 4)
|
66
|
+
rack (~> 1.0)
|
67
|
+
omniauth-google-oauth2 (0.2.5)
|
68
|
+
omniauth (> 1.0)
|
69
|
+
omniauth-oauth2 (~> 1.1)
|
70
|
+
omniauth-oauth2 (1.2.0)
|
71
|
+
faraday (>= 0.8, < 0.10)
|
72
|
+
multi_json (~> 1.3)
|
73
|
+
oauth2 (~> 1.0)
|
74
|
+
omniauth (~> 1.2)
|
75
|
+
polyglot (0.3.5)
|
76
|
+
rack (1.5.2)
|
77
|
+
rack-protection (1.5.3)
|
78
|
+
rack
|
79
|
+
rack-test (0.6.2)
|
80
|
+
rack (>= 1.0)
|
81
|
+
rails (4.1.5)
|
82
|
+
actionmailer (= 4.1.5)
|
83
|
+
actionpack (= 4.1.5)
|
84
|
+
actionview (= 4.1.5)
|
85
|
+
activemodel (= 4.1.5)
|
86
|
+
activerecord (= 4.1.5)
|
87
|
+
activesupport (= 4.1.5)
|
88
|
+
bundler (>= 1.3.0, < 2.0)
|
89
|
+
railties (= 4.1.5)
|
90
|
+
sprockets-rails (~> 2.0)
|
91
|
+
railties (4.1.5)
|
92
|
+
actionpack (= 4.1.5)
|
93
|
+
activesupport (= 4.1.5)
|
94
|
+
rake (>= 0.8.7)
|
95
|
+
thor (>= 0.18.1, < 2.0)
|
96
|
+
rake (10.3.2)
|
97
|
+
rspec (3.1.0)
|
98
|
+
rspec-core (~> 3.1.0)
|
99
|
+
rspec-expectations (~> 3.1.0)
|
100
|
+
rspec-mocks (~> 3.1.0)
|
101
|
+
rspec-core (3.1.1)
|
102
|
+
rspec-support (~> 3.1.0)
|
103
|
+
rspec-expectations (3.1.0)
|
104
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
105
|
+
rspec-support (~> 3.1.0)
|
106
|
+
rspec-mocks (3.1.0)
|
107
|
+
rspec-support (~> 3.1.0)
|
108
|
+
rspec-support (3.1.0)
|
109
|
+
sinatra (1.4.5)
|
110
|
+
rack (~> 1.4)
|
111
|
+
rack-protection (~> 1.4)
|
112
|
+
tilt (~> 1.3, >= 1.3.4)
|
113
|
+
sprockets (2.12.2)
|
114
|
+
hike (~> 1.2)
|
115
|
+
multi_json (~> 1.0)
|
116
|
+
rack (~> 1.0)
|
117
|
+
tilt (~> 1.1, != 1.3.0)
|
118
|
+
sprockets-rails (2.1.4)
|
119
|
+
actionpack (>= 3.0)
|
120
|
+
activesupport (>= 3.0)
|
121
|
+
sprockets (~> 2.8)
|
122
|
+
thin (1.6.2)
|
123
|
+
daemons (>= 1.0.9)
|
124
|
+
eventmachine (>= 1.0.0)
|
125
|
+
rack (>= 1.0.0)
|
126
|
+
thor (0.19.1)
|
127
|
+
thread_safe (0.3.4)
|
128
|
+
tilt (1.4.1)
|
129
|
+
treetop (1.4.15)
|
130
|
+
polyglot
|
131
|
+
polyglot (>= 0.3.1)
|
132
|
+
tzinfo (1.2.2)
|
133
|
+
thread_safe (~> 0.1)
|
134
|
+
|
135
|
+
PLATFORMS
|
136
|
+
ruby
|
137
|
+
|
138
|
+
DEPENDENCIES
|
139
|
+
omniauth-google-oauth2
|
140
|
+
rack-test
|
141
|
+
rails (~> 4.1.5)
|
142
|
+
rake
|
143
|
+
rspec
|
144
|
+
simple_admin_auth!
|
145
|
+
thin
|
@@ -7,13 +7,27 @@ module SimpleAdminAuth
|
|
7
7
|
|
8
8
|
class Authenticate
|
9
9
|
def self.matches?(request)
|
10
|
-
if
|
10
|
+
if is_admin?(request.session)
|
11
11
|
true
|
12
12
|
else
|
13
13
|
request.session[:admin_login_return_url] = request.url
|
14
14
|
raise RedirectException.new('/auth/admin/login')
|
15
15
|
end
|
16
|
+
end
|
16
17
|
|
18
|
+
def self.is_admin?(session)
|
19
|
+
valid_admin = false
|
20
|
+
if !session[:admin_user].nil? && !session[:admin_user][:email].nil?
|
21
|
+
email = session[:admin_user][:email]
|
22
|
+
if !SimpleAdminAuth::Configuration.email_white_list.nil?
|
23
|
+
if SimpleAdminAuth::Configuration.email_white_list.include?(email)
|
24
|
+
valid_admin = true
|
25
|
+
end
|
26
|
+
else
|
27
|
+
valid_admin = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
valid_admin
|
17
31
|
end
|
18
32
|
end
|
19
33
|
|
data/lib/simple_admin_auth.rb
CHANGED
data/spec/application_spec.rb
CHANGED
@@ -10,14 +10,14 @@ describe Application do
|
|
10
10
|
|
11
11
|
it "should present a login screen" do
|
12
12
|
get '/admin/login', nil, {}
|
13
|
-
last_response.should
|
14
|
-
last_response.body.should
|
13
|
+
last_response.status.should eq(200)
|
14
|
+
last_response.body.should match(/You need to sign in to continue\./)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should render a failure page" do
|
18
18
|
get '/failure', nil, {}
|
19
|
-
last_response.should
|
20
|
-
last_response.body.should
|
19
|
+
last_response.status.should eq(200)
|
20
|
+
last_response.body.should match(/Authentication failed\./)
|
21
21
|
end
|
22
22
|
|
23
23
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'simple_admin_auth'
|
3
|
+
require 'simple_admin_auth/require_admin'
|
4
|
+
|
5
|
+
describe SimpleAdminAuth::Authenticate do
|
6
|
+
|
7
|
+
let(:auth) do
|
8
|
+
SimpleAdminAuth::Authenticate
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:admin_session) do
|
12
|
+
{
|
13
|
+
admin_user:{
|
14
|
+
email: 'admin@example.com',
|
15
|
+
name: 'dummy'
|
16
|
+
}
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:invalid_session) do
|
21
|
+
{
|
22
|
+
admin_user:{
|
23
|
+
x_email: 'admin@example.com',
|
24
|
+
x_name: 'dummy'
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
before do
|
30
|
+
SimpleAdminAuth::Configuration.email_white_list = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should authenticate if admin email is set ' do
|
34
|
+
auth.is_admin?(admin_session).should eq(true)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not authenticate with empty session ' do
|
38
|
+
auth.is_admin?({}).should eq(false)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should not authenticate if user is not white listed' do
|
42
|
+
SimpleAdminAuth::Configuration.email_white_list = ['foo@bar.com']
|
43
|
+
auth.is_admin?(admin_session).should eq(false)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should authenticate if user is white listed' do
|
47
|
+
SimpleAdminAuth::Configuration.email_white_list = ['admin@example.com']
|
48
|
+
auth.is_admin?(admin_session).should eq(true)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not authenticate for none valid sessions' do
|
52
|
+
auth.is_admin?(invalid_session).should eq(false)
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,8 +7,10 @@ include SimpleAdminAuth
|
|
7
7
|
|
8
8
|
RSpec.configure do |conf|
|
9
9
|
conf.include Rack::Test::Methods
|
10
|
+
conf.expect_with :rspec do |c|
|
11
|
+
c.syntax = [:should, :expect]
|
12
|
+
end
|
10
13
|
end
|
11
14
|
|
12
|
-
|
13
|
-
OmniAuth.config.add_mock(:admin, {:uid => '12345'})
|
15
|
+
OmniAuth.config.add_mock(:admin, {:uid => '12345', info:{ email: 'foo@bar.com'}})
|
14
16
|
OmniAuth.config.test_mode = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_admin_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ralf Kistner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: omniauth
|
@@ -59,16 +59,22 @@ files:
|
|
59
59
|
- gemfiles/rack1.5.gemfile.lock
|
60
60
|
- gemfiles/rails3.2.gemfile
|
61
61
|
- gemfiles/rails3.2.gemfile.lock
|
62
|
+
- gemfiles/rails4.0.gemfile
|
63
|
+
- gemfiles/rails4.0.gemfile.lock
|
64
|
+
- gemfiles/rails4.1.gemfile
|
65
|
+
- gemfiles/rails4.1.gemfile.lock
|
62
66
|
- lib/simple_admin_auth.rb
|
63
67
|
- lib/simple_admin_auth/application.rb
|
64
68
|
- lib/simple_admin_auth/authenticated.rb
|
65
69
|
- lib/simple_admin_auth/builder.rb
|
70
|
+
- lib/simple_admin_auth/configuration.rb
|
66
71
|
- lib/simple_admin_auth/login_redirect.rb
|
67
72
|
- lib/simple_admin_auth/openid_ssl.rb
|
68
73
|
- lib/simple_admin_auth/require_admin.rb
|
69
74
|
- lib/simple_admin_auth/version.rb
|
70
75
|
- simple_admin_auth.gemspec
|
71
76
|
- spec/application_spec.rb
|
77
|
+
- spec/authenticate_spec.rb
|
72
78
|
- spec/dummy/.gitignore
|
73
79
|
- spec/dummy/application.rb
|
74
80
|
- spec/integration_examples.rb
|
@@ -95,12 +101,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
101
|
version: '0'
|
96
102
|
requirements: []
|
97
103
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.
|
104
|
+
rubygems_version: 2.2.2
|
99
105
|
signing_key:
|
100
106
|
specification_version: 4
|
101
107
|
summary: Simple admin authentication using Google Apps
|
102
108
|
test_files:
|
103
109
|
- spec/application_spec.rb
|
110
|
+
- spec/authenticate_spec.rb
|
104
111
|
- spec/dummy/.gitignore
|
105
112
|
- spec/dummy/application.rb
|
106
113
|
- spec/integration_examples.rb
|