balrog 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +55 -0
- data/Gemfile.lock +109 -2
- data/README.md +42 -8
- data/balrog.gemspec +1 -0
- data/bin/console +1 -1
- data/lib/balrog.rb +3 -1
- data/lib/balrog/engine.rb +11 -4
- data/lib/balrog/middleware.rb +7 -0
- data/lib/balrog/version.rb +1 -1
- data/lib/balrog/view_helpers.rb +16 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5139f44e15d64bc7e7138716bd2f94078345981281415b3ac40bf4408c8181b0
|
4
|
+
data.tar.gz: 014f03129ad8f39feac850621f6a581138419b6933341e09a3feae2273736b0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cfe1ba81b99825b54f41d0116c819d968bfcac4f5a85940676e4b583dee45fb80598e06deb8126c127e2879c7ff55713eb99aac484dc4ab1b8b84a4583b7c90
|
7
|
+
data.tar.gz: 8ba157eb6b60d32e272f09b508883fa5a0637810e5142e9dc5368cb1bd676bacc6952d559841c4b5f57e19965ebfff5f12ea1591cdc39633c939f2b0531d5871
|
@@ -0,0 +1,55 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.6.2-node-browsers
|
7
|
+
|
8
|
+
working_directory: ~/repo/spec/dummy-rails-app
|
9
|
+
|
10
|
+
steps:
|
11
|
+
- checkout:
|
12
|
+
path: ~/repo
|
13
|
+
|
14
|
+
# Download and cache dependencies
|
15
|
+
- restore_cache:
|
16
|
+
name: Restore Rubygems cache
|
17
|
+
keys:
|
18
|
+
- v1-rubygems-{{ checksum "Gemfile.lock" }}
|
19
|
+
# fallback to using the latest cache if no exact match is found
|
20
|
+
- v1-rubygems-
|
21
|
+
|
22
|
+
- run:
|
23
|
+
name: Install bundler
|
24
|
+
command: |
|
25
|
+
gem install bundler:2.0.1
|
26
|
+
- run:
|
27
|
+
name: Install Ruby dependencies
|
28
|
+
command: |
|
29
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
30
|
+
|
31
|
+
- save_cache:
|
32
|
+
name: Save Rubygems cache
|
33
|
+
paths:
|
34
|
+
- ./vendor/bundle
|
35
|
+
key: v1-rubygems-{{ checksum "Gemfile.lock" }}
|
36
|
+
|
37
|
+
# run tests!
|
38
|
+
- run:
|
39
|
+
name: run tests
|
40
|
+
command: |
|
41
|
+
mkdir /tmp/test-results
|
42
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
43
|
+
|
44
|
+
bundle exec rspec --format progress \
|
45
|
+
--format RspecJunitFormatter \
|
46
|
+
--out /tmp/test-results/rspec.xml \
|
47
|
+
--format progress \
|
48
|
+
$TEST_FILES
|
49
|
+
|
50
|
+
# collect reports
|
51
|
+
- store_test_results:
|
52
|
+
path: /tmp/test-results
|
53
|
+
- store_artifacts:
|
54
|
+
path: /tmp/test-results
|
55
|
+
destination: test-results
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,107 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
balrog (0.
|
4
|
+
balrog (0.2.0)
|
5
5
|
bcrypt (~> 3.0)
|
6
|
+
rails (>= 4.2)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
actioncable (5.2.3)
|
12
|
+
actionpack (= 5.2.3)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailer (5.2.3)
|
16
|
+
actionpack (= 5.2.3)
|
17
|
+
actionview (= 5.2.3)
|
18
|
+
activejob (= 5.2.3)
|
19
|
+
mail (~> 2.5, >= 2.5.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
actionpack (5.2.3)
|
22
|
+
actionview (= 5.2.3)
|
23
|
+
activesupport (= 5.2.3)
|
24
|
+
rack (~> 2.0)
|
25
|
+
rack-test (>= 0.6.3)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
actionview (5.2.3)
|
29
|
+
activesupport (= 5.2.3)
|
30
|
+
builder (~> 3.1)
|
31
|
+
erubi (~> 1.4)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
34
|
+
activejob (5.2.3)
|
35
|
+
activesupport (= 5.2.3)
|
36
|
+
globalid (>= 0.3.6)
|
37
|
+
activemodel (5.2.3)
|
38
|
+
activesupport (= 5.2.3)
|
39
|
+
activerecord (5.2.3)
|
40
|
+
activemodel (= 5.2.3)
|
41
|
+
activesupport (= 5.2.3)
|
42
|
+
arel (>= 9.0)
|
43
|
+
activestorage (5.2.3)
|
44
|
+
actionpack (= 5.2.3)
|
45
|
+
activerecord (= 5.2.3)
|
46
|
+
marcel (~> 0.3.1)
|
47
|
+
activesupport (5.2.3)
|
48
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
49
|
+
i18n (>= 0.7, < 2)
|
50
|
+
minitest (~> 5.1)
|
51
|
+
tzinfo (~> 1.1)
|
52
|
+
arel (9.0.0)
|
10
53
|
bcrypt (3.1.12)
|
54
|
+
builder (3.2.3)
|
55
|
+
concurrent-ruby (1.1.5)
|
56
|
+
crass (1.0.4)
|
11
57
|
diff-lcs (1.3)
|
58
|
+
erubi (1.8.0)
|
59
|
+
globalid (0.4.2)
|
60
|
+
activesupport (>= 4.2.0)
|
61
|
+
i18n (1.6.0)
|
62
|
+
concurrent-ruby (~> 1.0)
|
63
|
+
loofah (2.2.3)
|
64
|
+
crass (~> 1.0.2)
|
65
|
+
nokogiri (>= 1.5.9)
|
66
|
+
mail (2.7.1)
|
67
|
+
mini_mime (>= 0.1.1)
|
68
|
+
marcel (0.3.3)
|
69
|
+
mimemagic (~> 0.3.2)
|
70
|
+
method_source (0.9.2)
|
71
|
+
mimemagic (0.3.3)
|
72
|
+
mini_mime (1.0.1)
|
73
|
+
mini_portile2 (2.4.0)
|
74
|
+
minitest (5.11.3)
|
75
|
+
nio4r (2.3.1)
|
76
|
+
nokogiri (1.10.3)
|
77
|
+
mini_portile2 (~> 2.4.0)
|
78
|
+
rack (2.0.7)
|
79
|
+
rack-test (1.1.0)
|
80
|
+
rack (>= 1.0, < 3)
|
81
|
+
rails (5.2.3)
|
82
|
+
actioncable (= 5.2.3)
|
83
|
+
actionmailer (= 5.2.3)
|
84
|
+
actionpack (= 5.2.3)
|
85
|
+
actionview (= 5.2.3)
|
86
|
+
activejob (= 5.2.3)
|
87
|
+
activemodel (= 5.2.3)
|
88
|
+
activerecord (= 5.2.3)
|
89
|
+
activestorage (= 5.2.3)
|
90
|
+
activesupport (= 5.2.3)
|
91
|
+
bundler (>= 1.3.0)
|
92
|
+
railties (= 5.2.3)
|
93
|
+
sprockets-rails (>= 2.0.0)
|
94
|
+
rails-dom-testing (2.0.3)
|
95
|
+
activesupport (>= 4.2.0)
|
96
|
+
nokogiri (>= 1.6)
|
97
|
+
rails-html-sanitizer (1.0.4)
|
98
|
+
loofah (~> 2.2, >= 2.2.2)
|
99
|
+
railties (5.2.3)
|
100
|
+
actionpack (= 5.2.3)
|
101
|
+
activesupport (= 5.2.3)
|
102
|
+
method_source
|
103
|
+
rake (>= 0.8.7)
|
104
|
+
thor (>= 0.19.0, < 2.0)
|
12
105
|
rake (10.5.0)
|
13
106
|
rspec (3.8.0)
|
14
107
|
rspec-core (~> 3.8.0)
|
@@ -16,13 +109,27 @@ GEM
|
|
16
109
|
rspec-mocks (~> 3.8.0)
|
17
110
|
rspec-core (3.8.0)
|
18
111
|
rspec-support (~> 3.8.0)
|
19
|
-
rspec-expectations (3.8.
|
112
|
+
rspec-expectations (3.8.3)
|
20
113
|
diff-lcs (>= 1.2.0, < 2.0)
|
21
114
|
rspec-support (~> 3.8.0)
|
22
115
|
rspec-mocks (3.8.0)
|
23
116
|
diff-lcs (>= 1.2.0, < 2.0)
|
24
117
|
rspec-support (~> 3.8.0)
|
25
118
|
rspec-support (3.8.0)
|
119
|
+
sprockets (3.7.2)
|
120
|
+
concurrent-ruby (~> 1.0)
|
121
|
+
rack (> 1, < 3)
|
122
|
+
sprockets-rails (3.2.1)
|
123
|
+
actionpack (>= 4.0)
|
124
|
+
activesupport (>= 4.0)
|
125
|
+
sprockets (>= 3.0.0)
|
126
|
+
thor (0.20.3)
|
127
|
+
thread_safe (0.3.6)
|
128
|
+
tzinfo (1.2.5)
|
129
|
+
thread_safe (~> 0.1)
|
130
|
+
websocket-driver (0.7.0)
|
131
|
+
websocket-extensions (>= 0.1.0)
|
132
|
+
websocket-extensions (0.1.3)
|
26
133
|
|
27
134
|
PLATFORMS
|
28
135
|
ruby
|
data/README.md
CHANGED
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
![Balrog logo](https://user-images.githubusercontent.com/32128719/55335192-9566a000-5492-11e9-9449-746de68fbe94.png)
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/balrog.svg)](https://badge.fury.io/rb/balrog)
|
6
|
+
[![CircleCI](https://circleci.com/gh/pixielabs/balrog.svg?style=svg)](https://circleci.com/gh/pixielabs/balrog)
|
7
|
+
|
8
|
+
Balrog is a lightweight authorization library for Ruby on Rails written by
|
9
|
+
[Pixie Labs](https://pixielabs.io) that can protect your routes with a single
|
10
|
+
username & password combination.
|
7
11
|
|
8
12
|
Balrog is an alternative to `http_basic_authentication_with` that provides some
|
9
13
|
advantages:
|
@@ -14,11 +18,6 @@ advantages:
|
|
14
18
|
* Better support for password managers (which often don't support basic
|
15
19
|
authentication dialog boxes).
|
16
20
|
|
17
|
-
## Requirements
|
18
|
-
|
19
|
-
Balrog is designed to be used with Ruby on Rails applications, and has been
|
20
|
-
tested against Ruby on Rails 5.
|
21
|
-
|
22
21
|
## Installation
|
23
22
|
|
24
23
|
Add the gem to your Gemfile:
|
@@ -60,8 +59,44 @@ class AdminController < ApplicationController
|
|
60
59
|
end
|
61
60
|
```
|
62
61
|
|
62
|
+
## Logout button
|
63
|
+
|
64
|
+
To add a logout button, you can call the `balrog_logout_button` view helper
|
65
|
+
method and pass in a hash of HTML options to style it. After logout, the user
|
66
|
+
will be redirected to the root of the app.
|
67
|
+
|
68
|
+
For example, in your view:
|
69
|
+
|
70
|
+
```erb
|
71
|
+
<ul class='nav'>
|
72
|
+
<li>....</li>
|
73
|
+
<li><%= balrog_logout_button 'Admin Logout' %></li>
|
74
|
+
<li>....</li>
|
75
|
+
</ul>
|
76
|
+
```
|
77
|
+
|
78
|
+
Other usage examples:
|
79
|
+
|
80
|
+
```erb
|
81
|
+
<%= balrog_logout_button %>
|
82
|
+
<%= balrog_logout_button "Leave this place" %>
|
83
|
+
<%= balrog_logout_button "Click me", class: 'fancy-button--with-custom-text' %>
|
84
|
+
<%= balrog_logout_button class: 'fancy-button--with-default-text' %>
|
85
|
+
```
|
86
|
+
|
87
|
+
|
63
88
|
## Contributing
|
64
89
|
|
90
|
+
### Running the tests
|
91
|
+
|
92
|
+
Tests are part of the dummy Rails app within the spec folder:
|
93
|
+
|
94
|
+
```
|
95
|
+
$ cd spec/dummy-rails-app
|
96
|
+
$ bundle
|
97
|
+
$ rspec
|
98
|
+
```
|
99
|
+
|
65
100
|
Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md).
|
66
101
|
- Check out the latest master to make sure the feature hasn't been implemented
|
67
102
|
or the bug hasn't been fixed yet.
|
@@ -78,7 +113,6 @@ Before contributing, please read the [code of conduct](CODE_OF_CONDUCT.md).
|
|
78
113
|
## TODO
|
79
114
|
|
80
115
|
* Restricting access via `routes.rb`
|
81
|
-
* Logout
|
82
116
|
* Test coverage
|
83
117
|
* Check it's OK with Ruby on Rails 6
|
84
118
|
* Expire sessions
|
data/balrog.gemspec
CHANGED
data/bin/console
CHANGED
data/lib/balrog.rb
CHANGED
data/lib/balrog/engine.rb
CHANGED
@@ -1,13 +1,20 @@
|
|
1
|
-
require_relative 'helpers'
|
2
|
-
|
3
1
|
class Balrog::Engine < Rails::Engine
|
4
|
-
# Make
|
5
|
-
initializer "balrog.
|
2
|
+
# Make authenticate_with_balrog! available.
|
3
|
+
initializer "balrog.action_controller" do
|
6
4
|
ActiveSupport.on_load(:action_controller) do
|
5
|
+
require_relative 'helpers'
|
7
6
|
include Balrog::Helpers
|
8
7
|
end
|
9
8
|
end
|
10
9
|
|
10
|
+
# Add balrog_logout_button as a global view helper.
|
11
|
+
initializer "balrog.action_view" do
|
12
|
+
ActiveSupport.on_load(:action_view) do
|
13
|
+
require_relative 'view_helpers'
|
14
|
+
include Balrog::ViewHelpers
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
11
18
|
# Precompile the Balrog assets
|
12
19
|
initializer "balrog.assets.precompile" do |app|
|
13
20
|
app.config.assets.precompile += %w(
|
data/lib/balrog/middleware.rb
CHANGED
@@ -21,6 +21,8 @@ class Balrog::Middleware
|
|
21
21
|
method = env["REQUEST_METHOD"]
|
22
22
|
if method == 'POST' && path == '/balrog/signin'
|
23
23
|
handle_login(env)
|
24
|
+
elsif method == "DELETE" && path == '/balrog/logout'
|
25
|
+
handle_logout(env)
|
24
26
|
else
|
25
27
|
@app.call(env)
|
26
28
|
end
|
@@ -62,5 +64,10 @@ class Balrog::Middleware
|
|
62
64
|
[302, {"Location" => referer}, [""]]
|
63
65
|
end
|
64
66
|
|
67
|
+
def handle_logout(env)
|
68
|
+
env['rack.session'].delete(:balrog)
|
69
|
+
[302, {"Location" => '/'}, [""]]
|
70
|
+
end
|
71
|
+
|
65
72
|
end
|
66
73
|
|
data/lib/balrog/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# ViewHelpers methods are made available in all controllers by the code in engine.rb.
|
2
|
+
module Balrog::ViewHelpers
|
3
|
+
def balrog_logout_button(options = nil, html_options = nil)
|
4
|
+
name = 'Logout'
|
5
|
+
html_options ||= {}
|
6
|
+
html_options[:method] = 'delete'
|
7
|
+
|
8
|
+
if options.is_a?(String)
|
9
|
+
name = options
|
10
|
+
elsif options.is_a?(Hash)
|
11
|
+
html_options = html_options.merge(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
button_to(name, '/balrog/logout', html_options)
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: balrog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pixie Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,6 +88,7 @@ executables: []
|
|
74
88
|
extensions: []
|
75
89
|
extra_rdoc_files: []
|
76
90
|
files:
|
91
|
+
- ".circleci/config.yml"
|
77
92
|
- ".gitignore"
|
78
93
|
- ".rspec"
|
79
94
|
- ".travis.yml"
|
@@ -99,6 +114,7 @@ files:
|
|
99
114
|
- lib/balrog/rake_tasks.rb
|
100
115
|
- lib/balrog/tasks/generate_hash.rake
|
101
116
|
- lib/balrog/version.rb
|
117
|
+
- lib/balrog/view_helpers.rb
|
102
118
|
homepage: https://github.com/pixielabs/balrog
|
103
119
|
licenses:
|
104
120
|
- MIT
|
@@ -118,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
134
|
- !ruby/object:Gem::Version
|
119
135
|
version: '0'
|
120
136
|
requirements: []
|
121
|
-
rubygems_version: 3.0.
|
137
|
+
rubygems_version: 3.0.3
|
122
138
|
signing_key:
|
123
139
|
specification_version: 4
|
124
140
|
summary: An alternative to HTTP basic auth
|