Skip to content

Commit

Permalink
implement pds did:web well-known endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuchanan314 committed Dec 10, 2024
1 parent e755cb0 commit de236c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/millipds/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import json
import base64
import hashlib
import urllib.parse
from getpass import getpass

from docopt import docopt
Expand Down Expand Up @@ -98,21 +99,21 @@ def main():
if args["--dev"]: # like prod but http://
db.update_config(
pds_pfx=f'http://{args["<hostname>"]}',
pds_did=f'did:web:{args["<hostname>"]}',
pds_did=f'did:web:{urllib.parse.quote(args["<hostname>"])}',
bsky_appview_pfx="https://api.bsky.app",
bsky_appview_did="did:web:api.bsky.app",
)
elif args["--sandbox"]: # now-defunct, need to figure out how to point at local infra
db.update_config(
pds_pfx=f'https://{args["<hostname>"]}',
pds_did=f'did:web:{args["<hostname>"]}',
pds_did=f'did:web:{urllib.parse.quote(args["<hostname>"])}',
bsky_appview_pfx="https://api.bsky-sandbox.dev",
bsky_appview_did="did:web:api.bsky-sandbox.dev",
)
else: # "prod" presets
db.update_config(
pds_pfx=f'https://{args["<hostname>"]}',
pds_did=f'did:web:{args["<hostname>"]}',
pds_did=f'did:web:{urllib.parse.quote(args["<hostname>"])}',
bsky_appview_pfx="https://api.bsky.app",
bsky_appview_did="did:web:api.bsky.app",
)
Expand Down
18 changes: 18 additions & 0 deletions src/millipds/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ async def hello(request: web.Request):

return web.Response(text=msg)


@routes.get("/.well-known/did.json") # serve this server's did:web document (nb: reference PDS impl doesn't do this, hard to know the right thing to do)
async def well_known_did_web(request: web.Request):
cfg = get_db(request).config
return web.json_response({
"@context": [
"https://www.w3.org/ns/did/v1",
],
"id": cfg["pds_did"],
"service": [{ # is this the right thing to do?
"id": "#atproto_pds",
"type": "AtprotoPersonalDataServer",
"serviceEndpoint": cfg["pds_pfx"]
}]
})



@routes.get("/robots.txt")
async def robots_txt(request: web.Request):
return web.Response(text="""\
Expand Down

0 comments on commit de236c2

Please sign in to comment.