Skip to content

Commit 25f2915

Browse files
authored
session payments: add token rotation flow (#23)
1 parent e0c2255 commit 25f2915

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

section/session-flow.html

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,31 @@ <h3>Payment streaming</h3>
266266
<li>Let |result:OutgoingPaymentResult| be the result of [=send a create outgoing payment request=]
267267
with |userWallet|'s {{UserWallet/walletAddressDetails}}, |session|'s {{Session/incomingPaymentId}},
268268
|amountValue|, and |userWalletGrant|.</li>
269+
<li>If |result| is {{OutgoingPaymentResult/"token-invalid"}}:
270+
<ol>
271+
<li>Let |rotatedAccessToken:AccessToken| be the result of [=send a rotate access token request=]
272+
with |userWalletGrant|.</li>
273+
<li>If |rotatedAccessToken| is failure:
274+
<ol>
275+
<li>[=Revoke user wallet credentials=].</li>
276+
<li>Return.</li>
277+
</ol>
278+
</li>
279+
<li>Set |userWalletGrant|'s {{Grant/access_token}} to |rotatedAccessToken|.</li>
280+
<li>Run [=update grant access token=] with |rotatedAccessToken|.</li>
281+
<li>Set |result| to the result of [=send a create outgoing payment request=]
282+
with |userWallet|'s {{UserWallet/walletAddressDetails}}, |session|'s {{Session/incomingPaymentId}},
283+
|amountValue|, and |userWalletGrant|.</li>
284+
</ol>
285+
</li>
269286
<li>If |result| is {{OutgoingPaymentResult/"success"}}:
270287
<ol>
271288
<li>[=Fire monetization event=] given |session|, |amount|, and |userWallet|.</li>
272289
<li>[=Schedule payment streaming tick=].</li>
273290
<li>Return.</li>
274291
</ol>
275292
</li>
276-
<li>Otherwise:
277-
<ol>
278-
<li>TODO: Handle token rotation and other failure cases.</li>
279-
</ol>
280-
</li>
293+
<li>[=Revoke user wallet credentials=].</li>
281294
</ol>
282295
</div>
283296

@@ -321,5 +334,29 @@ <h3>Payment streaming</h3>
321334
</ol>
322335
<p class="note">For example, <code>convert scaled amount to decimal(100, 2)</code> returns <code>"1.00"</code>.</p>
323336
</div>
337+
338+
<div class="algorithm">
339+
<p>To <dfn>revoke user wallet credentials</dfn>, run these steps:</p>
340+
<ol>
341+
<li>Run [=update grant access token=] with the empty string.</li>
342+
<li>For each |session| in the [=active sessions list=]:
343+
<ol>
344+
<li>Remove |session| from the [=active sessions list=].</li>
345+
</ol>
346+
</li>
347+
<li>Set the [=current session iterator=] to the [=end iterator=].</li>
348+
</ol>
349+
<aside class="note">
350+
<p>
351+
Revoking credentials clears the access token but preserves other user wallet information
352+
(wallet address, auth keys). This allows the user interface to display a "Reconnect" prompt
353+
rather than requiring the user to set up their wallet again from scratch.
354+
</p>
355+
<p>
356+
All active monetization sessions are terminated since payments can no longer be made.
357+
</p>
358+
</aside>
359+
</div>
360+
324361
</section>
325362
</section>

section/storage.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ <h3>Storage operations</h3>
9090
</ol>
9191
</div>
9292

93+
<div class="algorithm">
94+
<p>To <dfn>update grant access token</dfn>, given |accessToken:DOMString|:</p>
95+
<ol>
96+
<li>Let |storage| be the result of [=get storage=].</li>
97+
<li>If |storage|'s {{Storage/grant}} is null, return.</li>
98+
<li>Set |storage|'s {{Storage/grant}}'s {{Grant/access_token}} to |accessToken|.</li>
99+
<li>[=Persist storage=] with |storage|.</li>
100+
</ol>
101+
<p class="note">This algorithm updates only the access token within an existing grant,
102+
preserving other grant properties. Used during token rotation when the authorization
103+
server issues a new access token. When |accessToken| is the empty string, the grant is
104+
invalidated but wallet information is preserved for reconnection.</p>
105+
</div>
106+
93107
<div class="algorithm">
94108
<p>To <dfn>store auth keys</dfn>, given |authKeys:AuthKeys|:</p>
95109
<ol>

0 commit comments

Comments
 (0)