Skip to content

Commit

Permalink
feat(content-serve): delegate with auth token caveat
Browse files Browse the repository at this point in the history
  • Loading branch information
fforbeck committed Dec 9, 2024
1 parent 84c4c2c commit 56067b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions packages/capabilities/src/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ export const allocate = capability({
export const contentServe = capability({
can: 'space/content/serve/*',
with: SpaceDID,
nb: Schema.struct({
authToken: Schema.string().optional(),
}),
derives: equalWith,
})

Expand Down
19 changes: 12 additions & 7 deletions packages/w3up-client/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ export class Client extends Base {
* @param {object} [options] - Options for the content serve authorization invocation.
* @param {`did:${string}:${string}`} [options.audience] - The Web DID of the audience (gateway or peer) to authorize.
* @param {number} [options.expiration] - The time at which the delegation expires in seconds from unix epoch.
* @param {string} [options.authToken] - The auth token to use for the content serve authorization invocation.
*/
export const authorizeContentServe = async (
client,
Expand All @@ -582,14 +583,18 @@ export const authorizeContentServe = async (
did: () => options.audience ?? connection.id.did(),
}

// Grant the audience the ability to serve content from the space, it includes existing proofs automatically
const delegation = await client.createDelegation(
const delegation = await SpaceCapabilities.contentServe.delegate({
issuer: client.agent.issuer,
audience,
[SpaceCapabilities.contentServe.can],
{
expiration: options.expiration ?? Infinity,
}
)
with: space.did(),
expiration: options.expiration ?? Infinity,
nb: {
authToken: options.authToken,
},
proofs: client.proofs([
{ can: SpaceCapabilities.contentServe.can, with: space.did() },
]),
})

// Publish the delegation to the content serve service
const accessProofs = client.proofs([
Expand Down

0 comments on commit 56067b2

Please sign in to comment.