Skip to content

feat: PATCH /users/<id>/reset-auth-token — rotate API token without invalidating sessions#2214

Draft
Copilot wants to merge 4 commits into
mainfrom
copilot/extensive-tech-spike-recommendation
Draft

feat: PATCH /users/<id>/reset-auth-token — rotate API token without invalidating sessions#2214
Copilot wants to merge 4 commits into
mainfrom
copilot/extensive-tech-spike-recommendation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 1, 2026

From issue #1800's tech spike (Option A): add a dedicated endpoint to rotate a user's API auth token (fs_token_uniquifier) independently of their browser session (fs_uniquifier).

Backend

  • New service fn reset_token_access(user) in data/services/users.py — calls user_datastore.set_token_uniquifier(user), leaving fs_uniquifier (and thus cookies/sessions) intact
  • New endpoint PATCH /api/v3_0/users/<id>/reset-auth-token — requires update permission, writes an audit log entry; mirrors existing PATCH /<id>/password-reset pattern

UI

  • "Reset access token" button on /logged-in-user (self-service) and /users/<id> (shown to users with update permission)
  • Uses fetch PATCH + toast; self-service page reloads to surface the newly-issued token

Config

  • SECURITY_TOKEN_MAX_AGE = None (no expiry) was already set — no change needed

Tests

test_user_reset_auth_token (6 parametrized cases): verifies 401/403/200 auth rules, asserts fs_uniquifier is unchanged after the call, fs_token_uniquifier is rotated, and the audit log record is created.

Copilot AI and others added 2 commits May 31, 2026 21:42
Agent-Logs-Url: https://github.com/FlexMeasures/flexmeasures/sessions/fe1f22ac-0352-484a-96f4-2f4057311057

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI changed the title Phase 1: Auth token reset endpoint + UI (Issue #1800) feat: PATCH /users/<id>/reset-auth-token — rotate API token without invalidating sessions Jun 1, 2026
Copilot finished work on behalf of Flix6x June 1, 2026 09:20
Copilot AI requested a review from Flix6x June 1, 2026 09:20
Signed-off-by: F.N. Claessen <claessen@seita.nl>
@nhoening
Copy link
Copy Markdown
Member

nhoening commented Jun 1, 2026

Are you aware of pallets-eco/flask-security#1206 ?

@nhoening
Copy link
Copy Markdown
Member

nhoening commented Jun 1, 2026

Are you aware of pallets-eco/flask-security#1206 ?

Oh wait, this is about resetting tokens. The refresh token thing might be a different spike.

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