Skip to content
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

Facilitate authing w/ PDS based on DID doc #1727

Merged
merged 11 commits into from
Oct 26, 2023
Merged

Facilitate authing w/ PDS based on DID doc #1727

merged 11 commits into from
Oct 26, 2023

Conversation

devinivy
Copy link
Collaborator

@devinivy devinivy commented Oct 9, 2023

  • Add didDoc output to lexicons used to create or refresh a session.
  • Allow configuring PDS to include didDoc on those lexicon methods.
  • Update API to use the returned pds endpoint

@@ -36,7 +36,8 @@
"@atproto/xrpc": "workspace:^",
"multiformats": "^9.9.0",
"tlds": "^1.234.0",
"typed-emitter": "^2.1.0"
"typed-emitter": "^2.1.0",
"zod": "^3.21.4"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an addition to the api because its dependencies already depended on it

export function getPdsEndpoint(doc: unknown): URL | undefined {
if (isValidDidDoc(doc)) {
const pds = doc.service?.find((s) => s.type === 'AtprotoPersonalDataServer')
if (pds && typeof pds.serviceEndpoint === 'string') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is currently taking the first PDS service entry and only handling the string value. I don't know what a non-string value would look like.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that'd be considered a valid json-ld did document, but not supported by atproto rn

this is similar to how we validate services in our identity resolver 👍

@pfrazee
Copy link
Collaborator

pfrazee commented Oct 11, 2023

@devinivy I tested by fudging some responses but I don't have a great way to test this meaningfully or in the test suite, and I'm only somewhat confident that it's correct. We either need to cook up good automated tests or be really aggressive about testing in staging scenarios before deploying.

@@ -157,6 +165,7 @@ export class AtpAgent {
this.session.email = res.data.email
this.session.handle = res.data.handle
this.session.emailConfirmed = res.data.emailConfirmed
this._updateApiEndpoint(res.data.didDoc)
Copy link
Collaborator Author

@devinivy devinivy Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, missed this in original review. This endpoint getSession doesn't include the did doc—if the credentials are no longer valid due to having migrated PDSes, the client will receive an ExpiredToken error and get set back on track via the refresh flow.

Suggested change
this._updateApiEndpoint(res.data.didDoc)

@devinivy devinivy marked this pull request as ready for review October 24, 2023 14:28
@@ -0,0 +1,40 @@
import { z } from 'zod'

export const verificationMethod = z.object({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm we already have something very similar this over in @atproto/identity - we may want to just use the code there instead of duplicating it over to the api package 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or if the client doesn't agree with the dependencies of that package, porting just these types & verification methods over to @atproto/common-web


export function getPdsEndpoint(doc: unknown): URL | undefined {
if (isValidDidDoc(doc)) {
const pds = doc.service?.find((s) => s.type === 'AtprotoPersonalDataServer')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in @atproto/identity, we find the first service entry with id #atproto_pds & then check the type

Copy link
Collaborator

@dholms dholms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet implementation seems sound 👌

Only thing I'd push for is moving the did doc logic to a common location - either @atproto/identity or @atproto/common-web

@devinivy
Copy link
Collaborator Author

@dholms took a quick swing at addressing your feedback.

@pfrazee
Copy link
Collaborator

pfrazee commented Oct 25, 2023

@devinivy if you dont mind just making any changes you think are needed, seems minor

@devinivy
Copy link
Collaborator Author

@pfrazee yup I got it from here!

@@ -0,0 +1,24 @@
import { DidDocument, didDocument } from '@atproto/common-web'

export function isValidDidDoc(doc: unknown): doc is DidDocument {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required, but I think we could take this one step further & move this to common-web as well

@devinivy devinivy merged commit 46b108c into main Oct 26, 2023
@devinivy devinivy deleted the auth-via-did-doc branch October 26, 2023 22:29
mloar pushed a commit to mloar/atproto that referenced this pull request Nov 15, 2023
* lexicon for did doc w/ auth credentials

* include did doc w/ session when configured. configure on dev-env.

* Add dynamic PDS URL adoption to the client

* remove usage of did doc field from getsession in client

* dry-up did doc type and validation

* remove explicit dep on zod by identity package

* move more did doc parsing to common-web

* go back to strings

* rollback breaking changes to identity package

* add changeset

---------

Co-authored-by: Paul Frazee <[email protected]>
Co-authored-by: dholms <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants