-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: access/authorize confirmation email click results in a delegation back to the issuer did:key so that access/claim works #460
Changes from 7 commits
6db052a
24f9266
94b1577
b92fad2
1735d15
c951907
a8cab05
1be596f
013ac0d
722abde
83141c4
685af65
48f4744
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* eslint-disable no-unused-vars */ | ||
import { stringToDelegation } from '@web3-storage/access/encoding' | ||
import * as Access from '@web3-storage/capabilities/access' | ||
import QRCode from 'qrcode' | ||
import { toEmail } from '../utils/did-mailto.js' | ||
import { | ||
|
@@ -8,6 +9,9 @@ import { | |
ValidateEmailError, | ||
PendingValidateEmail, | ||
} from '../utils/html.js' | ||
import * as ucanto from '@ucanto/core' | ||
import * as validator from '@ucanto/validator' | ||
import { Verifier } from '@ucanto/principal/ed25519' | ||
|
||
/** | ||
* @param {import('@web3-storage/worker-utils/router').ParsedRequest} req | ||
|
@@ -134,6 +138,38 @@ async function session(req, env) { | |
req.query.ucan, | ||
delegation.capabilities[0].nb.key | ||
) | ||
if (req.method.toLowerCase() === 'post') { | ||
const accessSessionResult = await validator.access(delegation, { | ||
capability: Access.session, | ||
principal: Verifier, | ||
authority: env.signer, | ||
}) | ||
if (accessSessionResult.error) { | ||
throw new Error( | ||
`unable to validate access session: ${accessSessionResult.error}` | ||
) | ||
} | ||
// generate a delegation to the key that we can save in | ||
// models.delegations to be found by subsequent access/claim | ||
// invocations invoked by the did:key | ||
const delegateToKey = await ucanto.delegate({ | ||
issuer: env.signer, | ||
audience: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Audience of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok. I updated to not use |
||
did() { | ||
return accessSessionResult.capability.nb.key | ||
}, | ||
}, | ||
proofs: [delegation], | ||
capabilities: [ | ||
{ | ||
can: './update', | ||
with: env.signer.did(), | ||
nb: accessSessionResult.capability.nb, | ||
}, | ||
], | ||
}) | ||
await env.models.delegations.putMany(delegateToKey) | ||
} | ||
|
||
try { | ||
return new HtmlResponse( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should be renamed and update comments as it does a different thing now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed/recommented in 685af65