rack-ninja_auth 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rack/ninja_auth/version.rb +1 -1
- data/lib/rack/ninja_auth.rb +14 -7
- data/rack-ninja_auth.gemspec +2 -0
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed94dae3e5a5547917ea634c229707e3b24595c3
|
4
|
+
data.tar.gz: 02b0610f20badd0ab573b099aabaf09ae9498460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7223fbff5f7dad8363aba145e9578c69fbb4c25b8835cf766211718b2c90cde930be18a0e34748e8ddadc8bee408dcbb61514081833479cff4520bd8c347b2e9
|
7
|
+
data.tar.gz: ff11492d8eeecf6678ec42a7862f5358ade0d35864f1bada8b3c64d41ad84210a0557ccea82f5c95d644a86ab23451672cb45b420eaaed5b2eb385832ac6c880
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ Require authentication via google for your application without passing any auth
|
|
4
4
|
|
5
5
|
## Example
|
6
6
|
|
7
|
-
Add this as middleware to your rack application, then execute with `NINJA_GOOGLE_CLIENT_ID` and `
|
7
|
+
Add this as middleware to your rack application, then execute with `NINJA_GOOGLE_CLIENT_ID`, `NINJA_GOOGLE_CLIENT_SECRET` and `NINJA_REDIS_URL` environment variables set.
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
require 'sinatra'
|
data/lib/rack/ninja_auth.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
require 'rack/ninja_auth/version'
|
2
2
|
require 'sinatra/base'
|
3
3
|
require 'omniauth/google_oauth2'
|
4
|
+
require 'rack/session/redis'
|
5
|
+
require 'rack/accept'
|
4
6
|
|
5
7
|
module Rack
|
6
8
|
module NinjaAuth
|
7
9
|
class Middleware < Sinatra::Base
|
8
|
-
use Rack::
|
10
|
+
use Rack::Accept
|
11
|
+
use Rack::Session::Redis,
|
9
12
|
key: 'rack.ninja_auth',
|
10
|
-
expire_after: 2592000
|
13
|
+
expire_after: 2592000,
|
14
|
+
redis_server: ENV['NINJA_REDIS_URL'] || 'redis://127.0.0.1:6379/0/rack:ninja_auth'
|
11
15
|
|
12
16
|
raise "Please set NINJA_GOOGLE_CLIENT_ID and NINJA_GOOGLE_CLIENT_SECRET to use NinjaAuth" unless ENV["NINJA_GOOGLE_CLIENT_ID"] && ENV["NINJA_GOOGLE_CLIENT_SECRET"]
|
13
17
|
use OmniAuth::Builder do
|
@@ -22,8 +26,10 @@ module Rack
|
|
22
26
|
end
|
23
27
|
|
24
28
|
before do
|
29
|
+
@hit_real_app = false
|
25
30
|
if is_authenticated?
|
26
31
|
res = @main_app.call(request.env)
|
32
|
+
@hit_real_app = true
|
27
33
|
headers res[1]
|
28
34
|
halt res[0], res[2]
|
29
35
|
end
|
@@ -34,17 +40,18 @@ module Rack
|
|
34
40
|
session[:user] = request.env["omniauth.auth"].info.email
|
35
41
|
redirect session[:redirect_to]
|
36
42
|
else
|
37
|
-
redirect '/
|
43
|
+
redirect '/auth/failure'
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
|
-
get '/
|
47
|
+
get '/auth/failure' do
|
42
48
|
send_file(@not_allowed_file, status: 401)
|
43
49
|
end
|
44
50
|
|
45
51
|
after do
|
46
|
-
if status == 404
|
47
|
-
|
52
|
+
if !@hit_real_app && status == 404
|
53
|
+
halt(403) unless env['rack-accept.request'].media_type?('text/html')
|
54
|
+
session[:redirect_to] = env['REQUEST_URI'] =~ %r{^/auth/google_oauth2} ? '/' : env['REQUEST_URI']
|
48
55
|
redirect '/auth/google_oauth2'
|
49
56
|
end
|
50
57
|
end
|
@@ -52,7 +59,7 @@ module Rack
|
|
52
59
|
private
|
53
60
|
|
54
61
|
def is_authenticated?
|
55
|
-
|
62
|
+
!session[:user].nil?
|
56
63
|
end
|
57
64
|
end
|
58
65
|
end
|
data/rack-ninja_auth.gemspec
CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency "sinatra", "~> 1.4"
|
23
23
|
spec.add_dependency "omniauth-google-oauth2", "~> 0.2"
|
24
|
+
spec.add_dependency "redis-rack", "~> 1.5"
|
25
|
+
spec.add_dependency "rack-accept", "~> 0.4"
|
24
26
|
|
25
27
|
spec.add_development_dependency "bundler", "~> 1.10"
|
26
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-ninja_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Hastings-Spital
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis-rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-accept
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.4'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: bundler
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|