Skip to content

Commit 67605fa

Browse files
authored
Document existing-user AgentCard wallet imports (#711)
1 parent 8f7318b commit 67605fa

2 files changed

Lines changed: 85 additions & 7 deletions

File tree

‎integrations/wallets/agentcard.mdx‎

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,80 @@ kernel vault-provider-configs create \
164164
</CodeGroup>
165165

166166
the response exposes `test_mode` (`true` means sandbox, `false` means live).
167-
verify it against `AGENTCARD_MODE`. then create the wallet with the
168-
project-scoped `kernel` client and `vault` from
169-
[Before you start](#before-you-start). CLI users should restore their
170-
project-scoped `KERNEL_API_KEY` before running the wallet command.
167+
verify it against `AGENTCARD_MODE`. create the wallet with the project-scoped
168+
`kernel` client and `vault` from [Before you start](#before-you-start).
169+
CLI users must restore their project-scoped `KERNEL_API_KEY` before running
170+
wallet commands.
171+
172+
#### Import an existing user
173+
174+
complete agentcard's [enrollment or sign-in flow](https://docs.agentcard.sh/vault/adding-a-card)
175+
in your own application and store the resulting `usr_` user id. if you've
176+
already connected the user, reuse that id; don't enroll them again.
177+
178+
pass the user id with your provider configuration. the examples read it from
179+
`AGENTCARD_USER_ID` on your server. in your application, resolve the id from the
180+
stored mapping for the authenticated end user who owns the vault, not from an
181+
untrusted request field. no per-user access or refresh tokens are required.
182+
183+
<CodeGroup>
184+
185+
```typescript TypeScript
186+
const wallet = await kernel.vaults.items.upsert("agentcard-wallet", {
187+
id_or_name: vault.id,
188+
type: "wallet",
189+
spec: {
190+
provider: "agentcard",
191+
provider_config: { name: agentcardConfig.name },
192+
user_id: process.env.AGENTCARD_USER_ID!,
193+
},
194+
});
195+
```
196+
197+
```python Python
198+
wallet = kernel.vaults.items.upsert(
199+
"agentcard-wallet",
200+
id_or_name=vault.id,
201+
type="wallet",
202+
spec={
203+
"provider": "agentcard",
204+
"provider_config": {"name": agentcard_config.name},
205+
"user_id": os.environ["AGENTCARD_USER_ID"],
206+
},
207+
)
208+
```
209+
210+
```bash CLI
211+
kernel vaults wallets create user-12345 agentcard-wallet \
212+
--provider agentcard \
213+
--provider-config-name checkout-agentcard \
214+
--spec "$(jq -n --arg user_id "$AGENTCARD_USER_ID" '{user_id: $user_id}')"
215+
```
216+
217+
</CodeGroup>
218+
219+
the cli example uses `jq` to build the json specification. KERNEL validates
220+
provider access using the selected credentials and their sandbox/live mode
221+
before creating the wallet. a successful import returns `state.status` set to
222+
`connected`, without a `card_enrollment` action. KERNEL manages the
223+
client-credentials access token; there's no per-user refresh-token handoff.
224+
225+
a valid connection with no stored cards also returns `connected`. inspect the
226+
wallet's advertised `payment_methods` expansion before creating a purchase;
227+
a connected wallet alone doesn't mean a card is available. continue with
228+
[Create a card item](#create-a-card-item) once the user has a stored card.
229+
230+
if agentcard rejects the user or credentials, import returns `400` without
231+
creating a wallet. check the user id, provider configuration, and sandbox/live
232+
mode, then retry with the corrected specification. after success, the user and
233+
configuration bindings are immutable. repeating the same key and specification
234+
returns the existing wallet; changing either binding returns `409`.
235+
236+
#### Enroll through KERNEL instead
237+
238+
if you want KERNEL to create and poll the hosted enrollment session, omit
239+
`user_id` while keeping your provider configuration. this is an alternative to
240+
importing a connected user, not a second step after import.
171241

172242
<CodeGroup>
173243

@@ -237,7 +307,7 @@ deadline expires. then continue with [Create a card item](#create-a-card-item).
237307

238308
## Lifecycle
239309

240-
1. create a `wallet` item and open the returned `card_enrollment` action for the user.
310+
1. connect a `wallet` item: open the returned `card_enrollment` action, or import an existing user with your own provider configuration.
241311
2. wait for the wallet to become `connected`.
242312
3. create a reusable `card` item with the merchant, amount, and currency.
243313
4. attach the vault to a browser and give `state.aliases` to the agent.
@@ -352,7 +422,10 @@ kernel vaults items get user-12345 agentcard-wallet --wait 60
352422
contain the action url.
353423
</Warning>
354424

355-
`spec.user_id` can reuse a user who was already enrolled through another wallet in your organization. it cannot reference an arbitrary agentcard user.
425+
with KERNEL-managed credentials, `spec.user_id` can only reuse a user already
426+
connected through another wallet in your organization under the same
427+
configuration. to import a user connected through your own application, select
428+
your customer-owned configuration and follow [Import an existing user](#import-an-existing-user).
356429

357430
## Create a card item
358431

@@ -745,7 +818,7 @@ wallet and card items accept these `spec` fields. fields not listed here are rej
745818

746819
| item | required fields | optional fields |
747820
| --- | --- | --- |
748-
| wallet | `provider: 'agentcard'` | `provider_config`; `user_id` for a user already enrolled in the organization under the same configuration |
821+
| wallet | `provider: 'agentcard'` | `provider_config`; `user_id` to import a connected user with customer-owned credentials, or reuse an organization-local user with KERNEL-managed credentials |
749822
| card | `provider`, `wallet`, `merchant`, `amount`, `currency` | `card_id`, `checkout_origin` |
750823

751824
agentcard accepts amounts from 1–9007199254740991 and a three-letter `currency`. `merchant` accepts 1–120 printable characters without control characters. `card_id` uses the provider's `vc_` identifier, and wallet `user_id` uses its `usr_` identifier.

‎integrations/wallets/overview.mdx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ provider configuration stores your application's `client_id` and `client_secret`
7272
not an end user's wallet grant. credentials are encrypted at rest; secrets are
7373
never returned.
7474

75+
with your own client, you can connect users in your backend before creating
76+
wallets in KERNEL. link imports the user's oauth access and refresh tokens;
77+
agentcard imports the connected user's `user_id` after validating provider
78+
access under your configuration, without another hosted enrollment action.
79+
7580
configurations are organization-scoped and shared across projects, unlike
7681
project-scoped vaults. create, update, and delete require organization-scoped
7782
authentication; project-scoped api keys receive `403`. names are unique within

0 commit comments

Comments
 (0)