oauth-bwergemn 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -3
- data/lib/oauth_bwergemn/auth_methods/auth_methods.rb +0 -8
- data/lib/oauth_bwergemn/auth_strategies/hub.rb +6 -28
- data/lib/oauth_bwergemn/extension.rb +11 -15
- data/lib/oauth_bwergemn/oauth2.rb +14 -35
- data/lib/oauth_bwergemn/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e32151695d92c0c2ef047d74d9d719a751781f196049cb7904b0ed837f0bcf
|
4
|
+
data.tar.gz: df02811335d7aadd9e0d04bf74c0c171dea51200cb4c9d87dcf7a97a853ba4d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 681152cb13886f430109c5b4824a5e77807569a65018c4a1e20f3baaa049a1f089030079b305aa94d89dc526008e748ffadc5838f33589539a99895a81a5cb61
|
7
|
+
data.tar.gz: 934fa511ac7dcdbaf5cf1f99b7bc0ab909a4b951537c98201011bc9f695865d1449df45cf8bcc30f2fdc6adfbce9986f7a086d3936808a6e4fe0990953cff658
|
data/.rubocop.yml
CHANGED
@@ -730,8 +730,8 @@ Style/CommentedKeyword:
|
|
730
730
|
Enabled: true
|
731
731
|
|
732
732
|
Style/ConditionalAssignment:
|
733
|
-
Enabled:
|
734
|
-
EnforcedStyle:
|
733
|
+
Enabled: false
|
734
|
+
EnforcedStyle: assign_inside_condition
|
735
735
|
SingleLineConditionsOnly: true
|
736
736
|
IncludeTernaryExpressions: true
|
737
737
|
|
@@ -952,7 +952,7 @@ Style/RedundantSortBy:
|
|
952
952
|
Enabled: true
|
953
953
|
|
954
954
|
Style/RescueModifier:
|
955
|
-
Enabled:
|
955
|
+
Enabled: false
|
956
956
|
|
957
957
|
Style/RescueStandardError:
|
958
958
|
Enabled: true
|
@@ -13,14 +13,6 @@ module OauthBwergemn
|
|
13
13
|
@protected_endpoint || false
|
14
14
|
end
|
15
15
|
|
16
|
-
def optional_endpoint=(opt)
|
17
|
-
@optional_endpoint = opt
|
18
|
-
end
|
19
|
-
|
20
|
-
def optional_endpoint?
|
21
|
-
@optional_endpoint || false
|
22
|
-
end
|
23
|
-
|
24
16
|
# rubocop:disable Lint/DuplicateMethods
|
25
17
|
def resource_token
|
26
18
|
@_resource_token
|
@@ -3,46 +3,24 @@
|
|
3
3
|
module OauthBwergemn
|
4
4
|
module AuthStrategies
|
5
5
|
class Hub < OauthBwergemn::BaseStrategy
|
6
|
-
def optional_endpoint?
|
7
|
-
has_authorizations? && !!optional_oauth2
|
8
|
-
end
|
9
|
-
|
10
6
|
def endpoint_protected?
|
11
|
-
|
7
|
+
!!endpoint_authorizations
|
12
8
|
end
|
13
9
|
|
14
10
|
def has_auth_scopes?
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
!!endpoint_authorizations &&
|
12
|
+
endpoint_authorizations.key?(:scopes) &&
|
13
|
+
!endpoint_authorizations[:scopes].empty?
|
18
14
|
end
|
19
15
|
|
20
16
|
def auth_scopes
|
21
|
-
|
22
|
-
optional_oauth2.map { |s| s.is_a?(String) || s.is_a?(Symbol) ? s.to_sym : s }
|
23
|
-
else
|
24
|
-
authorization_type_oauth2.map { |s| s.is_a?(String) || s.is_a?(Symbol) ? s.to_sym : s }
|
25
|
-
end
|
17
|
+
endpoint_authorizations[:scopes].map { |s| s.is_a?(String) || s.is_a?(Symbol) ? s.to_sym : s }
|
26
18
|
end
|
27
19
|
|
28
20
|
private
|
29
21
|
|
30
|
-
def has_authorizations?
|
31
|
-
!!endpoint_authorizations
|
32
|
-
end
|
33
|
-
|
34
22
|
def endpoint_authorizations
|
35
|
-
api_context.options[:route_options][:auth]
|
36
|
-
rescue
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
|
40
|
-
def authorization_type_oauth2
|
41
|
-
endpoint_authorizations
|
42
|
-
end
|
43
|
-
|
44
|
-
def optional_oauth2
|
45
|
-
endpoint_authorizations
|
23
|
+
api_context.options[:route_options][:auth]
|
46
24
|
end
|
47
25
|
end
|
48
26
|
end
|
@@ -3,26 +3,22 @@
|
|
3
3
|
module OauthBwergemn
|
4
4
|
module Extension
|
5
5
|
def oauth2(*scopes)
|
6
|
-
|
7
|
-
|
6
|
+
scopes = Doorkeeper.configuration.default_scopes.all if scopes.all? { |x| x.nil? }
|
7
|
+
if respond_to?(:route_setting) # >= grape-0.10.0
|
8
|
+
description = route_setting(:description) || route_setting(:description, {})
|
8
9
|
else
|
9
|
-
@last_description ||= {}
|
10
|
+
description = @last_description ||= {}
|
10
11
|
end
|
11
|
-
|
12
|
+
# case WineBouncer.configuration.auth_strategy
|
13
|
+
# when :default
|
12
14
|
description[:auth] = { scopes: scopes }
|
15
|
+
# when :swagger
|
13
16
|
description[:authorizations] = { oauth2: scopes.map { |x| { scope: x } } }
|
17
|
+
# end
|
14
18
|
end
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
@last_description ||= {}
|
21
|
-
end
|
22
|
-
|
23
|
-
description[:authorizations] = { optional_oauth2: scopes.map { |x| { scope: x } } }
|
24
|
-
end
|
25
|
-
|
26
|
-
Grape::API.extend self
|
20
|
+
# Grape::API::Instance is defined in grape 1.2.0 or above
|
21
|
+
grape_api = defined?(Grape::API::Instance) ? Grape::API::Instance : Grape::API
|
22
|
+
grape_api.extend self
|
27
23
|
end
|
28
24
|
end
|
@@ -19,16 +19,16 @@ module OauthBwergemn
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def token
|
22
|
-
|
22
|
+
if request.headers['Authorization'].present?
|
23
23
|
if request.headers['Authorization'].include?('bearer')
|
24
|
-
request.headers['Authorization'].try('split', 'bearer').try(:last).try(:strip)
|
24
|
+
token = request.headers['Authorization'].try('split', 'bearer').try(:last).try(:strip)
|
25
25
|
elsif request.headers['Authorization'].include?('Bearer')
|
26
|
-
request.headers['Authorization'].try('split', 'Bearer').try(:last).try(:strip)
|
26
|
+
token = request.headers['Authorization'].try('split', 'Bearer').try(:last).try(:strip)
|
27
27
|
else
|
28
|
-
request.headers['Authorization']
|
28
|
+
token = request.headers['Authorization']
|
29
29
|
end
|
30
30
|
else
|
31
|
-
request.parameters['access_token']
|
31
|
+
token = request.parameters['access_token']
|
32
32
|
end
|
33
33
|
token
|
34
34
|
end
|
@@ -37,14 +37,6 @@ module OauthBwergemn
|
|
37
37
|
# Authorization control.
|
38
38
|
############
|
39
39
|
|
40
|
-
def endpoint_protected?
|
41
|
-
auth_strategy.endpoint_protected?
|
42
|
-
end
|
43
|
-
|
44
|
-
def optional_endpoint?
|
45
|
-
auth_strategy.optional_endpoint?
|
46
|
-
end
|
47
|
-
|
48
40
|
def args
|
49
41
|
results = {}
|
50
42
|
auth_strategy.auth_scopes.map { |s| (results = results.merge(s)) if s.is_a?(Hash) }
|
@@ -62,13 +54,9 @@ module OauthBwergemn
|
|
62
54
|
unless access.present?
|
63
55
|
raise OauthBwergemn::Errors::InvalidToken
|
64
56
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
# rubocop:enable Security/Eval
|
69
|
-
rescue
|
70
|
-
nil
|
71
|
-
end
|
57
|
+
# rubocop:disable Security/Eval
|
58
|
+
resource = eval(OauthBwergemn.resources[args[:as].to_sym]).find_by(id: access.resource_owner_id) rescue nil
|
59
|
+
# rubocop:enable Security/Eval
|
72
60
|
{
|
73
61
|
resource_owner: resource,
|
74
62
|
resource_credential: {
|
@@ -92,25 +80,16 @@ module OauthBwergemn
|
|
92
80
|
context.extend(OauthBwergemn::AuthMethods)
|
93
81
|
|
94
82
|
context.protected_endpoint = endpoint_protected?
|
95
|
-
context.optional_endpoint = optional_endpoint?
|
96
83
|
|
97
|
-
return unless context.protected_endpoint?
|
84
|
+
return unless context.protected_endpoint?
|
98
85
|
|
99
86
|
self.the_request = env
|
100
87
|
|
101
|
-
if token.present? &&
|
102
|
-
response
|
103
|
-
context.resource_token
|
104
|
-
context.resource_owner
|
105
|
-
|
106
|
-
rescue
|
107
|
-
nil
|
108
|
-
end
|
109
|
-
context.resource_credentials = begin
|
110
|
-
response[:resource_credentials]
|
111
|
-
rescue
|
112
|
-
nil
|
113
|
-
end
|
88
|
+
if token.present? && context.protected_endpoint?
|
89
|
+
response = authorize!
|
90
|
+
context.resource_token = token
|
91
|
+
context.resource_owner = response[:resource_owner] rescue nil
|
92
|
+
context.resource_credentials = response[:resource_credentials] rescue nil
|
114
93
|
elsif token.nil? && context.protected_endpoint?
|
115
94
|
raise OauthBwergemn::Errors::InvalidToken
|
116
95
|
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
|
+
version: 1.0.3
|
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-
|
11
|
+
date: 2020-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|