oauth-bwergemn 1.0.9 → 1.0.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1198087600f843b4a1500049f999e031aec3631b0d0db76020162883b125a3e
4
- data.tar.gz: bc71b01282cd981b8e12e3b3f43f8ffb6a35ac30efd5d649af9decd691ce5612
3
+ metadata.gz: e46c6acfa64976a4efd66ac4e880f2b82c83354d275b81edadbd66632563c0db
4
+ data.tar.gz: 813e8774a700ed3225a3a5065928d39500b1110b2ee54e68dd6d229ed374ffc9
5
5
  SHA512:
6
- metadata.gz: 30c376fb21f5adc63f333de48d8e059beb9fb6a43df7228ea253297ade57122eb500f083f4ccb5a1833b822ed6425fae61e268f89f62d1b09154edcf2f5bfa34
7
- data.tar.gz: c843b88a28e9962a15a0dcd7ec0b33da8b30d73444729dd4854cf9f95ff4155cfe2686a3ffad22b50e829ff0464092c40f552fd9d32abc273a4883f0ff6134ff
6
+ metadata.gz: 28f9010d626ed0d8e1c4d51cb6fe370eb95eed73485077cbd1146caf1504cf8579c66d6725514c8b161d3f334464fdb7f98c9488898531ac4ee3890e7dbe010c
7
+ data.tar.gz: 05ecce137a71d52d379dbbb72674abd5b54c731ffa2c42d394720002f7344f544612fb2a644338e1d8f8d0b57bd6a01ac552e8c7fb0634b6746086cf3a99de80
@@ -49,18 +49,30 @@ module OauthBwergemn
49
49
  def scopes
50
50
  results = []
51
51
  auth_strategy.auth_scopes.map { |s| (results << s) unless s.is_a?(Hash) }
52
- results
52
+ results.map! &:to_sym
53
+ end
54
+
55
+ def access_scopes access
56
+ access.scopes.all.map!(&:to_sym) rescue []
53
57
  end
54
58
 
55
59
  def is_args_include_validate?
56
- if args.keys.include?(:validate) && ![true, false].include?(args[:validate])
60
+ if args.key?(:validate) && ![true, false].include?(args[:validate])
57
61
  raise OauthBwergemn::Errors::InvalidScope.new("Not valid scope '#{args[:validate]}' in `oauth2 scope`")
58
62
  end
59
- args.keys.include?(:validate)
63
+ args.key?(:validate)
60
64
  end
61
65
 
62
66
  def is_args_include_as?
63
- args.keys.include?(:as)
67
+ args.key?(:as)
68
+ end
69
+
70
+ def scope_authorize! access
71
+ if scopes.present? && access
72
+ unless (scopes & (access_scopes access)).present?
73
+ raise OauthBwergemn::Errors::InvalidScope.new('OAuth Scope is disallowed')
74
+ end
75
+ end
64
76
  end
65
77
 
66
78
  def token_optional?
@@ -76,16 +88,16 @@ module OauthBwergemn
76
88
  unless access.present?
77
89
  raise OauthBwergemn::Errors::InvalidToken
78
90
  end
91
+ scope_authorize! access
79
92
  resource_as = (is_args_include_as? ? args[:as] : OauthBwergemn.default_resources)
80
-
81
93
  # rubocop:disable Security/Eval
82
- resource = eval(OauthBwergemn.resources[resource_as.to_sym]).find_by(id: access.resource_owner_id) rescue nil
94
+ resource = eval(OauthBwergemn.resources[resource_as.to_sym]).where(id: access.resource_owner_id).last rescue nil
83
95
  # rubocop:enable Security/Eval
84
96
  {
85
97
  resource_owner: resource,
86
98
  resource_credential: {
87
99
  access_token: access.token,
88
- scopes: scopes,
100
+ scopes: (access_scopes access),
89
101
  token_type: 'bearer',
90
102
  expires_in: access.expires_in,
91
103
  refresh_token: access.refresh_token,
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OauthBwergemn
4
- VERSION = '1.0.9'
4
+ VERSION = '1.0.10'
5
5
  public_constant :VERSION
6
6
  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.9
4
+ version: 1.0.10
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-07-03 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler