doorkeeper-device_authorization_grant 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +320 -0
  4. data/Rakefile +34 -0
  5. data/app/controllers/doorkeeper/device_authorization_grant/device_authorizations_controller.rb +68 -0
  6. data/app/controllers/doorkeeper/device_authorization_grant/device_codes_controller.rb +28 -0
  7. data/app/views/doorkeeper/device_authorization_grant/device_authorizations/index.html.erb +19 -0
  8. data/config/locales/en.yml +15 -0
  9. data/db/migrate/20200629094624_create_doorkeeper_device_grants.rb +28 -0
  10. data/lib/doorkeeper/device_authorization_grant.rb +47 -0
  11. data/lib/doorkeeper/device_authorization_grant/config.rb +92 -0
  12. data/lib/doorkeeper/device_authorization_grant/engine.rb +12 -0
  13. data/lib/doorkeeper/device_authorization_grant/errors.rb +43 -0
  14. data/lib/doorkeeper/device_authorization_grant/oauth/device_authorization_request.rb +88 -0
  15. data/lib/doorkeeper/device_authorization_grant/oauth/device_authorization_response.rb +73 -0
  16. data/lib/doorkeeper/device_authorization_grant/oauth/device_code_request.rb +105 -0
  17. data/lib/doorkeeper/device_authorization_grant/oauth/helpers/user_code.rb +39 -0
  18. data/lib/doorkeeper/device_authorization_grant/orm/active_record.rb +27 -0
  19. data/lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant.rb +150 -0
  20. data/lib/doorkeeper/device_authorization_grant/rails/routes.rb +65 -0
  21. data/lib/doorkeeper/device_authorization_grant/rails/routes/mapper.rb +40 -0
  22. data/lib/doorkeeper/device_authorization_grant/rails/routes/mapping.rb +49 -0
  23. data/lib/doorkeeper/device_authorization_grant/request/device_authorization.rb +38 -0
  24. data/lib/doorkeeper/device_authorization_grant/version.rb +8 -0
  25. data/lib/doorkeeper/request/device_code.rb +33 -0
  26. data/lib/generators/doorkeeper/device_authorization_grant/install_generator.rb +16 -0
  27. data/lib/generators/doorkeeper/device_authorization_grant/templates/initializer.rb +33 -0
  28. metadata +139 -0
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doorkeeper
4
+ module DeviceAuthorizationGrant
5
+ module Request
6
+ # Doorkeeper strategy for OAuth 2.0 Device Authorization Requests.
7
+ #
8
+ # @see https://tools.ietf.org/html/rfc8628#section-3.1 RFC 8628, sect. 3.1
9
+ class DeviceAuthorization < ::Doorkeeper::Request::Strategy
10
+ delegate :client, to: :server
11
+
12
+ # @return [OAuth::DeviceAuthorizationRequest]
13
+ def request
14
+ @request ||= OAuth::DeviceAuthorizationRequest.new(
15
+ Doorkeeper.configuration,
16
+ client,
17
+ host_name
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ # @return [String]
24
+ def host_name
25
+ req = server.context.request
26
+ "#{req.scheme}://#{req.host}#{port}"
27
+ end
28
+
29
+ # @return [String, nil]
30
+ def port
31
+ return nil if [80, 443].include?(server.context.request.port)
32
+
33
+ ":#{server.context.request.port}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doorkeeper
4
+ module DeviceAuthorizationGrant
5
+ VERSION = '0.1.0'
6
+ public_constant :VERSION
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doorkeeper
4
+ module Request
5
+ # Doorkeeper strategy for OAuth 2.0 Device Access Token Requests.
6
+ #
7
+ # @see https://tools.ietf.org/html/rfc8628#section-3.4 RFC 8628, sect. 3.4
8
+ class DeviceCode < ::Doorkeeper::Request::Strategy
9
+ delegate :parameters, :client, to: :server
10
+
11
+ # @return [::Doorkeeper::DeviceAuthorizationGrant::OAuth::DeviceCodeRequest]
12
+ def request
13
+ @request ||=
14
+ ::Doorkeeper::DeviceAuthorizationGrant::OAuth::DeviceCodeRequest
15
+ .new(Doorkeeper.configuration, client, device_grant)
16
+ end
17
+
18
+ private
19
+
20
+ delegate :device_grant_model, to: :configuration
21
+
22
+ # @return [::Doorkeeper::DeviceAuthorizationGrant::DeviceGrant, nil]
23
+ def device_grant
24
+ @device_grant ||= device_grant_model.by_device_code(parameters[:device_code])
25
+ end
26
+
27
+ # @return [::Doorkeeper::DeviceAuthorizationGrant::Config]
28
+ def configuration
29
+ @configuration ||= DeviceAuthorizationGrant.configuration
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Doorkeeper
4
+ module DeviceAuthorizationGrant
5
+ # Rails generator to install DeviceAuthorizationGrant initializer and routes.
6
+ class InstallGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path('./templates', __dir__)
8
+ desc 'Installs Doorkeeper DeviceAuthorizationGrant.'
9
+
10
+ def install
11
+ template('initializer.rb', 'config/initializers/doorkeeper_device_authorization_grant.rb')
12
+ route('use_doorkeeper_device_authorization_grant')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ Doorkeeper::DeviceAuthorizationGrant.configure do
4
+ # Minimum device code polling interval expected from the client, expressed in seconds.
5
+ # device_code_polling_interval 5
6
+
7
+ # Device code expiration time, in seconds.
8
+ # device_code_expires_in 300
9
+
10
+ # Customizable reference to the DeviceGrant model.
11
+ # device_grant_class 'Doorkeeper::DeviceAuthorizationGrant::DeviceGrant'
12
+
13
+ # Reference to a model (or class) for user code generation.
14
+ #
15
+ # It must implement a `.generate` method, which can be invoked without
16
+ # arguments, to obtain a String user code value.
17
+ #
18
+ # user_code_generator 'Doorkeeper::DeviceAuthorizationGrant::OAuth::Helpers::UserCode'
19
+
20
+ # A Proc returning the end-user verification URI on the authorization server.
21
+ # verification_uri ->(host_name) do
22
+ # "#{host_name}/oauth/device"
23
+ # end
24
+
25
+ # A Proc returning the verification URI that includes the "user_code"
26
+ # (or other information with the same function as the "user_code"), which is
27
+ # designed for non-textual transmission. This is optional, so the Proc can
28
+ # also return `nil`.
29
+ #
30
+ # verification_uri_complete ->(verification_uri, host_name, device_grant) do
31
+ # "#{verification_uri}?user_code=#{CGI.escape(device_grant.user_code)}"
32
+ # end
33
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doorkeeper-device_authorization_grant
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - EXOP Group
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: doorkeeper
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.86.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.86.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.18.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.18.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.25
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.25
83
+ description: OAuth 2.0 Device Authorization Grant extension for Doorkeeper.
84
+ email:
85
+ - opensource@exop-group.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - MIT-LICENSE
91
+ - README.md
92
+ - Rakefile
93
+ - app/controllers/doorkeeper/device_authorization_grant/device_authorizations_controller.rb
94
+ - app/controllers/doorkeeper/device_authorization_grant/device_codes_controller.rb
95
+ - app/views/doorkeeper/device_authorization_grant/device_authorizations/index.html.erb
96
+ - config/locales/en.yml
97
+ - db/migrate/20200629094624_create_doorkeeper_device_grants.rb
98
+ - lib/doorkeeper/device_authorization_grant.rb
99
+ - lib/doorkeeper/device_authorization_grant/config.rb
100
+ - lib/doorkeeper/device_authorization_grant/engine.rb
101
+ - lib/doorkeeper/device_authorization_grant/errors.rb
102
+ - lib/doorkeeper/device_authorization_grant/oauth/device_authorization_request.rb
103
+ - lib/doorkeeper/device_authorization_grant/oauth/device_authorization_response.rb
104
+ - lib/doorkeeper/device_authorization_grant/oauth/device_code_request.rb
105
+ - lib/doorkeeper/device_authorization_grant/oauth/helpers/user_code.rb
106
+ - lib/doorkeeper/device_authorization_grant/orm/active_record.rb
107
+ - lib/doorkeeper/device_authorization_grant/orm/active_record/device_grant.rb
108
+ - lib/doorkeeper/device_authorization_grant/rails/routes.rb
109
+ - lib/doorkeeper/device_authorization_grant/rails/routes/mapper.rb
110
+ - lib/doorkeeper/device_authorization_grant/rails/routes/mapping.rb
111
+ - lib/doorkeeper/device_authorization_grant/request/device_authorization.rb
112
+ - lib/doorkeeper/device_authorization_grant/version.rb
113
+ - lib/doorkeeper/request/device_code.rb
114
+ - lib/generators/doorkeeper/device_authorization_grant/install_generator.rb
115
+ - lib/generators/doorkeeper/device_authorization_grant/templates/initializer.rb
116
+ homepage: https://github.com/exop-group/doorkeeper-device_authorization_grant
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.1.2
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: OAuth 2.0 Device Authorization Grant extension for Doorkeeper.
139
+ test_files: []