agentadmit 1.14.1 → 1.15.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/README.md +78 -2
- data/lib/agentadmit/introspection_client.rb +16 -3
- data/lib/agentadmit/tokens_client.rb +92 -3
- data/lib/agentadmit/version.rb +1 -1
- data/lib/agentadmit.rb +28 -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: cdf3d1325ca8755fd153ab45703eb9673fda20df40991b7fb6521ddd16c00117
|
|
4
|
+
data.tar.gz: cd700cced83a8b2abd12238fa3ea6370fb43b5e69a8dddad56b36343716bd5ac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95e4535b2b9591a5ecf9c9b34b723e851e589769b2d117e73ae890e720466a831521c4cd40ee0ebea6cfa7e65c2bf204fef2ad84a3e9103468728e7caadb4ad9
|
|
7
|
+
data.tar.gz: 5749c1faaceaebeab189c8d804f69978988c4ad5236654dd66130bff8d7aa87e6ec11d62659c858701aea2a718e392f525d1f89afc51c925944bf248e087256a
|
data/README.md
CHANGED
|
@@ -167,8 +167,7 @@ The SDK always forwards that header. A configured summary also causes the
|
|
|
167
167
|
middleware to send a `sha256:` digest of the raw Rack body and the summary,
|
|
168
168
|
then rewinds `rack.input` for the application. The hosted signature commits to
|
|
169
169
|
the scope, method, endpoint, digest, and the words shown to the human.
|
|
170
|
-
AgentAdmit
|
|
171
|
-
request.
|
|
170
|
+
AgentAdmit does not verify the summary against the request.
|
|
172
171
|
|
|
173
172
|
Custom gates receive a typed `AgentAdmit::ConfirmationRequiredError` carrying
|
|
174
173
|
the strictly parsed ceremony. Malformed ceremony blocks remain generic
|
|
@@ -190,6 +189,83 @@ user can lift a decline, and after the hold ends a retry stages a fresh
|
|
|
190
189
|
confirmation. A malformed `declined` block degrades to a generic 403 with no
|
|
191
190
|
block.
|
|
192
191
|
|
|
192
|
+
### Confirm each time: when the user has no passkey yet
|
|
193
|
+
|
|
194
|
+
A confirmation needs a passkey the user already has for your app. A user who
|
|
195
|
+
granted before you marked the scope `confirm_each_time`, or whose passkeys you
|
|
196
|
+
removed, has none, and the link the agent holds cannot be used alone. The
|
|
197
|
+
hosted service says so on the refusal: `confirmation["enrollment_required"]`
|
|
198
|
+
is `true`, and the SDK tells the agent to ask the user to open the request from
|
|
199
|
+
inside your app. `false` means a passkey is on file. The key is left out when
|
|
200
|
+
the hosted service did not state it; any value other than `true` or `false` is
|
|
201
|
+
treated the same way.
|
|
202
|
+
|
|
203
|
+
The 403 body the middleware sends in that case (custom gates get the same
|
|
204
|
+
hash from `ConfirmationRequiredError#denial_body`):
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"error": "confirmation_required",
|
|
209
|
+
"error_description": "This action requires a fresh human confirmation, and this user has no passkey on file for the app yet, so the confirmation link alone cannot be used. Ask the user to open the request from inside the app. After they confirm, retry with the X-AgentAdmit-Action-Attestation header.",
|
|
210
|
+
"confirmation": {
|
|
211
|
+
"action_session_id": "asess_...",
|
|
212
|
+
"action_session_url": "https://agentadmit.com/confirm/action/asess_...",
|
|
213
|
+
"enrollment_required": true,
|
|
214
|
+
"expires_at": "2026-11-20T18:30:00.000Z",
|
|
215
|
+
"scope": "write:payments",
|
|
216
|
+
"method": "POST",
|
|
217
|
+
"endpoint": "/api/payments",
|
|
218
|
+
"request_digest": "sha256:...",
|
|
219
|
+
"summary": "Pay Alex $50"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Your app then opens the confirmation for its own signed-in user with
|
|
225
|
+
`TokensClient#create_owner_link(action_session_id:, app_user_id:)` and sends
|
|
226
|
+
that user to
|
|
227
|
+
`owner_session_url`. On that page the user creates a passkey and confirms the
|
|
228
|
+
action; on a computer the page can show a QR code to continue on the user's
|
|
229
|
+
phone. When a passkey is already on file the result has
|
|
230
|
+
`"enrollment_required" => false` and the URL is the ordinary confirmation page.
|
|
231
|
+
|
|
232
|
+
```ruby
|
|
233
|
+
# A controller your signed-in user uses (your own session auth), not an agent route.
|
|
234
|
+
class PendingConfirmationsController < ApplicationController
|
|
235
|
+
before_action :authenticate_user!
|
|
236
|
+
|
|
237
|
+
def open
|
|
238
|
+
link = AgentAdmit::TokensClient.new.create_owner_link(
|
|
239
|
+
action_session_id: params[:id],
|
|
240
|
+
app_user_id: current_user.id.to_s
|
|
241
|
+
)
|
|
242
|
+
redirect_to link["owner_session_url"], allow_other_host: true, status: :see_other
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Two rules:
|
|
248
|
+
|
|
249
|
+
- Call `create_owner_link` only from a route your signed-in human uses, and pass
|
|
250
|
+
that user's id. The hosted service answers `404 not_found` when the
|
|
251
|
+
confirmation belongs to another user, another app, or the other environment.
|
|
252
|
+
- Do not return `owner_session_url` to an agent, and do not log it. Whoever opens
|
|
253
|
+
it can create the passkey that confirms the action.
|
|
254
|
+
|
|
255
|
+
The SDK does not add this to its middleware. A bad argument raises
|
|
256
|
+
`ArgumentError` before any request. Hosted errors raise `AgentAdmit::ApiError`
|
|
257
|
+
(an `IntrospectionError`) with `#status` and the hosted `#code`
|
|
258
|
+
(`invalid_api_key`, `api_key_not_app_linked`, `not_found`, `already_consumed`,
|
|
259
|
+
`already_verified`, `session_expired`); the call does not retry on a 4xx. Calling it again is safe: a new link replaces the previous
|
|
260
|
+
one.
|
|
261
|
+
|
|
262
|
+
Webhook: when your app removes a user's passkeys through the API, AgentAdmit
|
|
263
|
+
sends a signed `agentadmit.passkey_removed` event to your webhook URL, and
|
|
264
|
+
`AgentAdmit::Webhook.verify_signature` verifies it the same way as every other
|
|
265
|
+
delivery. The event carries `removal_id` and, under `data`, `app_user_id`, `credential_ids`,
|
|
266
|
+
`removed`, `remaining`, `wait_sec`, `removed_at`, `reenrollment_not_before` and
|
|
267
|
+
`removed_by`.
|
|
268
|
+
|
|
193
269
|
## Rate Limiting
|
|
194
270
|
|
|
195
271
|
The AgentAdmit introspection endpoint enforces rate limits. The Ruby SDK handles HTTP 429 responses **automatically** with exponential backoff and jitter -- no changes needed in your middleware code.
|
|
@@ -147,7 +147,9 @@ module AgentAdmit
|
|
|
147
147
|
# A strictly-typed copy of the wire `confirmation` block, or nil when
|
|
148
148
|
# it is malformed. ids/urls/expiry/scope must be Strings; method,
|
|
149
149
|
# endpoint, request_digest and summary are nullable Strings (anything
|
|
150
|
-
# else reads as nil).
|
|
150
|
+
# else reads as nil). "enrollment_required" (1.15.0) is present only
|
|
151
|
+
# when the wire value is true or false. Nothing outside the contract
|
|
152
|
+
# is copied through.
|
|
151
153
|
#
|
|
152
154
|
# @param raw [Object] the `confirmation` value from the hosted response
|
|
153
155
|
# @return [Hash, nil]
|
|
@@ -158,14 +160,21 @@ module AgentAdmit
|
|
|
158
160
|
.all? { |key| raw[key].is_a?(String) }
|
|
159
161
|
|
|
160
162
|
nullable = ->(value) { value.is_a?(String) ? value : nil }
|
|
161
|
-
|
|
163
|
+
confirmation = {
|
|
164
|
+
"action_session_id" => raw["action_session_id"],
|
|
162
165
|
"action_session_url" => raw["action_session_url"],
|
|
163
166
|
"expires_at" => raw["expires_at"],
|
|
164
167
|
"scope" => raw["scope"],
|
|
165
168
|
"method" => nullable.call(raw["method"]),
|
|
166
169
|
"endpoint" => nullable.call(raw["endpoint"]),
|
|
167
170
|
"request_digest" => nullable.call(raw["request_digest"]),
|
|
168
|
-
"summary" => nullable.call(raw["summary"])
|
|
171
|
+
"summary" => nullable.call(raw["summary"])
|
|
172
|
+
}
|
|
173
|
+
# SDK 1.15.0: kept only when the wire value is true or false; any
|
|
174
|
+
# other value reads as if the key were missing (never coerced).
|
|
175
|
+
enrollment = raw["enrollment_required"]
|
|
176
|
+
confirmation["enrollment_required"] = enrollment if enrollment == true || enrollment == false
|
|
177
|
+
confirmation
|
|
169
178
|
end
|
|
170
179
|
|
|
171
180
|
##
|
|
@@ -697,6 +706,10 @@ module AgentAdmit
|
|
|
697
706
|
description = data["error_description"]
|
|
698
707
|
description = ConfirmationRequiredError::DESCRIPTION unless
|
|
699
708
|
description.is_a?(String) && !description.empty?
|
|
709
|
+
# SDK 1.15.0: the user has no passkey yet, so the link alone cannot
|
|
710
|
+
# be used; the agent is told to send the user into the app.
|
|
711
|
+
description = ConfirmationRequiredError::ENROLLMENT_REQUIRED_DESCRIPTION if
|
|
712
|
+
confirmation["enrollment_required"] == true
|
|
700
713
|
status = data["attestation_status"]
|
|
701
714
|
raise ConfirmationRequiredError.new(
|
|
702
715
|
description,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "net/http"
|
|
4
4
|
require "json"
|
|
5
5
|
require "uri"
|
|
6
|
+
require "erb"
|
|
6
7
|
|
|
7
8
|
module AgentAdmit
|
|
8
9
|
##
|
|
@@ -147,14 +148,99 @@ module AgentAdmit
|
|
|
147
148
|
post("/api/v1/revoke", body, authenticated: true, op: "revoke")
|
|
148
149
|
end
|
|
149
150
|
|
|
151
|
+
# Shortest action_session_id the hosted service accepts (asess_ + id).
|
|
152
|
+
ACTION_SESSION_ID_MIN_LENGTH = 20
|
|
153
|
+
# Longest app_user_id the hosted service accepts.
|
|
154
|
+
APP_USER_ID_MAX_LENGTH = 255
|
|
155
|
+
|
|
156
|
+
##
|
|
157
|
+
# Open a pending confirmation for your own signed-in user (SDK 1.15.0).
|
|
158
|
+
# Calls POST /api/v1/action-sessions/{action_session_id}/owner-link with
|
|
159
|
+
# the app's API key and { "app_user_id" => ... }.
|
|
160
|
+
#
|
|
161
|
+
# When a scope needs a fresh human confirmation and the user has no
|
|
162
|
+
# passkey on file for the app yet (confirmation["enrollment_required"]
|
|
163
|
+
# is true), the link the agent holds cannot be used alone. Send the
|
|
164
|
+
# signed-in user to the returned "owner_session_url": on that page they
|
|
165
|
+
# create a passkey and confirm the action; on a computer the page can
|
|
166
|
+
# show a QR code to continue on the user's phone.
|
|
167
|
+
#
|
|
168
|
+
# Two rules: call this only from a route your signed-in human uses,
|
|
169
|
+
# passing that user's id; never return "owner_session_url" to an agent
|
|
170
|
+
# (whoever opens it can create the passkey that confirms the action), and
|
|
171
|
+
# never log it. The SDK does not mount this on any middleware or route.
|
|
172
|
+
#
|
|
173
|
+
# @param action_session_id [String] confirmation["action_session_id"]
|
|
174
|
+
# from the confirmation_required refusal
|
|
175
|
+
# @param app_user_id [String] the id of the user your backend has signed
|
|
176
|
+
# in; it must be the user the confirmation is for
|
|
177
|
+
# @return [Hash] "action_session_id", "owner_session_url",
|
|
178
|
+
# "enrollment_required" (true/false), "expires_at", and
|
|
179
|
+
# "enrollment_reason" ("no_passkey" or "no_eligible_authenticator")
|
|
180
|
+
# only when "enrollment_required" is true
|
|
181
|
+
# @raise [ArgumentError] on a bad argument, before any request
|
|
182
|
+
# @raise [ApiError] on any error status (no retry) or a malformed 2xx body
|
|
183
|
+
# @raise [IntrospectionError] when the hosted service cannot be reached
|
|
184
|
+
#
|
|
185
|
+
def create_owner_link(action_session_id:, app_user_id:)
|
|
186
|
+
unless action_session_id.is_a?(String) && action_session_id.start_with?("asess_") &&
|
|
187
|
+
action_session_id.length >= ACTION_SESSION_ID_MIN_LENGTH
|
|
188
|
+
raise ArgumentError, "action_session_id must be the action_session_id from the confirmation block (asess_...)"
|
|
189
|
+
end
|
|
190
|
+
unless app_user_id.is_a?(String) && !app_user_id.empty? && app_user_id.length <= APP_USER_ID_MAX_LENGTH
|
|
191
|
+
raise ArgumentError, "app_user_id must be a non-empty String of at most #{APP_USER_ID_MAX_LENGTH} characters"
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
path = "/api/v1/action-sessions/#{path_segment(action_session_id)}/owner-link"
|
|
195
|
+
response = send_post(path, { "app_user_id" => app_user_id }, authenticated: true, op: "create_owner_link")
|
|
196
|
+
status = response.code.to_i
|
|
197
|
+
parsed = begin
|
|
198
|
+
JSON.parse(response.body.to_s)
|
|
199
|
+
rescue JSON::ParserError
|
|
200
|
+
nil
|
|
201
|
+
end
|
|
202
|
+
body = parsed.is_a?(Hash) ? parsed : {}
|
|
203
|
+
|
|
204
|
+
unless status >= 200 && status < 300
|
|
205
|
+
code = body["error"].is_a?(String) ? body["error"] : nil
|
|
206
|
+
raise ApiError.new("create_owner_link returned #{status}#{code ? " #{code}" : ''}", status: status, code: code)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
enrollment = body["enrollment_required"]
|
|
210
|
+
unless body["owner_session_url"].is_a?(String) && (enrollment == true || enrollment == false) &&
|
|
211
|
+
body["action_session_id"].is_a?(String) && body["expires_at"].is_a?(String)
|
|
212
|
+
# The body is not attached: it may hold a partial owner link.
|
|
213
|
+
raise ApiError.new("create_owner_link returned a malformed response", status: status)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
link = { "action_session_id" => body["action_session_id"],
|
|
217
|
+
"owner_session_url" => body["owner_session_url"],
|
|
218
|
+
"enrollment_required" => enrollment,
|
|
219
|
+
"expires_at" => body["expires_at"] }
|
|
220
|
+
link["enrollment_reason"] = body["enrollment_reason"] if enrollment && body["enrollment_reason"].is_a?(String)
|
|
221
|
+
link
|
|
222
|
+
end
|
|
223
|
+
|
|
150
224
|
private
|
|
151
225
|
|
|
152
|
-
|
|
153
|
-
|
|
226
|
+
# Percent-encodes one path segment (space as %20, never "+").
|
|
227
|
+
def path_segment(value)
|
|
228
|
+
ERB::Util.url_encode(value)
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def build_http(uri)
|
|
154
232
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
155
233
|
http.use_ssl = uri.scheme == "https"
|
|
156
234
|
http.read_timeout = 10
|
|
157
235
|
http.open_timeout = 10
|
|
236
|
+
http
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
# Sends one POST and returns the Net::HTTP response; a transport failure
|
|
240
|
+
# raises IntrospectionError, exactly like the other calls on this client.
|
|
241
|
+
def send_post(path, body, authenticated:, op:)
|
|
242
|
+
uri = URI.parse("#{@config.api_url.chomp('/')}#{path}")
|
|
243
|
+
http = build_http(uri)
|
|
158
244
|
|
|
159
245
|
request = Net::HTTP::Post.new(uri.path)
|
|
160
246
|
request["Content-Type"] = "application/json"
|
|
@@ -166,11 +252,14 @@ module AgentAdmit
|
|
|
166
252
|
request.body = JSON.generate(body)
|
|
167
253
|
|
|
168
254
|
begin
|
|
169
|
-
|
|
255
|
+
http.request(request)
|
|
170
256
|
rescue StandardError => e
|
|
171
257
|
raise IntrospectionError, "#{op} failed: #{e.message}"
|
|
172
258
|
end
|
|
259
|
+
end
|
|
173
260
|
|
|
261
|
+
def post(path, body, authenticated:, op:)
|
|
262
|
+
response = send_post(path, body, authenticated: authenticated, op: op)
|
|
174
263
|
status = response.code.to_i
|
|
175
264
|
raise IntrospectionError, "#{op} returned #{status}" if status >= 400
|
|
176
265
|
|
data/lib/agentadmit/version.rb
CHANGED
data/lib/agentadmit.rb
CHANGED
|
@@ -127,9 +127,19 @@ module AgentAdmit
|
|
|
127
127
|
"Give the confirmation link to the user, then retry with " \
|
|
128
128
|
"the X-AgentAdmit-Action-Attestation header."
|
|
129
129
|
|
|
130
|
+
# SDK 1.15.0: what the agent is told when the confirmation needs a
|
|
131
|
+
# passkey the user has not created yet (confirmation["enrollment_required"]
|
|
132
|
+
# is true). This one replaces the hosted description.
|
|
133
|
+
ENROLLMENT_REQUIRED_DESCRIPTION =
|
|
134
|
+
"This action requires a fresh human confirmation, and this user has no " \
|
|
135
|
+
"passkey on file for the app yet, so the confirmation link alone cannot " \
|
|
136
|
+
"be used. Ask the user to open the request from inside the app. After " \
|
|
137
|
+
"they confirm, retry with the X-AgentAdmit-Action-Attestation header."
|
|
138
|
+
|
|
130
139
|
# @return [Hash] the strictly-typed staged ceremony: action_session_id,
|
|
131
140
|
# action_session_url, expires_at, scope (Strings), and method, endpoint,
|
|
132
|
-
# request_digest, summary (String or nil)
|
|
141
|
+
# request_digest, summary (String or nil); plus "enrollment_required"
|
|
142
|
+
# (true or false, 1.15.0) only when the hosted service stated it.
|
|
133
143
|
attr_reader :confirmation
|
|
134
144
|
# @return [String, nil] why a presented attestation was not accepted.
|
|
135
145
|
attr_reader :attestation_status
|
|
@@ -207,6 +217,23 @@ module AgentAdmit
|
|
|
207
217
|
end
|
|
208
218
|
|
|
209
219
|
class IntrospectionError < Error; end
|
|
220
|
+
|
|
221
|
+
##
|
|
222
|
+
# A hosted API call answered with an error status or a malformed body
|
|
223
|
+
# (SDK 1.15.0, raised by {TokensClient#create_owner_link}). A subclass of
|
|
224
|
+
# {IntrospectionError}, so existing rescues keep working. {#status} is the
|
|
225
|
+
# HTTP status, {#code} the hosted `error` code (nil for a malformed success
|
|
226
|
+
# body). The message never carries an owner link.
|
|
227
|
+
#
|
|
228
|
+
class ApiError < IntrospectionError
|
|
229
|
+
attr_reader :status, :code
|
|
230
|
+
|
|
231
|
+
def initialize(message, status:, code: nil)
|
|
232
|
+
super(message)
|
|
233
|
+
@status = status
|
|
234
|
+
@code = code
|
|
235
|
+
end
|
|
236
|
+
end
|
|
210
237
|
class ConfigurationError < Error; end
|
|
211
238
|
|
|
212
239
|
##
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: agentadmit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christopher Emerson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|