activeadmin-device_authorization 0.1.3 → 0.3.0
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/CHANGELOG.md +16 -1
- data/README.md +51 -18
- data/activeadmin-device_authorization.gemspec +13 -2
- data/app/views/active_admin/device_authorization/_consent.html.erb +77 -60
- data/lib/active_admin/device_authorization/configuration.rb +20 -3
- data/lib/active_admin/device_authorization/device_authorization_request.rb +3 -1
- data/lib/active_admin/device_authorization/engine.rb +18 -0
- data/lib/active_admin/device_authorization/page.rb +69 -68
- data/lib/active_admin/device_authorization/routes.rb +18 -44
- data/lib/active_admin/device_authorization/version.rb +1 -1
- metadata +165 -9
- data/app/controllers/active_admin/device_authorization/consents_controller.rb +0 -83
- data/app/views/active_admin/device_authorization/_standalone_styles.html.erb +0 -147
- data/app/views/active_admin/device_authorization/consents/index.html.erb +0 -19
- data/app/views/active_admin/device_authorization/consents/show.html.erb +0 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72adec60f28b252c649bee7dbf63751b0a2816839c4db22432cd713b3268dc90
|
|
4
|
+
data.tar.gz: 86a971e70328d02e98ef954f5043b085627d5157003425be94adda729cbf47ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4cdc2f8bf7811ba4767b737da76845e173e033de9dbd0612ba1e010412bb6a4d53235ae489f0ca0e1a10cb3179b5d10d73c029c1453448ebae48575c92cb4a8
|
|
7
|
+
data.tar.gz: feebea0eca1d77bfa901886a9b61ca23a2027e656f16dc79bf89f1e1ad3dab401df029707f61b06f0b874cfc9aa2cf98d652b29c4bf6d0bae357ac519406176f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.3.0 (2026-11-16)
|
|
4
|
+
|
|
5
|
+
- BREAKING: Consent UI is only the ActiveAdmin Device Auth page (`ActiveAdmin.routes`); remove `consent: :controller` and ConsentsController
|
|
6
|
+
- BREAKING: `Routes.draw` draws public OAuth endpoints only and applies `path_namespace` itself (one line at routes root; do not wrap in `namespace :admin`)
|
|
7
|
+
- BREAKING: `verification_uri_complete` uses a `user_code` query parameter instead of a path suffix
|
|
8
|
+
- Register the Device Auth page from `ActiveAdmin.after_load` when `register_active_admin_page` is true
|
|
9
|
+
- Allow manual `Page.register!` when `register_active_admin_page` is false (engine auto-register stays gated)
|
|
10
|
+
- Show the enter-code title on Device Auth when no grant is loaded
|
|
11
|
+
- Document the ActiveAdmin consent vs explicit OAuth split as RFC-0002
|
|
12
|
+
|
|
13
|
+
## 0.2.0 (2026-10-28)
|
|
14
|
+
|
|
15
|
+
- BREAKING: Require ActiveAdmin 4 (`>= 4.0.0.beta19`); drop ActiveAdmin 3 support
|
|
16
|
+
- Ship ActiveAdmin 4 consent markup: `.attributes-table`, self-contained verify prompt, Approve/Deny submits inside `.formtastic`
|
|
17
|
+
- Resolve `current_resource_owner` with `instance_exec` for zero-arity procs so private authentication helpers work
|
|
18
|
+
- Document page policy hooks `approve?` / `deny?` / `step_up?`
|
|
4
19
|
|
|
5
20
|
## 0.1.3 (2026-10-26)
|
|
6
21
|
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@ RFC 8628-style device authorization for ActiveAdmin: public device/token endpoin
|
|
|
8
8
|
|
|
9
9
|
- Ruby 3.4+
|
|
10
10
|
- Rails 7.2.3.2+
|
|
11
|
-
- ActiveAdmin
|
|
11
|
+
- ActiveAdmin 4.0.0.beta19+ (Tailwind theme; ActiveAdmin 3 is unsupported)
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
@@ -30,7 +30,7 @@ Maintainers publish with `make release` (`usr/bin/release.rb`), which builds, pu
|
|
|
30
30
|
|
|
31
31
|
## Why these settings are configurable
|
|
32
32
|
|
|
33
|
-
- `challenge_expires_in` (default 600s): RFC 8628 requires `expires_in` for device/user codes. The RFC example is 1800s;
|
|
33
|
+
- `challenge_expires_in` (default 600s): RFC 8628 requires `expires_in` for device/user codes. The RFC example is 1800s; this gem defaults to 600s. Always required; device codes must expire.
|
|
34
34
|
- `poll_interval` (default 5s): RFC 8628 `interval`; clients must use 5 when omitted.
|
|
35
35
|
- `slow_down_increment` (default 5s): RFC 8628 `slow_down` requires increasing the interval by 5s. Keep 5 unless you have a documented reason.
|
|
36
36
|
- `access_token_absolute_ttl` (default 4h): Absolute bearer cap (RFC 6819 short-lived access tokens). Set to `nil` to disable absolute expiry.
|
|
@@ -52,7 +52,11 @@ ActiveAdmin::DeviceAuthorization.configure do |config|
|
|
|
52
52
|
config.client_class_name = "DeviceAuthorizationClient"
|
|
53
53
|
config.grant_class_name = "DeviceAuthorizationGrant"
|
|
54
54
|
config.access_token_class_name = "DeviceAuthorizationAccessToken"
|
|
55
|
-
|
|
55
|
+
# Prefer zero-arity: the gem runs this with instance_exec on the controller.
|
|
56
|
+
# Auth helpers are often private; do not call them with an explicit receiver.
|
|
57
|
+
config.current_resource_owner = -> { current_admin_user }
|
|
58
|
+
# Arity-1 form still works; use send when the helper is private:
|
|
59
|
+
# config.current_resource_owner = ->(controller) { controller.send(:current_admin_user) }
|
|
56
60
|
|
|
57
61
|
config.scopes = %w[api:read api:write]
|
|
58
62
|
config.default_scopes = %w[api:read api:write]
|
|
@@ -83,15 +87,19 @@ end
|
|
|
83
87
|
```
|
|
84
88
|
|
|
85
89
|
```ruby
|
|
86
|
-
# config/routes.rb (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
# Optional: Routes.draw(self, consent: :controller) serves the code-entry and
|
|
90
|
-
# consent pages from the gem instead of ActiveAdmin page actions.
|
|
91
|
-
end
|
|
90
|
+
# config/routes.rb (at the mapper root; draws /admin/oauth/... only)
|
|
91
|
+
ActiveAdmin.routes(self)
|
|
92
|
+
ActiveAdmin::DeviceAuthorization::Routes.draw(self)
|
|
92
93
|
```
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
Consent UI is the ActiveAdmin "Device Auth" page (index plus `approve` / `deny` /
|
|
96
|
+
`step_up` page_actions). It is drawn by `ActiveAdmin.routes` and authenticated
|
|
97
|
+
through `ActiveAdmin::BaseController`. Do not nest `Routes.draw` under another
|
|
98
|
+
`namespace :admin` (that double-prefixes the OAuth path). OAuth controller paths
|
|
99
|
+
are absolute (`/active_admin/device_authorization/...`) so the admin namespace
|
|
100
|
+
does not invent `Admin::ActiveAdmin::...` constants. OAuth endpoints stay public
|
|
101
|
+
protocol surfaces (rate limits plus `client_id` / `device_code`); they do not use
|
|
102
|
+
the admin session. See RFC-0002.
|
|
95
103
|
|
|
96
104
|
`access_token_absolute_ttl` is the hard ceiling. Consent `min` / `max` / `default` / `choices` must sit inside that ceiling; `clamp_absolute_ttl` uses `min(access_token_max_absolute_ttl, access_token_absolute_ttl)`.
|
|
97
105
|
|
|
@@ -108,6 +116,28 @@ The gem does not replace host security controls. Before production traffic:
|
|
|
108
116
|
- Schedule `bundle exec rake active_admin:device_authorization:retention` at the cadence required by the host retention policy. Token retention deletes rows past `token_retention_period` after absolute expiry, revoke, or idle expiry (when idle TTL is enabled). Do not rely on absolute expiry alone when absolute TTL is nil (far-future sentinel).
|
|
109
117
|
- Implement host models and indexes that match the contract below, including uniqueness and foreign keys.
|
|
110
118
|
- Authenticate bearer tokens in the host API (see Bearer validation contract). The gem issues and expires tokens; it does not install API authentication middleware.
|
|
119
|
+
- When the host authorizes ActiveAdmin pages with an adapter that maps actions to `action_name?` methods, define `approve?`, `deny?`, and `step_up?` on the page policy. Missing methods fail closed and Approve/Deny/step-up return unauthorized. `step_up?` is needed only when `on_approve_step_up` is configured.
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
# Example page policy hooks for Device Auth
|
|
123
|
+
class ActiveAdmin::PagePolicy < ApplicationPolicy
|
|
124
|
+
def show?
|
|
125
|
+
true
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def approve?
|
|
129
|
+
show?
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def deny?
|
|
133
|
+
show?
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def step_up?
|
|
137
|
+
show?
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
```
|
|
111
141
|
|
|
112
142
|
### Host model contract
|
|
113
143
|
|
|
@@ -123,16 +153,15 @@ The gem does not replace host security controls. Before production traffic:
|
|
|
123
153
|
|
|
124
154
|
The gem issues and expires tokens, but it does not install authentication in the host API. For every protected request, the host must digest the presented bearer value with `ActiveAdmin::DeviceAuthorization.config.digest`, find the matching token through the allowed client or resource-owner relation, reject it when `AccessTokenExpiry#expired?` is true, enforce its scopes, and update `last_used_at` only after successful authentication. A missing, revoked, expired, or out-of-scope token must fail closed.
|
|
125
155
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
```
|
|
156
|
+
When `register_active_admin_page` is true (default), the engine registers the
|
|
157
|
+
Device Auth page from `ActiveAdmin.after_load`. Set it to false and call
|
|
158
|
+
`ActiveAdmin::DeviceAuthorization::Page.register!` yourself only when you need
|
|
159
|
+
to own registration timing.
|
|
131
160
|
|
|
132
161
|
## Protocol
|
|
133
162
|
|
|
134
163
|
1. `POST /admin/oauth/device_authorization` with `client_id` and `scope`
|
|
135
|
-
2. Open `verification_uri` / `verification_uri_complete` while signed in as an admin user
|
|
164
|
+
2. Open `verification_uri` / `verification_uri_complete` (`?user_code=...`) while signed in as an admin user
|
|
136
165
|
3. Approve or deny (optional host `before_approve` / `on_approve_step_up` for step-up second factor before Approve; Deny is ungated)
|
|
137
166
|
4. Poll `POST /admin/oauth/token` with `grant_type=urn:ietf:params:oauth:grant-type:device_code`
|
|
138
167
|
|
|
@@ -141,13 +170,17 @@ ActiveAdmin::DeviceAuthorization::Page.register!
|
|
|
141
170
|
```bash
|
|
142
171
|
bundle install
|
|
143
172
|
bundle exec appraisal install
|
|
173
|
+
npm install && npx playwright install chromium
|
|
144
174
|
make lint
|
|
145
175
|
make test
|
|
146
176
|
```
|
|
147
177
|
|
|
148
|
-
Matrixed Rails versions use [Appraisal](https://github.com/thoughtbot/appraisal): `gemfiles/rails72.gemfile`, `rails8ruby34.gemfile`, and `rails8ruby4.gemfile
|
|
178
|
+
Matrixed Rails versions use [Appraisal](https://github.com/thoughtbot/appraisal): `gemfiles/rails72.gemfile`, `rails8ruby34.gemfile`, and `rails8ruby4.gemfile`, each pinned to ActiveAdmin 4.0.0.beta23. Run `bundle exec appraisal rspec` to execute RSpec in each gemfile context.
|
|
179
|
+
|
|
180
|
+
Browser e2e uses Capybara + Playwright against `spec/dummy` (ActiveAdmin session,
|
|
181
|
+
device authorization consent, and bearer-protected API). See `spec/README.md`.
|
|
149
182
|
|
|
150
|
-
|
|
183
|
+
Trunk config lives in `.trunk/`; CI can run `trunk` via `.github/workflows/_trunk_check.yml`. Releases: `make release` or `usr/bin/release.rb`.
|
|
151
184
|
|
|
152
185
|
## Security
|
|
153
186
|
|
|
@@ -43,18 +43,29 @@ Gem::Specification.new do |spec|
|
|
|
43
43
|
|
|
44
44
|
spec.require_paths = ["lib"]
|
|
45
45
|
|
|
46
|
-
spec.add_dependency "activeadmin", ">=
|
|
46
|
+
spec.add_dependency "activeadmin", ">= 4.0.0.beta19", "< 5"
|
|
47
47
|
spec.add_dependency "rails", ">= 7.2.3.2"
|
|
48
48
|
|
|
49
49
|
spec.add_development_dependency "appraisal", "~> 2"
|
|
50
|
+
spec.add_development_dependency "activeadmin-graphql", ">= 0.4.1"
|
|
50
51
|
spec.add_development_dependency "bundler", ">= 2"
|
|
51
52
|
spec.add_development_dependency "bundler-audit", "~> 0.9"
|
|
52
|
-
spec.add_development_dependency "
|
|
53
|
+
spec.add_development_dependency "capybara", "~> 3.40"
|
|
54
|
+
spec.add_development_dependency "capybara-playwright-driver", "~> 0.5"
|
|
55
|
+
spec.add_development_dependency "cssbundling-rails"
|
|
56
|
+
spec.add_development_dependency "database_cleaner-active_record", "~> 2.2"
|
|
57
|
+
spec.add_development_dependency "devise", ">= 4.9"
|
|
58
|
+
spec.add_development_dependency "importmap-rails"
|
|
59
|
+
spec.add_development_dependency "polyrun", ">= 2.2.9"
|
|
60
|
+
spec.add_development_dependency "puma", ">= 5.0"
|
|
53
61
|
spec.add_development_dependency "rake", "~> 13"
|
|
54
62
|
spec.add_development_dependency "rbs", "~> 4"
|
|
55
63
|
spec.add_development_dependency "rspec", "~> 3"
|
|
64
|
+
spec.add_development_dependency "rspec-rails", ">= 6"
|
|
56
65
|
spec.add_development_dependency "rubocop-rspec", "~> 3.8"
|
|
57
66
|
spec.add_development_dependency "rubocop-thread_safety", "~> 0.7"
|
|
67
|
+
spec.add_development_dependency "sprockets-rails"
|
|
68
|
+
spec.add_development_dependency "sqlite3", ">= 2.1"
|
|
58
69
|
spec.add_development_dependency "standard", "~> 1.52"
|
|
59
70
|
spec.add_development_dependency "standard-custom", "~> 1.0"
|
|
60
71
|
spec.add_development_dependency "standard-performance", "~> 1.8"
|
|
@@ -10,18 +10,25 @@
|
|
|
10
10
|
font-size: 1.1em;
|
|
11
11
|
letter-spacing: 0.08em;
|
|
12
12
|
}
|
|
13
|
-
.device-auth-
|
|
13
|
+
.device-auth-verify {
|
|
14
|
+
border: 1px solid #8a2f1d;
|
|
15
|
+
border-radius: 0.25rem;
|
|
16
|
+
background: #f8e8e4;
|
|
17
|
+
color: #5c1f14;
|
|
18
|
+
margin: 0 0 1rem;
|
|
19
|
+
padding: 0.75rem 0.9rem;
|
|
20
|
+
}
|
|
21
|
+
.device-auth-actions {
|
|
14
22
|
display: flex;
|
|
15
23
|
flex-direction: column;
|
|
16
24
|
gap: 0.65rem;
|
|
17
|
-
|
|
18
|
-
margin: 0;
|
|
19
|
-
padding: 0;
|
|
25
|
+
margin-top: 0.75rem;
|
|
20
26
|
}
|
|
21
27
|
@media (min-width: 40rem) {
|
|
22
|
-
.device-auth-actions
|
|
28
|
+
.device-auth-actions {
|
|
23
29
|
flex-direction: row;
|
|
24
30
|
flex-wrap: wrap;
|
|
31
|
+
align-items: flex-end;
|
|
25
32
|
}
|
|
26
33
|
}
|
|
27
34
|
</style>
|
|
@@ -35,24 +42,26 @@
|
|
|
35
42
|
|
|
36
43
|
<div class="panel">
|
|
37
44
|
<div class="panel-body">
|
|
38
|
-
<
|
|
39
|
-
<
|
|
40
|
-
<
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
<div class="attributes-table">
|
|
46
|
+
<table>
|
|
47
|
+
<tbody>
|
|
48
|
+
<tr>
|
|
49
|
+
<th scope="row"><%= t("active_admin.device_authorization.client") %></th>
|
|
50
|
+
<td><%= client.name %></td>
|
|
51
|
+
</tr>
|
|
52
|
+
<tr>
|
|
53
|
+
<th scope="row"><%= t("active_admin.device_authorization.user_code") %></th>
|
|
54
|
+
<td><code class="device-auth-user-code"><%= grant.user_code %></code></td>
|
|
55
|
+
</tr>
|
|
56
|
+
<tr>
|
|
57
|
+
<th scope="row"><%= t("active_admin.device_authorization.status") %></th>
|
|
58
|
+
<td><%= grant.status %></td>
|
|
59
|
+
</tr>
|
|
60
|
+
</tbody>
|
|
61
|
+
</table>
|
|
62
|
+
</div>
|
|
54
63
|
|
|
55
|
-
<div class="
|
|
64
|
+
<div class="device-auth-verify" role="status">
|
|
56
65
|
<%= t("active_admin.device_authorization.verify_code") %>
|
|
57
66
|
</div>
|
|
58
67
|
|
|
@@ -61,49 +70,57 @@
|
|
|
61
70
|
<% end %>
|
|
62
71
|
|
|
63
72
|
<% if grant.pending? %>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
<%=
|
|
75
|
-
|
|
73
|
+
<div class="device-auth-actions">
|
|
74
|
+
<%= form_with url: url_for(action: :approve), method: :post, id: "device-auth-approve", data: {turbo: false}, class: "formtastic" do %>
|
|
75
|
+
<%= hidden_field_tag :user_code, grant.user_code %>
|
|
76
|
+
<% if available_scopes.any? %>
|
|
77
|
+
<fieldset class="inputs">
|
|
78
|
+
<legend><%= t("active_admin.device_authorization.scopes") %></legend>
|
|
79
|
+
<p class="inline-hints"><%= t("active_admin.device_authorization.scopes_hint") %></p>
|
|
80
|
+
<% available_scopes.each do |scope| %>
|
|
81
|
+
<% field_id = "scope_#{scope.tr(":", "_")}" %>
|
|
82
|
+
<li class="choice">
|
|
83
|
+
<label for="<%= field_id %>">
|
|
84
|
+
<%= check_box_tag "scopes[]", scope, default_scopes.include?(scope), id: field_id %>
|
|
85
|
+
<%= config.label_for_scope(scope) %>
|
|
86
|
+
</label>
|
|
87
|
+
</li>
|
|
88
|
+
<% end %>
|
|
89
|
+
</fieldset>
|
|
90
|
+
<% end %>
|
|
91
|
+
<% if config.absolute_expiry_enabled? && absolute_ttl_choices.any? %>
|
|
92
|
+
<fieldset class="inputs">
|
|
93
|
+
<div class="input select">
|
|
94
|
+
<label class="label" for="absolute_ttl_seconds"><%= t("active_admin.device_authorization.absolute_ttl") %></label>
|
|
95
|
+
<%= select_tag :absolute_ttl_seconds,
|
|
96
|
+
options_for_select(
|
|
97
|
+
absolute_ttl_choices.map { |seconds| ["#{seconds.to_i / 3600} h", seconds.to_i] },
|
|
98
|
+
config.access_token_default_absolute_ttl.to_i
|
|
99
|
+
),
|
|
100
|
+
id: "absolute_ttl_seconds" %>
|
|
101
|
+
</div>
|
|
102
|
+
</fieldset>
|
|
103
|
+
<% end %>
|
|
104
|
+
<fieldset class="actions">
|
|
105
|
+
<ol>
|
|
106
|
+
<li class="action input_action">
|
|
107
|
+
<%= submit_tag t("active_admin.device_authorization.approve") %>
|
|
76
108
|
</li>
|
|
77
|
-
|
|
109
|
+
</ol>
|
|
78
110
|
</fieldset>
|
|
79
111
|
<% end %>
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
id: "absolute_ttl_seconds" %>
|
|
90
|
-
</div>
|
|
112
|
+
|
|
113
|
+
<%= form_with url: url_for(action: :deny), method: :post, data: {turbo: false}, class: "formtastic" do %>
|
|
114
|
+
<%= hidden_field_tag :user_code, grant.user_code %>
|
|
115
|
+
<fieldset class="actions">
|
|
116
|
+
<ol>
|
|
117
|
+
<li class="action input_action">
|
|
118
|
+
<%= submit_tag t("active_admin.device_authorization.deny") %>
|
|
119
|
+
</li>
|
|
120
|
+
</ol>
|
|
91
121
|
</fieldset>
|
|
92
122
|
<% end %>
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
<fieldset class="actions device-auth-actions">
|
|
96
|
-
<ol>
|
|
97
|
-
<li class="action input_action">
|
|
98
|
-
<%= submit_tag t("active_admin.device_authorization.approve"), form: "device-auth-approve" %>
|
|
99
|
-
</li>
|
|
100
|
-
<li class="action input_action">
|
|
101
|
-
<%= form_with url: send(:"#{config.path_namespace}_deny_device_auth_path", grant.user_code), method: :post, data: {turbo: false} do %>
|
|
102
|
-
<%= submit_tag t("active_admin.device_authorization.deny") %>
|
|
103
|
-
<% end %>
|
|
104
|
-
</li>
|
|
105
|
-
</ol>
|
|
106
|
-
</fieldset>
|
|
123
|
+
</div>
|
|
107
124
|
<% else %>
|
|
108
125
|
<p><%= t("active_admin.device_authorization.not_actionable", status: grant.status) %></p>
|
|
109
126
|
<% end %>
|
|
@@ -62,10 +62,11 @@ module ActiveAdmin
|
|
|
62
62
|
@client_class_name = "DeviceAuthorizationClient"
|
|
63
63
|
@grant_class_name = "DeviceAuthorizationGrant"
|
|
64
64
|
@access_token_class_name = "DeviceAuthorizationAccessToken"
|
|
65
|
-
|
|
65
|
+
# Zero-arity: resolved with instance_exec so private auth helpers work
|
|
66
|
+
# without an explicit receiver (current_admin_user / current_user).
|
|
67
|
+
@current_resource_owner = -> { current_admin_user }
|
|
66
68
|
|
|
67
|
-
# RFC 8628 example uses 1800s;
|
|
68
|
-
# Ten minutes is a practical admin-consent window.
|
|
69
|
+
# RFC 8628 example uses 1800s; ten minutes is a practical admin-consent window.
|
|
69
70
|
@challenge_expires_in = 10 * 60
|
|
70
71
|
@poll_interval = 5
|
|
71
72
|
@slow_down_increment = 5
|
|
@@ -146,6 +147,22 @@ module ActiveAdmin
|
|
|
146
147
|
key
|
|
147
148
|
end
|
|
148
149
|
|
|
150
|
+
# Resolves the signed-in resource owner for consent actions.
|
|
151
|
+
# Zero-arity callables run via instance_exec on the controller so private
|
|
152
|
+
# auth helpers (current_admin_user, current_user) are reachable.
|
|
153
|
+
# Arity-1 callables still receive the controller; use send(:current_user)
|
|
154
|
+
# when calling with an explicit receiver.
|
|
155
|
+
def resolve_current_resource_owner(controller)
|
|
156
|
+
callable = current_resource_owner
|
|
157
|
+
return nil if callable.nil?
|
|
158
|
+
|
|
159
|
+
if callable.is_a?(Proc) && callable.arity == 0
|
|
160
|
+
controller.instance_exec(&callable)
|
|
161
|
+
else
|
|
162
|
+
callable.call(controller)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
149
166
|
def normalize_scopes(requested)
|
|
150
167
|
allowed = Array(scopes).map(&:to_s)
|
|
151
168
|
Array(requested).flatten.compact.map(&:to_s).map(&:strip).uniq.select { |scope| allowed.include?(scope) }
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "cgi"
|
|
4
|
+
|
|
3
5
|
module ActiveAdmin
|
|
4
6
|
module DeviceAuthorization
|
|
5
7
|
class DeviceAuthorizationRequest
|
|
@@ -48,7 +50,7 @@ module ActiveAdmin
|
|
|
48
50
|
device_code: device_code,
|
|
49
51
|
user_code: user_code,
|
|
50
52
|
verification_uri: verification_uri,
|
|
51
|
-
verification_uri_complete: "#{verification_uri}
|
|
53
|
+
verification_uri_complete: "#{verification_uri}?user_code=#{CGI.escape(user_code)}",
|
|
52
54
|
expires_in: @config.challenge_expires_in.to_i,
|
|
53
55
|
interval: @config.poll_interval.to_i
|
|
54
56
|
)
|
|
@@ -12,6 +12,24 @@ module ActiveAdmin
|
|
|
12
12
|
initializer "active_admin.device_authorization.filter_parameters" do |app|
|
|
13
13
|
app.config.filter_parameters |= [:device_code, :user_code, :access_token]
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
# Register the consent page after ActiveAdmin loads admin files (RFC-0002).
|
|
17
|
+
# Auto-register only when register_active_admin_page is true; hosts may still
|
|
18
|
+
# call Page.register! manually when that flag is false.
|
|
19
|
+
initializer "active_admin.device_authorization.page", after: :load_config_initializers do
|
|
20
|
+
ActiveAdmin.after_load do
|
|
21
|
+
if ActiveAdmin::DeviceAuthorization.config.register_active_admin_page
|
|
22
|
+
ActiveAdmin::DeviceAuthorization::Page.register!
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if defined?(ActiveAdmin) &&
|
|
27
|
+
ActiveAdmin.application.respond_to?(:loaded?) &&
|
|
28
|
+
ActiveAdmin.application.loaded? &&
|
|
29
|
+
ActiveAdmin::DeviceAuthorization.config.register_active_admin_page
|
|
30
|
+
ActiveAdmin::DeviceAuthorization::Page.register!
|
|
31
|
+
end
|
|
32
|
+
end
|
|
15
33
|
end
|
|
16
34
|
end
|
|
17
35
|
end
|
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
module ActiveAdmin
|
|
4
4
|
module DeviceAuthorization
|
|
5
|
-
# Registers the ActiveAdmin consent page.
|
|
6
|
-
#
|
|
7
|
-
#
|
|
5
|
+
# Registers the ActiveAdmin consent page (RFC-0002). Always registers when
|
|
6
|
+
# called. The engine auto-calls this from `ActiveAdmin.after_load` only when
|
|
7
|
+
# `register_active_admin_page` is true; hosts may call `register!` themselves
|
|
8
|
+
# when that flag is false.
|
|
9
|
+
#
|
|
10
|
+
# Consent auth and authorization stay on ActiveAdmin::BaseController via
|
|
11
|
+
# `ActiveAdmin.routes`. Approve and deny are page_actions; index renders
|
|
12
|
+
# consent when `user_code` is present.
|
|
8
13
|
module Page
|
|
9
14
|
module_function
|
|
10
15
|
|
|
11
16
|
def register!
|
|
12
17
|
config = ActiveAdmin::DeviceAuthorization.config
|
|
13
|
-
return unless config.register_active_admin_page
|
|
14
|
-
|
|
15
18
|
menu_label = config.menu_label || -> { I18n.t("active_admin.device_authorization.menu") }
|
|
16
|
-
verification = config.verification_path
|
|
17
19
|
|
|
18
20
|
ActiveAdmin.register_page "Device Auth" do
|
|
19
21
|
menu parent: config.menu_parent,
|
|
@@ -26,77 +28,73 @@ module ActiveAdmin
|
|
|
26
28
|
define_method(:index) do
|
|
27
29
|
user_code = ActiveAdmin::DeviceAuthorization::UserCode.normalize(params[:user_code])
|
|
28
30
|
if user_code.present?
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
load_grant!
|
|
32
|
+
@grant.mark_expired_if_needed!
|
|
33
|
+
@page_title = I18n.t("active_admin.device_authorization.title")
|
|
34
|
+
else
|
|
35
|
+
@page_title = I18n.t("active_admin.device_authorization.enter_code")
|
|
31
36
|
end
|
|
32
|
-
|
|
33
|
-
@page_title = I18n.t("active_admin.device_authorization.enter_code")
|
|
34
37
|
super()
|
|
35
38
|
end
|
|
36
39
|
|
|
37
|
-
define_method(:
|
|
38
|
-
load_grant!
|
|
39
|
-
@grant.mark_expired_if_needed!
|
|
40
|
-
@page_title = I18n.t("active_admin.device_authorization.title")
|
|
41
|
-
render "active_admin/page/index"
|
|
42
|
-
end
|
|
40
|
+
define_method(:device_auth_grant) { @grant }
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
load_grant!
|
|
46
|
-
if config.before_approve && !config.before_approve.call(self)
|
|
47
|
-
return
|
|
48
|
-
end
|
|
42
|
+
private
|
|
49
43
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
absolute_ttl_seconds: params[:absolute_ttl_seconds]
|
|
55
|
-
).approve!
|
|
56
|
-
redirect_to send(:"#{config.path_namespace}_device_auth_grant_path", @grant.user_code),
|
|
57
|
-
notice: I18n.t("active_admin.device_authorization.approved")
|
|
58
|
-
rescue ActiveAdmin::DeviceAuthorization::Consent::Error => error
|
|
59
|
-
redirect_to send(:"#{config.path_namespace}_device_auth_grant_path", @grant.user_code),
|
|
60
|
-
alert: I18n.t(
|
|
61
|
-
"active_admin.device_authorization.error.#{error.message}",
|
|
62
|
-
default: error.message
|
|
63
|
-
)
|
|
44
|
+
define_method(:load_grant!) do
|
|
45
|
+
user_code = ActiveAdmin::DeviceAuthorization::UserCode.normalize(params[:user_code])
|
|
46
|
+
@grant = ActiveAdmin::DeviceAuthorization.config.grant_class
|
|
47
|
+
.find_by!(user_code: user_code)
|
|
64
48
|
end
|
|
65
49
|
|
|
66
|
-
define_method(:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
scopes: @grant.requested_scopes,
|
|
72
|
-
absolute_ttl_seconds: config.access_token_default_absolute_ttl
|
|
73
|
-
).deny!
|
|
74
|
-
redirect_to send(:"#{config.path_namespace}_device_auth_grant_path", @grant.user_code),
|
|
75
|
-
notice: I18n.t("active_admin.device_authorization.denied")
|
|
76
|
-
rescue ActiveAdmin::DeviceAuthorization::Consent::Error => error
|
|
77
|
-
redirect_to send(:"#{config.path_namespace}_device_auth_grant_path", @grant.user_code),
|
|
78
|
-
alert: I18n.t(
|
|
79
|
-
"active_admin.device_authorization.error.#{error.message}",
|
|
80
|
-
default: error.message
|
|
81
|
-
)
|
|
50
|
+
define_method(:consent_redirect_path) do
|
|
51
|
+
send(
|
|
52
|
+
:"#{ActiveAdmin::DeviceAuthorization.config.path_namespace}_device_auth_path",
|
|
53
|
+
user_code: @grant.user_code
|
|
54
|
+
)
|
|
82
55
|
end
|
|
56
|
+
end
|
|
83
57
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
else
|
|
90
|
-
super()
|
|
91
|
-
end
|
|
58
|
+
page_action :approve, method: :post do
|
|
59
|
+
load_grant!
|
|
60
|
+
config = ActiveAdmin::DeviceAuthorization.config
|
|
61
|
+
if config.before_approve && !config.before_approve.call(self)
|
|
62
|
+
return
|
|
92
63
|
end
|
|
93
64
|
|
|
94
|
-
|
|
65
|
+
ActiveAdmin::DeviceAuthorization::Consent.new(
|
|
66
|
+
grant: @grant,
|
|
67
|
+
resource_owner: config.resolve_current_resource_owner(self),
|
|
68
|
+
scopes: Array(params[:scopes]),
|
|
69
|
+
absolute_ttl_seconds: params[:absolute_ttl_seconds]
|
|
70
|
+
).approve!
|
|
71
|
+
redirect_to consent_redirect_path,
|
|
72
|
+
notice: I18n.t("active_admin.device_authorization.approved")
|
|
73
|
+
rescue ActiveAdmin::DeviceAuthorization::Consent::Error => error
|
|
74
|
+
redirect_to consent_redirect_path,
|
|
75
|
+
alert: I18n.t(
|
|
76
|
+
"active_admin.device_authorization.error.#{error.message}",
|
|
77
|
+
default: error.message
|
|
78
|
+
)
|
|
79
|
+
end
|
|
95
80
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
page_action :deny, method: :post do
|
|
82
|
+
load_grant!
|
|
83
|
+
config = ActiveAdmin::DeviceAuthorization.config
|
|
84
|
+
ActiveAdmin::DeviceAuthorization::Consent.new(
|
|
85
|
+
grant: @grant,
|
|
86
|
+
resource_owner: config.resolve_current_resource_owner(self),
|
|
87
|
+
scopes: @grant.requested_scopes,
|
|
88
|
+
absolute_ttl_seconds: config.access_token_default_absolute_ttl
|
|
89
|
+
).deny!
|
|
90
|
+
redirect_to consent_redirect_path,
|
|
91
|
+
notice: I18n.t("active_admin.device_authorization.denied")
|
|
92
|
+
rescue ActiveAdmin::DeviceAuthorization::Consent::Error => error
|
|
93
|
+
redirect_to consent_redirect_path,
|
|
94
|
+
alert: I18n.t(
|
|
95
|
+
"active_admin.device_authorization.error.#{error.message}",
|
|
96
|
+
default: error.message
|
|
97
|
+
)
|
|
100
98
|
end
|
|
101
99
|
|
|
102
100
|
page_action :step_up, method: [:get, :post] do
|
|
@@ -108,7 +106,13 @@ module ActiveAdmin
|
|
|
108
106
|
end
|
|
109
107
|
end
|
|
110
108
|
|
|
111
|
-
content title: proc {
|
|
109
|
+
content title: proc {
|
|
110
|
+
if device_auth_grant
|
|
111
|
+
I18n.t("active_admin.device_authorization.title")
|
|
112
|
+
else
|
|
113
|
+
I18n.t("active_admin.device_authorization.enter_code")
|
|
114
|
+
end
|
|
115
|
+
} do
|
|
112
116
|
if device_auth_grant
|
|
113
117
|
render partial: "active_admin/device_authorization/consent",
|
|
114
118
|
locals: {grant: device_auth_grant}
|
|
@@ -117,9 +121,6 @@ module ActiveAdmin
|
|
|
117
121
|
end
|
|
118
122
|
end
|
|
119
123
|
end
|
|
120
|
-
|
|
121
|
-
# Host must also route show/approve/deny; Page only registers the AA index shell.
|
|
122
|
-
verification
|
|
123
124
|
end
|
|
124
125
|
end
|
|
125
126
|
end
|
|
@@ -3,56 +3,30 @@
|
|
|
3
3
|
module ActiveAdmin
|
|
4
4
|
module DeviceAuthorization
|
|
5
5
|
module Routes
|
|
6
|
-
#
|
|
6
|
+
# Draw public OAuth JSON endpoints only (RFC-0002).
|
|
7
7
|
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# end
|
|
8
|
+
# ActiveAdmin.routes(self)
|
|
9
|
+
# ActiveAdmin::DeviceAuthorization::Routes.draw(self)
|
|
11
10
|
#
|
|
12
|
-
#
|
|
13
|
-
# under `namespace :admin`
|
|
11
|
+
# Call at the routes root. `draw` applies `config.path_namespace` itself;
|
|
12
|
+
# nesting under another `namespace :admin` double-prefixes the path.
|
|
13
|
+
# Consent UI is owned by the ActiveAdmin page (`Page.register!` /
|
|
14
|
+
# `ActiveAdmin.routes`); do not declare consent routes here.
|
|
14
15
|
#
|
|
15
|
-
#
|
|
16
|
-
# ActiveAdmin
|
|
17
|
-
#
|
|
18
|
-
def self.draw(mapper, config: ActiveAdmin::DeviceAuthorization.config
|
|
16
|
+
# OAuth controllers use absolute gem paths so the admin namespace does not
|
|
17
|
+
# invent `Admin::ActiveAdmin::...` constants. They do not use the admin
|
|
18
|
+
# session; rate-limit procs and protocol parameters gate access.
|
|
19
|
+
def self.draw(mapper, config: ActiveAdmin::DeviceAuthorization.config)
|
|
19
20
|
config.validate_rate_limits!
|
|
20
21
|
oauth = config.oauth_path_prefix.to_s
|
|
21
|
-
verification = config.verification_path.to_s
|
|
22
22
|
|
|
23
|
-
mapper.namespace
|
|
24
|
-
mapper.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
case consent
|
|
31
|
-
when :active_admin_page
|
|
32
|
-
mapper.get "#{verification}/:user_code",
|
|
33
|
-
to: "device_auth#show",
|
|
34
|
-
as: :device_auth_grant
|
|
35
|
-
mapper.post "#{verification}/:user_code/approve",
|
|
36
|
-
to: "device_auth#approve",
|
|
37
|
-
as: :approve_device_auth
|
|
38
|
-
mapper.post "#{verification}/:user_code/deny",
|
|
39
|
-
to: "device_auth#deny",
|
|
40
|
-
as: :deny_device_auth
|
|
41
|
-
when :controller
|
|
42
|
-
mapper.get verification,
|
|
43
|
-
to: "/active_admin/device_authorization/consents#index",
|
|
44
|
-
as: :device_auth
|
|
45
|
-
mapper.get "#{verification}/:user_code",
|
|
46
|
-
to: "/active_admin/device_authorization/consents#show",
|
|
47
|
-
as: :device_auth_grant
|
|
48
|
-
mapper.post "#{verification}/:user_code/approve",
|
|
49
|
-
to: "/active_admin/device_authorization/consents#approve",
|
|
50
|
-
as: :approve_device_auth
|
|
51
|
-
mapper.post "#{verification}/:user_code/deny",
|
|
52
|
-
to: "/active_admin/device_authorization/consents#deny",
|
|
53
|
-
as: :deny_device_auth
|
|
54
|
-
else
|
|
55
|
-
raise ArgumentError, "consent must be :active_admin_page or :controller (got #{consent.inspect})"
|
|
23
|
+
mapper.namespace config.path_namespace do
|
|
24
|
+
mapper.namespace :oauth, path: oauth do
|
|
25
|
+
mapper.post :device_authorization,
|
|
26
|
+
to: "/active_admin/device_authorization/device_authorizations#create"
|
|
27
|
+
mapper.post :token,
|
|
28
|
+
to: "/active_admin/device_authorization/tokens#create"
|
|
29
|
+
end
|
|
56
30
|
end
|
|
57
31
|
end
|
|
58
32
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activeadmin-device_authorization
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andrei Makarov
|
|
@@ -15,14 +15,20 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
18
|
+
version: 4.0.0.beta19
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '5'
|
|
19
22
|
type: :runtime
|
|
20
23
|
prerelease: false
|
|
21
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
25
|
requirements:
|
|
23
26
|
- - ">="
|
|
24
27
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
28
|
+
version: 4.0.0.beta19
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '5'
|
|
26
32
|
- !ruby/object:Gem::Dependency
|
|
27
33
|
name: rails
|
|
28
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -51,6 +57,20 @@ dependencies:
|
|
|
51
57
|
- - "~>"
|
|
52
58
|
- !ruby/object:Gem::Version
|
|
53
59
|
version: '2'
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: activeadmin-graphql
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - ">="
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: 0.4.1
|
|
67
|
+
type: :development
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 0.4.1
|
|
54
74
|
- !ruby/object:Gem::Dependency
|
|
55
75
|
name: bundler
|
|
56
76
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -79,20 +99,118 @@ dependencies:
|
|
|
79
99
|
- - "~>"
|
|
80
100
|
- !ruby/object:Gem::Version
|
|
81
101
|
version: '0.9'
|
|
102
|
+
- !ruby/object:Gem::Dependency
|
|
103
|
+
name: capybara
|
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
|
105
|
+
requirements:
|
|
106
|
+
- - "~>"
|
|
107
|
+
- !ruby/object:Gem::Version
|
|
108
|
+
version: '3.40'
|
|
109
|
+
type: :development
|
|
110
|
+
prerelease: false
|
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - "~>"
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '3.40'
|
|
116
|
+
- !ruby/object:Gem::Dependency
|
|
117
|
+
name: capybara-playwright-driver
|
|
118
|
+
requirement: !ruby/object:Gem::Requirement
|
|
119
|
+
requirements:
|
|
120
|
+
- - "~>"
|
|
121
|
+
- !ruby/object:Gem::Version
|
|
122
|
+
version: '0.5'
|
|
123
|
+
type: :development
|
|
124
|
+
prerelease: false
|
|
125
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - "~>"
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: '0.5'
|
|
130
|
+
- !ruby/object:Gem::Dependency
|
|
131
|
+
name: cssbundling-rails
|
|
132
|
+
requirement: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: '0'
|
|
137
|
+
type: :development
|
|
138
|
+
prerelease: false
|
|
139
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
140
|
+
requirements:
|
|
141
|
+
- - ">="
|
|
142
|
+
- !ruby/object:Gem::Version
|
|
143
|
+
version: '0'
|
|
144
|
+
- !ruby/object:Gem::Dependency
|
|
145
|
+
name: database_cleaner-active_record
|
|
146
|
+
requirement: !ruby/object:Gem::Requirement
|
|
147
|
+
requirements:
|
|
148
|
+
- - "~>"
|
|
149
|
+
- !ruby/object:Gem::Version
|
|
150
|
+
version: '2.2'
|
|
151
|
+
type: :development
|
|
152
|
+
prerelease: false
|
|
153
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
154
|
+
requirements:
|
|
155
|
+
- - "~>"
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: '2.2'
|
|
158
|
+
- !ruby/object:Gem::Dependency
|
|
159
|
+
name: devise
|
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
|
161
|
+
requirements:
|
|
162
|
+
- - ">="
|
|
163
|
+
- !ruby/object:Gem::Version
|
|
164
|
+
version: '4.9'
|
|
165
|
+
type: :development
|
|
166
|
+
prerelease: false
|
|
167
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
168
|
+
requirements:
|
|
169
|
+
- - ">="
|
|
170
|
+
- !ruby/object:Gem::Version
|
|
171
|
+
version: '4.9'
|
|
172
|
+
- !ruby/object:Gem::Dependency
|
|
173
|
+
name: importmap-rails
|
|
174
|
+
requirement: !ruby/object:Gem::Requirement
|
|
175
|
+
requirements:
|
|
176
|
+
- - ">="
|
|
177
|
+
- !ruby/object:Gem::Version
|
|
178
|
+
version: '0'
|
|
179
|
+
type: :development
|
|
180
|
+
prerelease: false
|
|
181
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
182
|
+
requirements:
|
|
183
|
+
- - ">="
|
|
184
|
+
- !ruby/object:Gem::Version
|
|
185
|
+
version: '0'
|
|
82
186
|
- !ruby/object:Gem::Dependency
|
|
83
187
|
name: polyrun
|
|
84
188
|
requirement: !ruby/object:Gem::Requirement
|
|
85
189
|
requirements:
|
|
86
190
|
- - ">="
|
|
87
191
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: 2.2.
|
|
192
|
+
version: 2.2.9
|
|
89
193
|
type: :development
|
|
90
194
|
prerelease: false
|
|
91
195
|
version_requirements: !ruby/object:Gem::Requirement
|
|
92
196
|
requirements:
|
|
93
197
|
- - ">="
|
|
94
198
|
- !ruby/object:Gem::Version
|
|
95
|
-
version: 2.2.
|
|
199
|
+
version: 2.2.9
|
|
200
|
+
- !ruby/object:Gem::Dependency
|
|
201
|
+
name: puma
|
|
202
|
+
requirement: !ruby/object:Gem::Requirement
|
|
203
|
+
requirements:
|
|
204
|
+
- - ">="
|
|
205
|
+
- !ruby/object:Gem::Version
|
|
206
|
+
version: '5.0'
|
|
207
|
+
type: :development
|
|
208
|
+
prerelease: false
|
|
209
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
210
|
+
requirements:
|
|
211
|
+
- - ">="
|
|
212
|
+
- !ruby/object:Gem::Version
|
|
213
|
+
version: '5.0'
|
|
96
214
|
- !ruby/object:Gem::Dependency
|
|
97
215
|
name: rake
|
|
98
216
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -135,6 +253,20 @@ dependencies:
|
|
|
135
253
|
- - "~>"
|
|
136
254
|
- !ruby/object:Gem::Version
|
|
137
255
|
version: '3'
|
|
256
|
+
- !ruby/object:Gem::Dependency
|
|
257
|
+
name: rspec-rails
|
|
258
|
+
requirement: !ruby/object:Gem::Requirement
|
|
259
|
+
requirements:
|
|
260
|
+
- - ">="
|
|
261
|
+
- !ruby/object:Gem::Version
|
|
262
|
+
version: '6'
|
|
263
|
+
type: :development
|
|
264
|
+
prerelease: false
|
|
265
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
266
|
+
requirements:
|
|
267
|
+
- - ">="
|
|
268
|
+
- !ruby/object:Gem::Version
|
|
269
|
+
version: '6'
|
|
138
270
|
- !ruby/object:Gem::Dependency
|
|
139
271
|
name: rubocop-rspec
|
|
140
272
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -163,6 +295,34 @@ dependencies:
|
|
|
163
295
|
- - "~>"
|
|
164
296
|
- !ruby/object:Gem::Version
|
|
165
297
|
version: '0.7'
|
|
298
|
+
- !ruby/object:Gem::Dependency
|
|
299
|
+
name: sprockets-rails
|
|
300
|
+
requirement: !ruby/object:Gem::Requirement
|
|
301
|
+
requirements:
|
|
302
|
+
- - ">="
|
|
303
|
+
- !ruby/object:Gem::Version
|
|
304
|
+
version: '0'
|
|
305
|
+
type: :development
|
|
306
|
+
prerelease: false
|
|
307
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
308
|
+
requirements:
|
|
309
|
+
- - ">="
|
|
310
|
+
- !ruby/object:Gem::Version
|
|
311
|
+
version: '0'
|
|
312
|
+
- !ruby/object:Gem::Dependency
|
|
313
|
+
name: sqlite3
|
|
314
|
+
requirement: !ruby/object:Gem::Requirement
|
|
315
|
+
requirements:
|
|
316
|
+
- - ">="
|
|
317
|
+
- !ruby/object:Gem::Version
|
|
318
|
+
version: '2.1'
|
|
319
|
+
type: :development
|
|
320
|
+
prerelease: false
|
|
321
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
322
|
+
requirements:
|
|
323
|
+
- - ">="
|
|
324
|
+
- !ruby/object:Gem::Version
|
|
325
|
+
version: '2.1'
|
|
166
326
|
- !ruby/object:Gem::Dependency
|
|
167
327
|
name: standard
|
|
168
328
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -236,15 +396,11 @@ files:
|
|
|
236
396
|
- SECURITY.md
|
|
237
397
|
- activeadmin-device_authorization.gemspec
|
|
238
398
|
- app/controllers/active_admin/device_authorization/application_controller.rb
|
|
239
|
-
- app/controllers/active_admin/device_authorization/consents_controller.rb
|
|
240
399
|
- app/controllers/active_admin/device_authorization/device_authorizations_controller.rb
|
|
241
400
|
- app/controllers/active_admin/device_authorization/json_response.rb
|
|
242
401
|
- app/controllers/active_admin/device_authorization/tokens_controller.rb
|
|
243
402
|
- app/views/active_admin/device_authorization/_consent.html.erb
|
|
244
403
|
- app/views/active_admin/device_authorization/_enter_code.html.erb
|
|
245
|
-
- app/views/active_admin/device_authorization/_standalone_styles.html.erb
|
|
246
|
-
- app/views/active_admin/device_authorization/consents/index.html.erb
|
|
247
|
-
- app/views/active_admin/device_authorization/consents/show.html.erb
|
|
248
404
|
- config/locales/en.yml
|
|
249
405
|
- config/locales/fi.yml
|
|
250
406
|
- config/locales/sv.yml
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module ActiveAdmin
|
|
4
|
-
module DeviceAuthorization
|
|
5
|
-
# Thin HTML consent actions when the host does not use the ActiveAdmin page.
|
|
6
|
-
# Prefer ActiveAdmin::DeviceAuthorization::Page.register! for the AA layout.
|
|
7
|
-
class ConsentsController < ApplicationController
|
|
8
|
-
before_action :authenticate_resource_owner!
|
|
9
|
-
before_action :load_grant!, except: :index
|
|
10
|
-
|
|
11
|
-
def index
|
|
12
|
-
user_code = UserCode.normalize(params[:user_code])
|
|
13
|
-
if user_code.present?
|
|
14
|
-
redirect_to send(
|
|
15
|
-
:"#{ActiveAdmin::DeviceAuthorization.config.path_namespace}_device_auth_grant_path",
|
|
16
|
-
user_code
|
|
17
|
-
)
|
|
18
|
-
return
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
render layout: false
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def show
|
|
25
|
-
@grant.mark_expired_if_needed!
|
|
26
|
-
render layout: false
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def approve
|
|
30
|
-
config = ActiveAdmin::DeviceAuthorization.config
|
|
31
|
-
if config.before_approve && !config.before_approve.call(self)
|
|
32
|
-
return
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
Consent.new(
|
|
36
|
-
grant: @grant,
|
|
37
|
-
resource_owner: current_resource_owner,
|
|
38
|
-
scopes: Array(params[:scopes]),
|
|
39
|
-
absolute_ttl_seconds: params[:absolute_ttl_seconds]
|
|
40
|
-
).approve!
|
|
41
|
-
redirect_to after_consent_path, notice: I18n.t("active_admin.device_authorization.approved")
|
|
42
|
-
rescue Consent::Error => error
|
|
43
|
-
redirect_to after_consent_path,
|
|
44
|
-
alert: I18n.t("active_admin.device_authorization.error.#{error.message}", default: error.message)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def deny
|
|
48
|
-
Consent.new(
|
|
49
|
-
grant: @grant,
|
|
50
|
-
resource_owner: current_resource_owner,
|
|
51
|
-
scopes: @grant.requested_scopes,
|
|
52
|
-
absolute_ttl_seconds: ActiveAdmin::DeviceAuthorization.config.access_token_default_absolute_ttl
|
|
53
|
-
).deny!
|
|
54
|
-
redirect_to after_consent_path, notice: I18n.t("active_admin.device_authorization.denied")
|
|
55
|
-
rescue Consent::Error => error
|
|
56
|
-
redirect_to after_consent_path,
|
|
57
|
-
alert: I18n.t("active_admin.device_authorization.error.#{error.message}", default: error.message)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
private
|
|
61
|
-
|
|
62
|
-
def authenticate_resource_owner!
|
|
63
|
-
return if current_resource_owner
|
|
64
|
-
|
|
65
|
-
head :unauthorized
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def current_resource_owner
|
|
69
|
-
@current_resource_owner ||= ActiveAdmin::DeviceAuthorization.config.current_resource_owner.call(self)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def load_grant!
|
|
73
|
-
@grant = ActiveAdmin::DeviceAuthorization.config.grant_class
|
|
74
|
-
.find_by!(user_code: UserCode.normalize(params[:user_code]))
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def after_consent_path
|
|
78
|
-
config = ActiveAdmin::DeviceAuthorization.config
|
|
79
|
-
"/#{config.path_namespace}/#{config.verification_path}/#{@grant.user_code}"
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
<style>
|
|
2
|
-
.device-auth-standalone {
|
|
3
|
-
box-sizing: border-box;
|
|
4
|
-
color: #1a1a1a;
|
|
5
|
-
font-family: Georgia, "Times New Roman", serif;
|
|
6
|
-
line-height: 1.5;
|
|
7
|
-
margin: 0 auto;
|
|
8
|
-
max-width: 40rem;
|
|
9
|
-
padding: 1.5rem 1rem 3rem;
|
|
10
|
-
}
|
|
11
|
-
.device-auth-standalone *,
|
|
12
|
-
.device-auth-standalone *::before,
|
|
13
|
-
.device-auth-standalone *::after {
|
|
14
|
-
box-sizing: border-box;
|
|
15
|
-
}
|
|
16
|
-
.device-auth-standalone h1,
|
|
17
|
-
.device-auth-standalone .panel-title {
|
|
18
|
-
color: #111;
|
|
19
|
-
font-family: Georgia, "Times New Roman", serif;
|
|
20
|
-
font-size: 1.75rem;
|
|
21
|
-
font-weight: 700;
|
|
22
|
-
line-height: 1.25;
|
|
23
|
-
margin: 0 0 1rem;
|
|
24
|
-
}
|
|
25
|
-
.device-auth-standalone .panel {
|
|
26
|
-
background: #fff;
|
|
27
|
-
border: 1px solid #c8c8c8;
|
|
28
|
-
margin: 0 0 1.25rem;
|
|
29
|
-
padding: 1rem 1.1rem;
|
|
30
|
-
}
|
|
31
|
-
.device-auth-standalone .panel-body > *:first-child {
|
|
32
|
-
margin-top: 0;
|
|
33
|
-
}
|
|
34
|
-
.device-auth-standalone .panel-body > *:last-child {
|
|
35
|
-
margin-bottom: 0;
|
|
36
|
-
}
|
|
37
|
-
.device-auth-standalone .attributes_table {
|
|
38
|
-
border-collapse: collapse;
|
|
39
|
-
margin: 0 0 1rem;
|
|
40
|
-
width: 100%;
|
|
41
|
-
}
|
|
42
|
-
.device-auth-standalone .attributes_table th,
|
|
43
|
-
.device-auth-standalone .attributes_table td {
|
|
44
|
-
border-bottom: 1px solid #ddd;
|
|
45
|
-
padding: 0.55rem 0.35rem;
|
|
46
|
-
text-align: left;
|
|
47
|
-
vertical-align: top;
|
|
48
|
-
}
|
|
49
|
-
.device-auth-standalone .attributes_table th {
|
|
50
|
-
color: #444;
|
|
51
|
-
font-weight: 600;
|
|
52
|
-
width: 8.5rem;
|
|
53
|
-
}
|
|
54
|
-
.device-auth-standalone .device-auth-user-code {
|
|
55
|
-
font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
|
|
56
|
-
font-size: 1.15rem;
|
|
57
|
-
letter-spacing: 0.08em;
|
|
58
|
-
}
|
|
59
|
-
.device-auth-standalone .flash {
|
|
60
|
-
border: 1px solid #8a2f1d;
|
|
61
|
-
border-radius: 2px;
|
|
62
|
-
margin: 0 0 1rem;
|
|
63
|
-
padding: 0.75rem 0.9rem;
|
|
64
|
-
}
|
|
65
|
-
.device-auth-standalone .flash_alert {
|
|
66
|
-
background: #f8e8e4;
|
|
67
|
-
color: #5c1f14;
|
|
68
|
-
}
|
|
69
|
-
.device-auth-standalone .inline-hints {
|
|
70
|
-
color: #555;
|
|
71
|
-
margin: 0 0 1rem;
|
|
72
|
-
}
|
|
73
|
-
.device-auth-standalone fieldset {
|
|
74
|
-
border: 0;
|
|
75
|
-
margin: 0 0 1rem;
|
|
76
|
-
min-width: 0;
|
|
77
|
-
padding: 0;
|
|
78
|
-
}
|
|
79
|
-
.device-auth-standalone legend,
|
|
80
|
-
.device-auth-standalone .label {
|
|
81
|
-
color: #222;
|
|
82
|
-
display: block;
|
|
83
|
-
font-weight: 600;
|
|
84
|
-
margin: 0 0 0.4rem;
|
|
85
|
-
}
|
|
86
|
-
.device-auth-standalone .choice {
|
|
87
|
-
list-style: none;
|
|
88
|
-
margin: 0 0 0.45rem;
|
|
89
|
-
}
|
|
90
|
-
.device-auth-standalone .choice label {
|
|
91
|
-
display: inline-flex;
|
|
92
|
-
gap: 0.45rem;
|
|
93
|
-
align-items: flex-start;
|
|
94
|
-
}
|
|
95
|
-
.device-auth-standalone input[type="text"],
|
|
96
|
-
.device-auth-standalone select {
|
|
97
|
-
border: 1px solid #888;
|
|
98
|
-
border-radius: 2px;
|
|
99
|
-
display: block;
|
|
100
|
-
font: inherit;
|
|
101
|
-
max-width: 100%;
|
|
102
|
-
padding: 0.5rem 0.6rem;
|
|
103
|
-
width: 100%;
|
|
104
|
-
}
|
|
105
|
-
.device-auth-standalone input[type="text"]:focus,
|
|
106
|
-
.device-auth-standalone select:focus,
|
|
107
|
-
.device-auth-standalone input[type="checkbox"]:focus,
|
|
108
|
-
.device-auth-standalone input[type="submit"]:focus {
|
|
109
|
-
outline: 3px solid #1d4f91;
|
|
110
|
-
outline-offset: 2px;
|
|
111
|
-
}
|
|
112
|
-
.device-auth-standalone .device-auth-actions ol {
|
|
113
|
-
display: flex;
|
|
114
|
-
flex-direction: column;
|
|
115
|
-
gap: 0.65rem;
|
|
116
|
-
list-style: none;
|
|
117
|
-
margin: 0;
|
|
118
|
-
padding: 0;
|
|
119
|
-
}
|
|
120
|
-
.device-auth-standalone .device-auth-actions input[type="submit"],
|
|
121
|
-
.device-auth-standalone fieldset.actions input[type="submit"] {
|
|
122
|
-
background: #1d4f91;
|
|
123
|
-
border: 1px solid #163d70;
|
|
124
|
-
border-radius: 2px;
|
|
125
|
-
color: #fff;
|
|
126
|
-
cursor: pointer;
|
|
127
|
-
font: inherit;
|
|
128
|
-
min-height: 2.5rem;
|
|
129
|
-
padding: 0.45rem 1rem;
|
|
130
|
-
width: 100%;
|
|
131
|
-
}
|
|
132
|
-
.device-auth-standalone .device-auth-actions li:last-child input[type="submit"] {
|
|
133
|
-
background: #fff;
|
|
134
|
-
border-color: #888;
|
|
135
|
-
color: #222;
|
|
136
|
-
}
|
|
137
|
-
@media (min-width: 40rem) {
|
|
138
|
-
.device-auth-standalone .device-auth-actions ol {
|
|
139
|
-
flex-direction: row;
|
|
140
|
-
flex-wrap: wrap;
|
|
141
|
-
}
|
|
142
|
-
.device-auth-standalone .device-auth-actions input[type="submit"],
|
|
143
|
-
.device-auth-standalone fieldset.actions input[type="submit"] {
|
|
144
|
-
width: auto;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
</style>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="<%= I18n.locale %>">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title><%= t("active_admin.device_authorization.enter_code") %></title>
|
|
7
|
-
<%= render partial: "active_admin/device_authorization/standalone_styles" %>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<main class="device-auth-standalone">
|
|
11
|
-
<h1><%= t("active_admin.device_authorization.enter_code") %></h1>
|
|
12
|
-
<div class="panel">
|
|
13
|
-
<div class="panel-body">
|
|
14
|
-
<%= render partial: "active_admin/device_authorization/enter_code" %>
|
|
15
|
-
</div>
|
|
16
|
-
</div>
|
|
17
|
-
</main>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="<%= I18n.locale %>">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
-
<title><%= t("active_admin.device_authorization.title") %></title>
|
|
7
|
-
<%= render partial: "active_admin/device_authorization/standalone_styles" %>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<main class="device-auth-standalone">
|
|
11
|
-
<%= render partial: "active_admin/device_authorization/consent", locals: {grant: @grant, heading_level: :h1} %>
|
|
12
|
-
</main>
|
|
13
|
-
</body>
|
|
14
|
-
</html>
|