Skip to content

Commit 9f68f9b

Browse files
actually store PARs
1 parent 9a2bb78 commit 9f68f9b

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

src/millipds/auth_oauth.py

+23-7
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,34 @@ async def dpop_handler(request: web.Request):
321321
@dpop_protected
322322
async def oauth_pushed_authorization_request(request: web.Request):
323323
# NOTE: rfc9126 says this is posted as form data, but this is atproto-flavoured oauth
324-
data = await request.json()
325-
logging.info(data)
324+
request_json = await request.json()
325+
logging.info(request_json)
326326

327-
assert data["client_id"] == request["dpop_iss"] # idk if this is required
327+
# idk if this is required
328+
assert request_json["client_id"] == request["dpop_iss"]
328329

329-
# TODO: request client metadata???
330+
now = int(time.time())
331+
par_uri = "urn:ietf:params:oauth:request_uri:req-" + secrets.token_hex()
330332

331-
# TODO: we need to store the request somewhere, and associate it with the URI we return (and also the DPoP key)
333+
# NOTE: we don't do any verification of the auth request itself, we just associate it with a URI for later retreival.
334+
get_db(request).con.execute(
335+
"""
336+
INSERT INTO oauth_par (
337+
uri, dpop_jwk, value, created_at, expires_at
338+
) VALUES (?, ?, ?, ?, ?)
339+
""",
340+
(
341+
par_uri,
342+
request["dpop_jwk"],
343+
cbrrr.encode_dag_cbor(request_json),
344+
now,
345+
now + static_config.OAUTH_PAR_EXP,
346+
),
347+
)
332348

333349
return web.json_response(
334350
{
335-
"request_uri": "urn:ietf:params:oauth:request_uri:req-064ed63e9fbf10815fd5f402f4f3e92a", # XXX hardcoded test
336-
"expires_in": 299,
351+
"request_uri": par_uri,
352+
"expires_in": static_config.OAUTH_PAR_EXP,
337353
}
338354
)

src/millipds/database.py

+14
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,20 @@ def _init_tables(self):
275275
"""
276276
)
277277

278+
# TODO: unsure if we need to track dpop jwk here?
279+
# (if we do, it could just be a hash of the key)
280+
self.con.execute(
281+
"""
282+
CREATE TABLE oauth_par(
283+
uri TEXT PRIMARY KEY NOT NULL,
284+
dpop_jwk BLOB NOT NULL,
285+
value BLOB NOT NULL,
286+
created_at INTEGER NOT NULL,
287+
expires_at INTEGER NOT NULL
288+
) STRICT, WITHOUT ROWID
289+
"""
290+
)
291+
278292
# has user granted a particular scope to a particular app?
279293
self.con.execute(
280294
"""

src/millipds/static_config.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
REFRESH_EXP = 60 * 60 * 24 * 90 # 90 days
3535

3636
OAUTH_COOKIE_EXP = 60 * 60 * 24 * 90 # 90 days
37+
OAUTH_PAR_EXP = 300

0 commit comments

Comments
 (0)