feat(api): add scoped persistent access token infrastructure - #790
Conversation
|
Thanks! But let's go step by step please - atomic PRs, even if it belong to a single feature. Let's first just implement the persistent token feature without the new anniversaries endpoint. And we need to think more long term - having a dedicated database migration just for a single feature without any extensibility doesn't make sense. Long lived access tokens with limited scope, anniversaries being one (the first) example. |
073fab6 to
4eacd13
Compare
|
Updated as requested and split to the first atomic step. This PR now contains only the generic persistent scoped token infrastructure (migration + helpers + scoped token lifecycle endpoint + tests). I removed the anniversaries ICS endpoint from this PR. I will open it as a follow-up PR on top of this once this part is reviewed. |
|
Hi, thanks for refactoring! I'll review when tests pass. |
|
Done ;) |
There was a problem hiding this comment.
Pull request overview
Adds a first-pass backend implementation for long-lived, scope-bound “persistent access tokens” (intended to support future features like an anniversaries ICS feed), including storage, auth helpers, endpoints, and endpoint tests.
Changes:
- Introduces an
access_tokenspersistence model + Alembic migration for user-scoped tokens. - Adds auth-layer helpers to validate scopes and manage token lifecycle (get/rotate/revoke/resolve user).
- Adds
/api/users/-/access-tokens/<scope>/GET/POST/DELETE endpoints plus endpoint tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_endpoints/test_access_tokens.py |
Adds endpoint-level lifecycle and validation tests for the new access-token endpoints. |
gramps_webapi/auth/const.py |
Defines allowed persistent access-token scopes. |
gramps_webapi/auth/__init__.py |
Adds AccessToken model and helper functions for token scope validation + lifecycle. |
gramps_webapi/api/resources/access_tokens.py |
Implements authenticated per-scope token management endpoints for the current user. |
gramps_webapi/api/__init__.py |
Registers the new access-token endpoint route. |
alembic_users/versions/6d8f3cb50b71_add_persistent_access_tokens_table.py |
Creates the new access_tokens table and indexes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@elig-45 please hold back your agent until I've completed the review, thanks! I appreciate your proactiveness but I can't review if you keep changing things. |
|
Also - it's ok if you use AI of course, but it's NOT OK if you just tell copilot to implement maintainer review comments, especially if they are security relevant. I expect you take full responsibility of all commits. |
|
Ok I understand, I wanted to try this functionnality here |
|
I looked into this in detail and thought about it for a while, but I realized I need to think deeper about the implications (security and design) before it's worth (for you) investing more work into it. In the case of OIDC authentication, I was a bit too quick merging the contribution without fully realizing the maintenance burden. Let's put this on hold for a few days and I'll come back with more useful feedback. |
|
np, keep me updated! |
|
Sorry for the delay. I think this is the right way foward. If you can rebase on current on current main and address the comments, I think we can merge this in the near future. Please make sure the tokens are not stored in the database (only an appropriate hash) and that GET doesn't return the token value (only whether it's active/valid). |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
3f35b6e to
f1d3eba
Compare
|
I rebased this branch on current
I also fixed the Alembic chain so there is a single migration head after rebase. |
|
Please review copilot's last comment and fix or reject. Apart from that, LGTM! |
…level unique/index flags Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Done ✅ |
|
Sorry for the delay. |
Summary
Implement the first atomic backend step: generic long-lived scoped access token infrastructure.
What’s included
access_tokenstable (Alembic migration), instead of a feature-specific column onusers.GET /api/users/-/access-tokens/<scope>/POST /api/users/-/access-tokens/<scope>/DELETE /api/users/-/access-tokens/<scope>/Not in this PR
/api/anniversaries.icsendpoint yet.Related