oauth-bwergemn 1.0.4 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28680e1cabddf3a646ce5e9b58ad26b9d6e6e5d5dfbc3b7ed18a625a2b0b13a4
4
- data.tar.gz: f198b7a8da14f14a5f66d3361c3ff31e3bddf6974b1d73bdcec3170022fbe524
3
+ metadata.gz: f1198087600f843b4a1500049f999e031aec3631b0d0db76020162883b125a3e
4
+ data.tar.gz: bc71b01282cd981b8e12e3b3f43f8ffb6a35ac30efd5d649af9decd691ce5612
5
5
  SHA512:
6
- metadata.gz: 9321d12b5598bb230196e8fd73162e1e0a51208108c3610e08b5cedac8ed4719fc0210311e3502226dd29830c06bef9a945a3bb924f49bab58a8c8b161d7c5ea
7
- data.tar.gz: c74d19c90247e8cea7871199ec6f8d7518970e66df2497344f672a1bd267ce4a68d260b89db18b927e440b2df795c95d9560b866dcd447cd9a95e369d4adc313
6
+ metadata.gz: 30c376fb21f5adc63f333de48d8e059beb9fb6a43df7228ea253297ade57122eb500f083f4ccb5a1833b822ed6425fae61e268f89f62d1b09154edcf2f5bfa34
7
+ data.tar.gz: c843b88a28e9962a15a0dcd7ec0b33da8b30d73444729dd4854cf9f95ff4155cfe2686a3ffad22b50e829ff0464092c40f552fd9d32abc273a4883f0ff6134ff
@@ -1,55 +1,66 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oauth-bwergemn (1.0.2)
5
- grape (~> 1.2.0)
4
+ oauth-bwergemn (1.0.8)
5
+ grape (~> 1.3.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (6.0.2.1)
10
+ activesupport (6.0.3.2)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 0.7, < 2)
13
13
  minitest (~> 5.1)
14
14
  tzinfo (~> 1.1)
15
- zeitwerk (~> 2.2)
16
- ast (2.4.0)
17
- axiom-types (0.1.1)
18
- descendants_tracker (~> 0.0.4)
19
- ice_nine (~> 0.11.0)
20
- thread_safe (~> 0.3, >= 0.3.1)
15
+ zeitwerk (~> 2.2, >= 2.2.2)
16
+ ast (2.4.1)
21
17
  builder (3.2.4)
22
- coercible (1.0.0)
23
- descendants_tracker (~> 0.0.1)
24
- concurrent-ruby (1.1.5)
25
- descendants_tracker (0.0.4)
26
- thread_safe (~> 0.3, >= 0.3.1)
27
- diff-lcs (1.3)
28
- equalizer (0.0.11)
29
- grape (1.2.5)
18
+ concurrent-ruby (1.1.6)
19
+ diff-lcs (1.4.4)
20
+ dry-configurable (0.11.6)
21
+ concurrent-ruby (~> 1.0)
22
+ dry-core (~> 0.4, >= 0.4.7)
23
+ dry-equalizer (~> 0.2)
24
+ dry-container (0.7.2)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-configurable (~> 0.1, >= 0.1.3)
27
+ dry-core (0.4.9)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-equalizer (0.3.0)
30
+ dry-inflector (0.2.0)
31
+ dry-logic (1.0.6)
32
+ concurrent-ruby (~> 1.0)
33
+ dry-core (~> 0.2)
34
+ dry-equalizer (~> 0.2)
35
+ dry-types (1.4.0)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-container (~> 0.3)
38
+ dry-core (~> 0.4, >= 0.4.4)
39
+ dry-equalizer (~> 0.3)
40
+ dry-inflector (~> 0.1, >= 0.1.2)
41
+ dry-logic (~> 1.0, >= 1.0.2)
42
+ grape (1.3.3)
30
43
  activesupport
31
44
  builder
45
+ dry-types (>= 1.1)
32
46
  mustermann-grape (~> 1.0.0)
33
47
  rack (>= 1.3.0)
34
48
  rack-accept
35
- virtus (>= 1.0.0)
36
- i18n (1.8.1)
49
+ i18n (1.8.3)
37
50
  concurrent-ruby (~> 1.0)
38
- ice_nine (0.11.2)
39
51
  jaro_winkler (1.5.4)
40
- minitest (5.13.0)
52
+ minitest (5.14.1)
41
53
  mustermann (1.1.1)
42
54
  ruby2_keywords (~> 0.0.1)
43
55
  mustermann-grape (1.0.1)
44
56
  mustermann (>= 1.0.0)
45
- parallel (1.19.1)
46
- parser (2.7.0.2)
47
- ast (~> 2.4.0)
48
- rack (2.0.8)
57
+ parallel (1.19.2)
58
+ parser (2.7.1.4)
59
+ ast (~> 2.4.1)
60
+ rack (2.2.3)
49
61
  rack-accept (0.4.5)
50
62
  rack (>= 0.4)
51
63
  rainbow (3.0.0)
52
- rake (10.5.0)
53
64
  rspec (3.7.0)
54
65
  rspec-core (~> 3.7.0)
55
66
  rspec-expectations (~> 3.7.0)
@@ -75,15 +86,10 @@ GEM
75
86
  ruby-progressbar (1.10.1)
76
87
  ruby2_keywords (0.0.2)
77
88
  thread_safe (0.3.6)
