Skip to content

Commit

Permalink
new table to track oauth grants
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBuchanan314 committed Jan 17, 2025
1 parent 769a828 commit 1bc99b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/millipds/auth_oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async def oauth_authorize_handle_login(request: web.Request):
now = int(time.time())
db.con.execute(
"""
INSERT INTO session_cookie (
INSERT INTO oauth_session_cookie (
token, user_id, value, created_at, expires_at
) VALUES (?, ?, ?, ?, ?)
""",
Expand Down
17 changes: 16 additions & 1 deletion src/millipds/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def _init_tables(self):

# this is only for the tokens *we* issue, dpop jti will be tracked separately
# there's no point remembering that an expired token was revoked, and we'll garbage-collect these periodically
# note: I'm using did here instead of user_id, this is vaguely inconsistent
# with other tables but in practice it should reduce query complexity
self.con.execute(
"""
CREATE TABLE revoked_token(
Expand All @@ -262,7 +264,7 @@ def _init_tables(self):
# oauth stuff!
self.con.execute(
"""
CREATE TABLE session_cookie(
CREATE TABLE oauth_session_cookie(
token TEXT PRIMARY KEY NOT NULL,
user_id INTEGER NOT NULL,
value BLOB NOT NULL,
Expand All @@ -273,6 +275,19 @@ def _init_tables(self):
"""
)

# has user granted a particular scope to a particular app?
self.con.execute(
"""
CREATE TABLE oauth_grants(
user_id INTEGER NOT NULL,
client_id TEXT NOT NULL,
scope TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES user(id),
PRIMARY KEY (user_id, client_id, scope)
) STRICT, WITHOUT ROWID
"""
)

def update_config(
self,
pds_pfx: Optional[str] = None,
Expand Down

0 comments on commit 1bc99b8

Please sign in to comment.