auth_strategist 0.5.0 → 0.6.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 +11 -10
- data/auth_strategist.gemspec +1 -0
- data/lib/auth_strategist.rb +1 -0
- data/lib/auth_strategist/errors/unauthorized.rb +9 -0
- data/lib/auth_strategist/strategy_interface.rb +4 -0
- data/lib/auth_strategist/version.rb +1 -1
- data/spec/strategy_interface_spec.rb +11 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07d66deb03bf384671d5622aee616fd13adb2897
|
4
|
+
data.tar.gz: e3f3e66267fbf073375ed49bd396636c692826b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51d781f1d8e9e8e464f33b0961316f161aba8872da8b9955d512db56daaa5f1910729260356f586d50c34f14b99d3fd48fc1655a687b5d874be9d242cbde8080
|
7
|
+
data.tar.gz: 6bed7d0bd697858927e38bd1ae1eae45ef154d2b59fe13ee0cd1cda44745e5b85a9a5a0b0e632dadb293713996b1e57c893a44e64bf861ea4dd2593ef4458857
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
AuthStrategist
|
5
5
|
======
|
6
6
|
[![Code Climate](https://codeclimate.com/github/buszu/auth_strategist/badges/gpa.svg)](https://codeclimate.com/github/buszu/auth_strategist)
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/auth_strategist.svg)](http://badge.fury.io/rb/auth_strategist)
|
7
8
|
|
8
9
|
AuthStrategist is a simple gem to define and use authorization strategies.
|
9
10
|
|
@@ -40,8 +41,8 @@ AuthStrategist.configure do |c|
|
|
40
41
|
# Register your strategies
|
41
42
|
# Required for each strategy you have defined
|
42
43
|
c.strategies do |s|
|
43
|
-
# E.g.
|
44
|
-
s.
|
44
|
+
# E.g. OwnershipAuthStrategy will be available under :ownership key
|
45
|
+
s.ownership = OwnershipAuthStrategy
|
45
46
|
end
|
46
47
|
end
|
47
48
|
```
|
@@ -51,36 +52,36 @@ end
|
|
51
52
|
### Defining a Strategy
|
52
53
|
* Define a strategy
|
53
54
|
```ruby
|
54
|
-
class
|
55
|
+
class OwnershipAuthStrategy
|
55
56
|
include AuthStrategist::StrategyInterface
|
56
57
|
|
57
|
-
define_components :user, :
|
58
|
+
define_components :user, :item
|
58
59
|
|
59
60
|
def authorize!
|
60
|
-
raise
|
61
|
+
raise unauthorized if item.user_id != user.id
|
61
62
|
end
|
62
63
|
end
|
63
64
|
```
|
64
65
|
* Register it
|
65
66
|
```ruby
|
66
67
|
AuthStrategist.strategies do |s|
|
67
|
-
s.
|
68
|
+
s.ownership = OwnershipAuthStrategy
|
68
69
|
end
|
69
70
|
```
|
70
71
|
or
|
71
72
|
```ruby
|
72
73
|
AuthStrategist.configure do |c|
|
73
74
|
c.strategies do |s|
|
74
|
-
s.
|
75
|
+
s.ownership = OwnershipAuthStrategy
|
75
76
|
end
|
76
77
|
end
|
77
78
|
```
|
78
79
|
### Using strategies
|
79
80
|
* Using strategy by calling authorization Service Object
|
80
81
|
```ruby
|
81
|
-
AuthStrategist::Authorize.call strategy: :
|
82
|
+
AuthStrategist::Authorize.call strategy: :ownership,
|
82
83
|
user: current_user,
|
83
|
-
|
84
|
+
item: book
|
84
85
|
```
|
85
86
|
* Using strategy with authorize! method
|
86
87
|
```ruby
|
@@ -88,7 +89,7 @@ class SomethingsController < ApplicationController
|
|
88
89
|
include AuthStrategist::Authorization
|
89
90
|
|
90
91
|
def show
|
91
|
-
authorize! strategy: :
|
92
|
+
authorize! strategy: :ownership, user: current_user, item: book
|
92
93
|
end
|
93
94
|
end
|
94
95
|
```
|
data/auth_strategist.gemspec
CHANGED
data/lib/auth_strategist.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'auth_strategist/version'
|
2
2
|
require 'auth_strategist/configuration'
|
3
3
|
require 'auth_strategist/configuration/strategies_registry'
|
4
|
+
require 'auth_strategist/errors/unauthorized'
|
4
5
|
require 'auth_strategist/strategy_interface'
|
5
6
|
require 'auth_strategist/authorize'
|
6
7
|
require 'auth_strategist/authorization'
|
@@ -29,6 +29,10 @@ describe AuthStrategist::StrategyInterface do
|
|
29
29
|
expect(strategy_class.new).to respond_to(:authorize!)
|
30
30
|
end
|
31
31
|
|
32
|
+
it 'adds #unauthorized method to base' do
|
33
|
+
expect(strategy_class.new).to respond_to(:unauthorized)
|
34
|
+
end
|
35
|
+
|
32
36
|
it 'adds getters for default components to base' do
|
33
37
|
default_components.each do |c|
|
34
38
|
expect(strategy_class.new).to respond_to(c)
|
@@ -128,7 +132,7 @@ describe AuthStrategist::StrategyInterface do
|
|
128
132
|
it 'assigns components values properly' do
|
129
133
|
expect(subject.user).to eq('john')
|
130
134
|
expect(subject.password).to eq('rambo')
|
131
|
-
expect { subject.missing_component }.to raise_error
|
135
|
+
expect { subject.missing_component }.to raise_error(NoMethodError)
|
132
136
|
end
|
133
137
|
end
|
134
138
|
|
@@ -162,5 +166,11 @@ describe AuthStrategist::StrategyInterface do
|
|
162
166
|
end
|
163
167
|
end
|
164
168
|
end
|
169
|
+
|
170
|
+
describe '#unauthorized' do
|
171
|
+
subject { strategy_class.new }
|
172
|
+
|
173
|
+
it { expect(subject.unauthorized).to eq(AuthStrategist::Errors::Unauthorized) }
|
174
|
+
end
|
165
175
|
end
|
166
176
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth_strategist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Buszewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-its
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- krzysztof.buszewicz@gmail.com
|
@@ -75,6 +89,7 @@ files:
|
|
75
89
|
- lib/auth_strategist/authorize.rb
|
76
90
|
- lib/auth_strategist/configuration.rb
|
77
91
|
- lib/auth_strategist/configuration/strategies_registry.rb
|
92
|
+
- lib/auth_strategist/errors/unauthorized.rb
|
78
93
|
- lib/auth_strategist/strategy_interface.rb
|
79
94
|
- lib/auth_strategist/version.rb
|
80
95
|
- lib/generators/auth_strategist/install_generator.rb
|
@@ -110,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
125
|
version: '0'
|
111
126
|
requirements: []
|
112
127
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.6.8
|
114
129
|
signing_key:
|
115
130
|
specification_version: 4
|
116
131
|
summary: Simple gem to realize API actions authorization with different strategies.
|
@@ -126,4 +141,3 @@ test_files:
|
|
126
141
|
- spec/factories/authorize.rb
|
127
142
|
- spec/spec_helper.rb
|
128
143
|
- spec/strategy_interface_spec.rb
|
129
|
-
has_rdoc:
|