heroku-bouncer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -6
- data/README.md +15 -1
- data/lib/heroku/bouncer.rb +51 -30
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
heroku-bouncer (0.0
|
4
|
+
heroku-bouncer (0.1.0)
|
5
5
|
faraday (~> 0.8)
|
6
6
|
multi_json (~> 1.0)
|
7
7
|
omniauth-heroku (>= 0.1.0)
|
@@ -14,8 +14,8 @@ GEM
|
|
14
14
|
multipart-post (~> 1.1)
|
15
15
|
hashie (1.2.0)
|
16
16
|
httpauth (0.2.0)
|
17
|
-
jwt (0.1.
|
18
|
-
multi_json (>= 1.
|
17
|
+
jwt (0.1.7)
|
18
|
+
multi_json (>= 1.5)
|
19
19
|
multi_json (1.6.1)
|
20
20
|
multipart-post (1.2.0)
|
21
21
|
oauth2 (0.8.1)
|
@@ -27,20 +27,20 @@ GEM
|
|
27
27
|
omniauth (1.1.3)
|
28
28
|
hashie (~> 1.2)
|
29
29
|
rack
|
30
|
-
omniauth-heroku (0.1.
|
30
|
+
omniauth-heroku (0.1.1)
|
31
31
|
omniauth (~> 1.0)
|
32
32
|
omniauth-oauth2 (~> 1.0)
|
33
33
|
omniauth-oauth2 (1.1.1)
|
34
34
|
oauth2 (~> 0.8.0)
|
35
35
|
omniauth (~> 1.0)
|
36
36
|
rack (1.5.2)
|
37
|
-
rack-protection (1.
|
37
|
+
rack-protection (1.5.0)
|
38
38
|
rack
|
39
39
|
sinatra (1.3.5)
|
40
40
|
rack (~> 1.4)
|
41
41
|
rack-protection (~> 1.3)
|
42
42
|
tilt (~> 1.3, >= 1.3.3)
|
43
|
-
tilt (1.3.
|
43
|
+
tilt (1.3.5)
|
44
44
|
|
45
45
|
PLATFORMS
|
46
46
|
ruby
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ requires Heroku OAuth on all requests.
|
|
12
12
|
heroku clients:create likeaboss https://likeaboss.herokuapp.com/auth/heroku/callback
|
13
13
|
```
|
14
14
|
|
15
|
-
2. Set `
|
15
|
+
2. Set `HEROKU_OAUTH_ID` and `HEROKU_OAUTH_SECRET` in your environment.
|
16
16
|
3. Use the middleware:
|
17
17
|
|
18
18
|
```ruby
|
@@ -54,6 +54,20 @@ the following keys to your request environment:
|
|
54
54
|
|
55
55
|
You can access this in your Rack app by reading `request.env[key]`.
|
56
56
|
|
57
|
+
## Using the Heroku API
|
58
|
+
|
59
|
+
If you set `expose_token` to `true`, you'll get an API token that you
|
60
|
+
can use to make Heroku API calls on behalf of the logged-in user using
|
61
|
+
[heroku.rb](https://github.com/heroku/heroku.rb).
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
heroku = Heroku::API.new(:api_key => request.env["bouncer.token"])
|
65
|
+
apps = heroku.get_apps.body
|
66
|
+
```
|
67
|
+
|
68
|
+
Keep in mind that this adds substantial security risk to your
|
69
|
+
application.
|
70
|
+
|
57
71
|
## Logging out
|
58
72
|
|
59
73
|
Send users to `/auth/sso-logout` if logging out of Heroku is
|
data/lib/heroku/bouncer.rb
CHANGED
@@ -7,43 +7,39 @@ Heroku ||= Module.new
|
|
7
7
|
|
8
8
|
class Heroku::Bouncer < Sinatra::Base
|
9
9
|
|
10
|
+
$stderr.puts "[warn] heroku-bouncer: HEROKU_ID detected, please use HEROKU_OAUTH_ID instead" if ENV.has_key?('HEROKU_ID')
|
11
|
+
$stderr.puts "[warn] heroku-bouncer: HEROKU_SECRET detected, please use HEROKU_OAUTH_SECRET instead" if ENV.has_key?('HEROKU_SECRET')
|
12
|
+
|
13
|
+
ID = (ENV['HEROKU_OAUTH_ID'] || ENV['HEROKU_ID']).to_s
|
14
|
+
SECRET = (ENV['HEROKU_OAUTH_SECRET'] || ENV['HEROKU_SECRET']).to_s
|
15
|
+
|
10
16
|
enable :sessions
|
11
|
-
set :session_secret,
|
17
|
+
set :session_secret, ID + SECRET
|
12
18
|
|
13
19
|
# sets up the /auth/heroku endpoint
|
14
|
-
|
15
|
-
|
20
|
+
unless ID.empty? || SECRET.empty?
|
21
|
+
use OmniAuth::Builder do
|
22
|
+
provider :heroku, ID, SECRET
|
23
|
+
end
|
16
24
|
end
|
17
25
|
|
18
26
|
def initialize(app, options = {})
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
MultiJson.decode(
|
32
|
-
Faraday.new(ENV["HEROKU_API_URL"] || "https://api.heroku.com/").get('/account') do |r|
|
33
|
-
r.headers['Accept'] = 'application/json'
|
34
|
-
r.headers['Authorization'] = "Bearer #{token}"
|
35
|
-
end.body)
|
36
|
-
end
|
37
|
-
|
38
|
-
def store(key, value)
|
39
|
-
session[:store] ||= {}
|
40
|
-
session[:store][key] = value
|
27
|
+
if ID.empty? || SECRET.empty?
|
28
|
+
$stderr.puts "[fatal] heroku-bouncer: HEROKU_OAUTH_ID or HEROKU_OAUTH_SECRET not set, middleware disabled"
|
29
|
+
@app = app
|
30
|
+
@disabled = true
|
31
|
+
# super is not called; we're not using sinatra if we're disabled
|
32
|
+
else
|
33
|
+
super(app)
|
34
|
+
@herokai_only = extract_option(options, :herokai_only, false)
|
35
|
+
@expose_token = extract_option(options, :expose_token, false)
|
36
|
+
@expose_email = extract_option(options, :expose_email, true)
|
37
|
+
@expose_user = extract_option(options, :expose_user, true)
|
38
|
+
end
|
41
39
|
end
|
42
40
|
|
43
|
-
def
|
44
|
-
|
45
|
-
request.env["bouncer.#{key}"] = value
|
46
|
-
end
|
41
|
+
def call(env)
|
42
|
+
@disabled ? @app.call(env) : super(env)
|
47
43
|
end
|
48
44
|
|
49
45
|
before do
|
@@ -82,7 +78,7 @@ class Heroku::Bouncer < Sinatra::Base
|
|
82
78
|
# logout, single sign-on style
|
83
79
|
get '/auth/sso-logout' do
|
84
80
|
session.destroy
|
85
|
-
auth_url = ENV["HEROKU_AUTH_URL"] || "https://
|
81
|
+
auth_url = ENV["HEROKU_AUTH_URL"] || "https://id.heroku.com"
|
86
82
|
redirect to("#{auth_url}/logout")
|
87
83
|
end
|
88
84
|
|
@@ -92,4 +88,29 @@ class Heroku::Bouncer < Sinatra::Base
|
|
92
88
|
redirect to("/")
|
93
89
|
end
|
94
90
|
|
91
|
+
private
|
92
|
+
|
93
|
+
def extract_option(options, option, default = nil)
|
94
|
+
options.has_key?(option) ? options[option] : default
|
95
|
+
end
|
96
|
+
|
97
|
+
def fetch_user(token)
|
98
|
+
MultiJson.decode(
|
99
|
+
Faraday.new(ENV["HEROKU_API_URL"] || "https://api.heroku.com/").get('/account') do |r|
|
100
|
+
r.headers['Accept'] = 'application/json'
|
101
|
+
r.headers['Authorization'] = "Bearer #{token}"
|
102
|
+
end.body)
|
103
|
+
end
|
104
|
+
|
105
|
+
def store(key, value)
|
106
|
+
session[:store] ||= {}
|
107
|
+
session[:store][key] = value
|
108
|
+
end
|
109
|
+
|
110
|
+
def expose_store
|
111
|
+
session[:store].each_pair do |key, value|
|
112
|
+
request.env["bouncer.#{key}"] = value
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
95
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku-bouncer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth-heroku
|