authorized_persona 0.9.0 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +27 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -1
- data/.rubocop_todo.yml +100 -0
- data/.ruby-version +1 -0
- data/Appraisals +14 -0
- data/README.md +5 -4
- data/authorized_persona.gemspec +6 -4
- data/gemfiles/rails_6_0.gemfile +8 -0
- data/gemfiles/rails_6_1.gemfile +8 -0
- data/gemfiles/rails_7_0.gemfile +8 -0
- data/lib/authorized_persona/authorization.rb +5 -5
- data/lib/authorized_persona/persona.rb +1 -1
- data/lib/authorized_persona/railtie.rb +1 -1
- data/lib/authorized_persona/version.rb +1 -1
- metadata +49 -28
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83c7b75e101248119260f84dc0cfabd9dc6db7a079cacf89de689d7863e12028
|
4
|
+
data.tar.gz: 9d1e4c231c66e743650ae5566192a5a5aa640974d616c3f508b0f08a981ed592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db6b39f1ca8cadb3e9180e17bf36eb33467c5d929144444ac9d17d2e949d13697c36a21241f4e168367c0013569699299e6322b2e85d1548ef2360c9377ff890
|
7
|
+
data.tar.gz: 6300f79ee516294b170acd149d555b80c23033a29513d667511ef447e8025abccff942faf9ab55823dedc3d871daa17326c691ef4ef969d544c2958451bd5794
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby: ['2.7', '3.0']
|
12
|
+
gemfile:
|
13
|
+
- gemfiles/rails_6_0.gemfile
|
14
|
+
- gemfiles/rails_6_1.gemfile
|
15
|
+
- gemfiles/rails_7_0.gemfile
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- uses: ruby/setup-ruby@v1
|
19
|
+
env:
|
20
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
24
|
+
- name: Run tests and linter
|
25
|
+
env:
|
26
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
27
|
+
run: bundle exec rake
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 99999`
|
3
|
+
# on 2023-05-09 13:01:46 UTC using RuboCop version 1.50.2.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 4
|
10
|
+
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
|
11
|
+
# SupportedStyles: Gemfile, gems.rb, gemspec
|
12
|
+
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
|
13
|
+
Gemspec/DevelopmentDependencies:
|
14
|
+
Exclude:
|
15
|
+
- 'authorized_persona.gemspec'
|
16
|
+
|
17
|
+
# Offense count: 1
|
18
|
+
# Configuration parameters: Severity, Include.
|
19
|
+
# Include: **/*.gemspec
|
20
|
+
Gemspec/RequiredRubyVersion:
|
21
|
+
Exclude:
|
22
|
+
- 'authorized_persona.gemspec'
|
23
|
+
|
24
|
+
# Offense count: 1
|
25
|
+
# This cop supports safe autocorrection (--autocorrect).
|
26
|
+
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
27
|
+
# URISchemes: http, https
|
28
|
+
Layout/LineLength:
|
29
|
+
Exclude:
|
30
|
+
- 'lib/authorized_persona/authorization.rb'
|
31
|
+
|
32
|
+
# Offense count: 2
|
33
|
+
Lint/MissingSuper:
|
34
|
+
Exclude:
|
35
|
+
- 'spec/authorized_persona/authorization_spec.rb'
|
36
|
+
- 'spec/authorized_persona/persona_spec.rb'
|
37
|
+
|
38
|
+
# Offense count: 2
|
39
|
+
# This cop supports safe autocorrection (--autocorrect).
|
40
|
+
Lint/RedundantCopDisableDirective:
|
41
|
+
Exclude:
|
42
|
+
- 'lib/authorized_persona/authorization.rb'
|
43
|
+
|
44
|
+
# Offense count: 1
|
45
|
+
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
46
|
+
Metrics/PerceivedComplexity:
|
47
|
+
Exclude:
|
48
|
+
- 'lib/authorized_persona/persona.rb'
|
49
|
+
|
50
|
+
# Offense count: 2
|
51
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
52
|
+
RSpec/BeEq:
|
53
|
+
Exclude:
|
54
|
+
- 'spec/authorized_persona/authorization_spec.rb'
|
55
|
+
|
56
|
+
# Offense count: 1
|
57
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
58
|
+
Rails/ActiveSupportOnLoad:
|
59
|
+
Exclude:
|
60
|
+
- 'lib/authorized_persona/railtie.rb'
|
61
|
+
|
62
|
+
# Offense count: 1
|
63
|
+
Rails/I18nLocaleTexts:
|
64
|
+
Exclude:
|
65
|
+
- 'lib/authorized_persona/authorization.rb'
|
66
|
+
|
67
|
+
# Offense count: 1
|
68
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
69
|
+
# Configuration parameters: Include.
|
70
|
+
# Include: **/Rakefile, **/*.rake
|
71
|
+
Rails/RakeEnvironment:
|
72
|
+
Exclude:
|
73
|
+
- 'Rakefile'
|
74
|
+
|
75
|
+
# Offense count: 1
|
76
|
+
# This cop supports safe autocorrection (--autocorrect).
|
77
|
+
Rake/Desc:
|
78
|
+
Exclude:
|
79
|
+
- 'Rakefile'
|
80
|
+
|
81
|
+
# Offense count: 2
|
82
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
83
|
+
# Configuration parameters: AllowedReceivers.
|
84
|
+
# AllowedReceivers: Thread.current
|
85
|
+
Style/HashEachMethods:
|
86
|
+
Exclude:
|
87
|
+
- 'lib/authorized_persona/persona.rb'
|
88
|
+
|
89
|
+
# Offense count: 1
|
90
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
91
|
+
Style/MapToHash:
|
92
|
+
Exclude:
|
93
|
+
- 'lib/authorized_persona/authorization.rb'
|
94
|
+
|
95
|
+
# Offense count: 1
|
96
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
97
|
+
# Configuration parameters: Mode.
|
98
|
+
Style/StringConcatenation:
|
99
|
+
Exclude:
|
100
|
+
- 'lib/authorized_persona/view_helpers.rb'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0.6
|
data/Appraisals
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
appraise 'rails-6-0' do
|
2
|
+
gem 'railties', '~> 6.0.0'
|
3
|
+
gem 'activemodel', '~>6.0.0'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'rails-6-1' do
|
7
|
+
gem 'railties', '~> 6.1.0'
|
8
|
+
gem 'activemodel', '~>6.1.0'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise 'rails-7-0' do
|
12
|
+
gem 'railties', '~> 7.0.0'
|
13
|
+
gem 'activemodel', '~>7.0.0'
|
14
|
+
end
|
data/README.md
CHANGED
@@ -107,23 +107,24 @@ end
|
|
107
107
|
class ApplicationController < ActionController::Base
|
108
108
|
include AuthorizedPersona::Authorization
|
109
109
|
|
110
|
-
# Any
|
110
|
+
# Any hooks your authentication library needs to ensure
|
111
111
|
# `current_user` is set before # authorization, e.g.:
|
112
112
|
#
|
113
|
-
#
|
113
|
+
# before_action :authenticate_user!
|
114
114
|
|
115
115
|
authorize_persona class_name: "User"
|
116
116
|
|
117
117
|
# or optionally override the method name we use to fetch current_[class_name] e.g.:
|
118
118
|
#
|
119
|
-
# authorize_persona class_name: "User",
|
119
|
+
# authorize_persona class_name: "User", current_user_method: :current_fancy_user
|
120
120
|
|
121
121
|
# Your code here...
|
122
122
|
end
|
123
123
|
```
|
124
124
|
|
125
125
|
At this point, no user is authorized to make a request to any descendent
|
126
|
-
of `ApplicationController`.
|
126
|
+
of `ApplicationController`. Note that any unauthenticated controllers (e.g. authentication
|
127
|
+
controllers) will need to have authorization disabled via `skip_before_action :authorize!`.
|
127
128
|
|
128
129
|
3. Grant privileges in your base controller or any subclass:
|
129
130
|
|
data/authorized_persona.gemspec
CHANGED
@@ -22,13 +22,15 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
rails_version_range = [">= 5.1.6.2", "< 7"]
|
25
|
+
rails_version_range = [">= 5.1.6.2", "< 7.1"]
|
26
26
|
|
27
27
|
spec.add_dependency "railties", *rails_version_range
|
28
28
|
|
29
29
|
spec.add_development_dependency "activemodel", *rails_version_range
|
30
|
-
spec.add_development_dependency "
|
31
|
-
spec.add_development_dependency "
|
30
|
+
spec.add_development_dependency "appraisal"
|
31
|
+
spec.add_development_dependency "betterlint"
|
32
|
+
spec.add_development_dependency "bundler"
|
33
|
+
spec.add_development_dependency "rake"
|
32
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
-
spec.
|
35
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
34
36
|
end
|
@@ -13,7 +13,7 @@ module AuthorizedPersona
|
|
13
13
|
|
14
14
|
class_methods do
|
15
15
|
# Configure authorization for an authorized persona class
|
16
|
-
def authorize_persona(class_name:, current_user_method: nil) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/
|
16
|
+
def authorize_persona(class_name:, current_user_method: nil) # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/
|
17
17
|
raise AuthorizedPersona::Error, "you can only configure authorization once" if authorization_persona_class_name.present?
|
18
18
|
raise AuthorizedPersona::Error, "class_name must be a string" unless class_name.is_a?(String)
|
19
19
|
raise AuthorizedPersona::Error, "current_user_method must be a symbol" if current_user_method && !current_user_method.is_a?(Symbol)
|
@@ -36,13 +36,13 @@ module AuthorizedPersona
|
|
36
36
|
|
37
37
|
# Grants replace all previous grants to avoid privilege leakage
|
38
38
|
def grant(privileges) # rubocop:disable Metrics/AbcSize
|
39
|
-
self.authorized_actions =
|
39
|
+
self.authorized_actions = privileges.map { |auth_tier, actions| [auth_tier.to_s, [actions].flatten.map(&:to_sym)] }.to_h
|
40
40
|
|
41
41
|
tier_names = authorization_persona.authorization_tier_names
|
42
42
|
extra_keys = authorized_actions.keys - authorization_persona.authorization_tier_names
|
43
43
|
if extra_keys.present?
|
44
44
|
raise AuthorizedPersona::Error, "invalid grant: #{authorization_persona_class_name} " \
|
45
|
-
|
45
|
+
"has authorization tiers #{tier_names.join(', ')} but received extra keys: #{extra_keys.join(', ')}"
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -79,7 +79,7 @@ module AuthorizedPersona
|
|
79
79
|
def authorization_current_user
|
80
80
|
unless authorization_current_user_method.is_a?(Symbol)
|
81
81
|
raise AuthorizedPersona::Error, "you must configure authorization with a valid current_user method name, " \
|
82
|
-
|
82
|
+
"e.g. `authorize_persona class_name: 'User', current_user_method: :my_custom_current_user`"
|
83
83
|
end
|
84
84
|
|
85
85
|
send(self.class.authorization_current_user_method)
|
@@ -89,7 +89,7 @@ module AuthorizedPersona
|
|
89
89
|
self.class.authorized_tier(action: params[:action])
|
90
90
|
end
|
91
91
|
|
92
|
-
def authorize!
|
92
|
+
def authorize!
|
93
93
|
return if authorized?
|
94
94
|
|
95
95
|
respond_to do |format|
|
@@ -34,7 +34,7 @@ module AuthorizedPersona
|
|
34
34
|
end
|
35
35
|
|
36
36
|
# Configure the authorization tiers in my_tier_slug: "My Tier Title And Description" form from lowest to highest privilege.
|
37
|
-
def authorization_tiers(tiers) # rubocop:disable Metrics/AbcSize
|
37
|
+
def authorization_tiers(tiers) # rubocop:disable Metrics/AbcSize
|
38
38
|
raise AuthorizedPersona::Error, "you can only define authorization tiers once" if instance_variable_defined?(:@authorization_tiers)
|
39
39
|
|
40
40
|
if !tiers.is_a?(Hash) || !tiers.all? { |k, v| k.is_a?(Symbol) && v.is_a?(String) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authorized_persona
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mileham
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: 5.1.6.2
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '7'
|
22
|
+
version: '7.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: 5.1.6.2
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '7'
|
32
|
+
version: '7.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activemodel
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: 5.1.6.2
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '7'
|
42
|
+
version: '7.1'
|
43
43
|
type: :development
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,51 +49,51 @@ dependencies:
|
|
49
49
|
version: 5.1.6.2
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '7'
|
52
|
+
version: '7.1'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: appraisal
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
|
-
- - "
|
57
|
+
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
59
|
+
version: '0'
|
60
60
|
type: :development
|
61
61
|
prerelease: false
|
62
62
|
version_requirements: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- - "
|
64
|
+
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '
|
66
|
+
version: '0'
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
|
-
name:
|
68
|
+
name: betterlint
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
|
-
- - "
|
71
|
+
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
73
|
+
version: '0'
|
74
74
|
type: :development
|
75
75
|
prerelease: false
|
76
76
|
version_requirements: !ruby/object:Gem::Requirement
|
77
77
|
requirements:
|
78
|
-
- - "
|
78
|
+
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
80
|
+
version: '0'
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name:
|
82
|
+
name: bundler
|
83
83
|
requirement: !ruby/object:Gem::Requirement
|
84
84
|
requirements:
|
85
|
-
- - "
|
85
|
+
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: '
|
87
|
+
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
90
|
version_requirements: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
|
-
- - "
|
92
|
+
- - ">="
|
93
93
|
- !ruby/object:Gem::Version
|
94
|
-
version: '
|
94
|
+
version: '0'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
|
-
name:
|
96
|
+
name: rake
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
99
|
- - ">="
|
@@ -106,6 +106,20 @@ dependencies:
|
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rspec
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '3.0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '3.0'
|
109
123
|
description: AuthorizedPersona is a rails implementation of Betterment's Persona Centric
|
110
124
|
Authorization pattern
|
111
125
|
email:
|
@@ -114,10 +128,13 @@ executables: []
|
|
114
128
|
extensions: []
|
115
129
|
extra_rdoc_files: []
|
116
130
|
files:
|
131
|
+
- ".github/workflows/ci.yml"
|
117
132
|
- ".gitignore"
|
118
133
|
- ".rspec"
|
119
134
|
- ".rubocop.yml"
|
120
|
-
- ".
|
135
|
+
- ".rubocop_todo.yml"
|
136
|
+
- ".ruby-version"
|
137
|
+
- Appraisals
|
121
138
|
- CODE_OF_CONDUCT.md
|
122
139
|
- Gemfile
|
123
140
|
- LICENSE.txt
|
@@ -126,6 +143,9 @@ files:
|
|
126
143
|
- authorized_persona.gemspec
|
127
144
|
- bin/console
|
128
145
|
- bin/setup
|
146
|
+
- gemfiles/rails_6_0.gemfile
|
147
|
+
- gemfiles/rails_6_1.gemfile
|
148
|
+
- gemfiles/rails_7_0.gemfile
|
129
149
|
- lib/authorized_persona.rb
|
130
150
|
- lib/authorized_persona/authorization.rb
|
131
151
|
- lib/authorized_persona/persona.rb
|
@@ -135,8 +155,9 @@ files:
|
|
135
155
|
homepage: https://github.com/Betterment/authorized_persona
|
136
156
|
licenses:
|
137
157
|
- MIT
|
138
|
-
metadata:
|
139
|
-
|
158
|
+
metadata:
|
159
|
+
rubygems_mfa_required: 'true'
|
160
|
+
post_install_message:
|
140
161
|
rdoc_options: []
|
141
162
|
require_paths:
|
142
163
|
- lib
|
@@ -151,8 +172,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
172
|
- !ruby/object:Gem::Version
|
152
173
|
version: '0'
|
153
174
|
requirements: []
|
154
|
-
rubygems_version: 3.
|
155
|
-
signing_key:
|
175
|
+
rubygems_version: 3.4.12
|
176
|
+
signing_key:
|
156
177
|
specification_version: 4
|
157
178
|
summary: the simplest authorization library you will ever love
|
158
179
|
test_files: []
|