-
Notifications
You must be signed in to change notification settings - Fork 19
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!: upgrade capabilities to latest ucanto #463
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2f320ae
feat!: upgrade capabilities to latest ucanto
Gozala 449fc5a
fix: tests
Gozala 556d588
fix: type errors
Gozala fe7d244
chore: undo unnecessary type annotation
Gozala 1d590c1
feat: update access/authorize capability per spec
Gozala c7c6752
update ucan/authorize provider
Gozala 08af6cf
chore: close the security hole
Gozala 236077c
update ucanto version
Gozala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,21 +14,27 @@ export function accessAuthorizeProvider(ctx) { | |
return Server.provide( | ||
Access.authorize, | ||
async ({ capability, invocation }) => { | ||
const session = await Access.session | ||
/** | ||
* We re-delegate the capability to the account DID and limit it's | ||
* lifetime to 15 minutes which should be enough time for the user to | ||
* complete the authorization. We don't want to allow authorization for | ||
* long time because it could be used by an attacker to gain authorization | ||
* by sending second request misleading a user to click a wrong one. | ||
*/ | ||
const authorization = await Access.authorize | ||
.invoke({ | ||
issuer: ctx.signer, | ||
audience: DID.parse(capability.nb.as), | ||
with: ctx.signer.did(), | ||
lifetimeInSeconds: 86_400 * 7, // 7 days | ||
nb: { | ||
key: capability.with, | ||
}, | ||
audience: DID.parse(capability.nb.iss), | ||
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. information coming in is {
with: "did:key:zAlice",
can: "access/authorize",
nb: {
iss: "did:malito:web.mail:alice"
att: [{ can: "*" }]
}
} 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. {
"iss": "did:web:web3.storage",
"aud": "did:malito:web.mail:alice",
"expiration": 15,
"att": [{
can: "access/confirm",
with: "did:web:web.storage",
nb: {
aud: "did:key:zAlice",
iss: "did:malito:web.mail:alice",
att: [{ can: "*" }]
}
}]
} |
||
with: capability.with, | ||
lifetimeInSeconds: 60 * 15, // 15 minutes | ||
nb: capability.nb, | ||
proofs: [invocation], | ||
}) | ||
.delegate() | ||
|
||
const encoded = delegationToString(session) | ||
const encoded = delegationToString(authorization) | ||
|
||
await ctx.models.accounts.create(capability.nb.as) | ||
await ctx.models.accounts.create(capability.nb.iss) | ||
|
||
const url = `${ctx.url.protocol}//${ctx.url.host}/validate-email?ucan=${encoded}&mode=session` | ||
// For testing | ||
|
@@ -37,7 +43,7 @@ export function accessAuthorizeProvider(ctx) { | |
} | ||
|
||
await ctx.email.sendValidation({ | ||
to: Mailto.toEmail(capability.nb.as), | ||
to: Mailto.toEmail(capability.nb.iss), | ||
url, | ||
}) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
same