doorkeeper-device_authorization_grant 0.2.0 → 0.2.1

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: '08caf432de1258cd6b0dab0346a332f0a49698e35838194e1e6e9f999d1a2ccc'
4
- data.tar.gz: 98c6b042087cb1a1df1f84d4e9aca7327f2cb637eaee58729de53a0d76fd9900
3
+ metadata.gz: 87c9de51f80c701da39179d542265e15fc426cefdff8b7b70827305d27c89a16
4
+ data.tar.gz: '028cb5145903789550175cb6acdec567a214d4b84186d9e08fb9274b4016a4f3'
5
5
  SHA512:
6
- metadata.gz: 05dca92fad2e8ef88aae7d9739aa08c990dd5643c1ef4aab563b761d3afb1f08727efd2f508d45155e524943f9082203fa8e7019bd0829867a0c218266aa9fb8
7
- data.tar.gz: c603c13d33a65616bd370dac83625396318ee7e47e0dc16f99cd620c23ebd5e1df0f9a30a6b7915eb33f85dd9ba7e2d2284793c0156808c86350591e97ae9085
6
+ metadata.gz: 667775d114f8a4559eaf84e84e8806acbdae0555bacb57db2c13a73d07dc447a60a2e135b837ffb42382e403f43774ce02f9933e619a0a6a28b291f771898f33
7
+ data.tar.gz: d8e6b3a77372b2dfe23e4a5f65d669878403b3ed803e1b66861d9c8c1279d3b7ecad1c97313a74475bd0a2ecc107e81410f74f9bf5de259a94a1292d48b1701c
@@ -9,7 +9,7 @@ module Doorkeeper
9
9
  def create
10
10
  headers.merge!(authorize_response.headers)
11
11
  render(json: authorize_response.body, status: authorize_response.status)
12
- rescue Errors::DoorkeeperError => e
12
+ rescue Doorkeeper::Errors::DoorkeeperError => e
13
13
  handle_token_exception(e)
14
14
  end
15
15
 
@@ -1,4 +1,11 @@
1
1
  en:
2
+ activerecord:
3
+ errors:
4
+ models:
5
+ doorkeeper/device_authorization_grant/device_grant:
6
+ attributes:
7
+ scopes:
8
+ not_match_configured: "doesn't match configured on the server."
2
9
  doorkeeper:
3
10
  device_authorization_grant:
4
11
  device_authorizations:
@@ -18,11 +18,13 @@ module Doorkeeper
18
18
  # @param server
19
19
  # @param client
20
20
  # @param host_name [String]
21
- def initialize(server, client, host_name)
21
+ # @param parameters [Hash]
22
+ def initialize(server, client, host_name, parameters = {}) # rubocop:disable Style/OptionHash
22
23
  super()
23
24
  @server = server
24
25
  @client = client
25
26
  @host_name = host_name
27
+ @original_scopes = parameters[:scope]
26
28
  end
27
29
 
28
30
  # @return [DeviceAuthorizationResponse, Doorkeeper::OAuth::ErrorResponse]
@@ -10,7 +10,7 @@ module Doorkeeper
10
10
  extend ActiveSupport::Concern
11
11
  include ::Doorkeeper::Models::Expirable
12
12
 
13
- included do
13
+ included do # rubocop:disable Metrics/BlockLength
14
14
  self.table_name = "#{table_name_prefix}oauth_device_grants#{table_name_suffix}"
15
15
 
16
16
  delegate :secret_strategy, :fallback_secret_strategy, to: :class
@@ -28,6 +28,7 @@ module Doorkeeper
28
28
 
29
29
  validates :resource_owner_id, presence: true, if: -> { user_code.blank? }
30
30
  validates :resource_owner_id, absence: true, if: -> { user_code.present? }
31
+ validate :scopes_match_configured, if: :enforce_scopes?
31
32
 
32
33
  scope(
33
34
  :expired,
@@ -127,6 +128,19 @@ module Doorkeeper
127
128
  @raw_device_code = Doorkeeper::OAuth::Helpers::UniqueToken.generate
128
129
  secret_strategy.store_secret(self, :device_code, @raw_device_code)
129
130
  end
131
+
132
+ def scopes_match_configured
133
+ if scopes.present? && !Doorkeeper::OAuth::Helpers::ScopeChecker.valid?(
134
+ scope_str: scopes.to_s,
135
+ server_scopes: Doorkeeper.config.scopes
136
+ )
137
+ errors.add(:scopes, :not_match_configured)
138
+ end
139
+ end
140
+
141
+ def enforce_scopes?
142
+ Doorkeeper.config.enforce_configured_scopes?
143
+ end
130
144
  end
131
145
  end
132
146
  end
@@ -7,14 +7,15 @@ module Doorkeeper
7
7
  #
8
8
  # @see https://tools.ietf.org/html/rfc8628#section-3.1 RFC 8628, sect. 3.1
9
9
  class DeviceAuthorization < ::Doorkeeper::Request::Strategy
10
- delegate :client, to: :server
10
+ delegate :client, :parameters, to: :server
11
11
 
12
12
  # @return [OAuth::DeviceAuthorizationRequest]
13
13
  def request
14
14
  @request ||= OAuth::DeviceAuthorizationRequest.new(
15
15
  Doorkeeper.configuration,
16
16
  client,
17
- host_name
17
+ host_name,
18
+ parameters
18
19
  )
19
20
  end
20
21
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Doorkeeper
4
4
  module DeviceAuthorizationGrant
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.1'
6
6
  public_constant :VERSION
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doorkeeper-device_authorization_grant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - EXOP Group
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2021-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: doorkeeper