78
- tzinfo (1.2.6)
89
+ tzinfo (1.2.7)
79
90
  thread_safe (~> 0.1)
80
- unicode-display_width (1.6.0)
81
- virtus (1.0.5)
82
- axiom-types (~> 0.1)
83
- coercible (~> 1.0)
84
- descendants_tracker (~> 0.0, >= 0.0.3)
85
- equalizer (~> 0.0, >= 0.0.9)
86
- zeitwerk (2.2.2)
91
+ unicode-display_width (1.6.1)
92
+ zeitwerk (2.3.1)
87
93
 
88
94
  PLATFORMS
89
95
  ruby
@@ -91,7 +97,6 @@ PLATFORMS
91
97
  DEPENDENCIES
92
98
  bundler (~> 2.1.0)
93
99
  oauth-bwergemn!
94
- rake (~> 10.0)
95
100
  rspec (~> 3.7.0)
96
101
  rubocop (~> 0.79.0)
97
102
  rubocop-performance (~> 1.5.2)
@@ -21,6 +21,7 @@ module OauthBwergemn
21
21
  extend OauthBwergemn::Configuration
22
22
  define_setting :auth_strategy, 'hub'
23
23
  define_setting :resources, user: 'User'
24
+ define_setting :default_resources, :user
24
25
 
25
26
  def self.config_resources
26
27
  resources
@@ -52,13 +52,34 @@ module OauthBwergemn
52
52
  results
53
53
  end
54
54
 
55
+ def is_args_include_validate?
56
+ if args.keys.include?(:validate) && ![true, false].include?(args[:validate])
57
+ raise OauthBwergemn::Errors::InvalidScope.new("Not valid scope '#{args[:validate]}' in `oauth2 scope`")
58
+ end
59
+ args.keys.include?(:validate)
60
+ end
61
+
62
+ def is_args_include_as?
63
+ args.keys.include?(:as)
64
+ end
65
+
66
+ def token_optional?
67
+ is_args_include_validate? && [true, false].include?(args[:validate]) && args[:validate].eql?(false)
68
+ end
69
+
70
+ def token_required?
71
+ is_args_include_validate? && [true, false].include?(args[:validate]) && args[:validate].eql?(true) || is_args_include_validate?.blank?
72
+ end
73
+
55
74
  def authorize!
56
75
  access = Doorkeeper::AccessToken.find_by(token: token)
57
76
  unless access.present?
58
77
  raise OauthBwergemn::Errors::InvalidToken
59
78
  end
79
+ resource_as = (is_args_include_as? ? args[:as] : OauthBwergemn.default_resources)
80
+
60
81
  # rubocop:disable Security/Eval
61
- resource = eval(OauthBwergemn.resources[args[:as].to_sym]).find_by(id: access.resource_owner_id) rescue nil
82
+ resource = eval(OauthBwergemn.resources[resource_as.to_sym]).find_by(id: access.resource_owner_id) rescue nil
62
83
  # rubocop:enable Security/Eval
63
84
  {
64
85
  resource_owner: resource,
@@ -87,13 +108,23 @@ module OauthBwergemn
87
108
  return unless context.protected_endpoint?
88
109
 
89
110
  self.the_request = env
90
-
91
- if token.present? && context.protected_endpoint?
111
+ if token_optional? && context.protected_endpoint?
112
+ context.resource_token = token
113
+ context.resource_owner = nil
114
+ context.resource_credentials = nil
115
+ response = authorize! rescue nil
116
+ if response.present?
117
+ context.resource_owner = response[:resource_owner] rescue nil
118
+ context.resource_credentials = response[:resource_credentials] rescue nil
119
+ end
120
+ elsif token.present? && token_required? && context.protected_endpoint?
92
121
  response = authorize!
93
122
  context.resource_token = token
94
123
  context.resource_owner = response[:resource_owner] rescue nil
95
124
  context.resource_credentials = response[:resource_credentials] rescue nil
96
- elsif token.nil? && context.protected_endpoint?
125
+ elsif context.resource_owner.nil? && context.protected_endpoint?
126
+ raise OauthBwergemn::Errors::InvalidToken
127
+ else
97
128
  raise OauthBwergemn::Errors::InvalidToken
98
129
  end
99
130
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OauthBwergemn
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.9'
5
5
  public_constant :VERSION
6
6
  end
@@ -34,9 +34,8 @@ Gem::Specification.new do |spec|
34
34
  spec.require_paths = ['lib']
35
35
 
36
36
  spec.add_development_dependency 'bundler', '~> 2.1.0'
37
- spec.add_development_dependency 'rake', '~> 10.0'
38
37
  spec.add_development_dependency 'rspec', '~> 3.7.0'
39
38
  spec.add_development_dependency 'rubocop', '~> 0.79.0'
40
39
  spec.add_development_dependency 'rubocop-performance', '~> 1.5.2'
41
- spec.add_dependency 'grape', '~> 1.2.0'
40
+ spec.add_dependency 'grape', '~> 1.3.0'
42
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth-bwergemn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alam Ybs
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-12 00:00:00.000000000 Z
11
+ date: 2020-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.1.0
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +72,14 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: 1.2.0
75
+ version: 1.3.0
90
76
  type: :runtime
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: 1.2.0
82
+ version: 1.3.0
97
83
  description: Oauth Bwergemn is a Grape middleware to connect your API resources with
98
84
  your API authenticator.
99
85
  email: