fix(auth): invalidate scope cache on web/REST provisioning paths

The elicitation flow points users to the Astrolabe web route or the
BasicAuth REST endpoint to provision their app password. Both paths
stored the password without clearing the in-process scope cache, so a
user who provisioned through them would keep hitting
ProvisioningRequiredError for up to _SCOPE_CACHE_TTL (5 min) afterwards.

Add invalidate_scope_cache(user_id) to both write-paths (matching the
existing pattern in nc_auth_check_status), correct the now-misleading
comment in scope_authorization.py to name all three invalidation paths,
and add a one-line hint above the first elicitation patch in the test
file so future authors don't "fix" the patch target to the wrong module.

Addresses PR #757 round-3 review feedback.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-05-02 16:59:53 +02:00
co-authored by Claude Opus 4.7
parent 7464340763
commit f31d0544b7
4 changed files with 17 additions and 5 deletions
@@ -169,11 +169,16 @@ def require_scopes(*required_scopes: str):
# again (which would loop).
if elicit_result == "accepted":
# Note: stored-scope lookups are cached for
# _SCOPE_CACHE_TTL (5 min). Both nc_auth_provision_access
# and the Astrolabe web route invalidate the cache when
# they finish, but if the LFv2 poller is still in-flight
# at acknowledge-time the next retry can still hit the
# stale cache — hence the "wait a moment" qualifier.
# _SCOPE_CACHE_TTL (5 min). All three provisioning
# paths invalidate the cache on completion: the
# in-tool poller in nc_auth_check_status
# (auth_tools.py), the Astrolabe web route
# (provision_routes.py), and the BasicAuth REST
# endpoint (api/passwords.py). However, if the
# LFv2 poller is still in-flight at acknowledge-
# time the next retry can still hit a not-yet-
# populated entry — hence the "wait a moment"
# qualifier below.
error_msg = (
f"Access denied to {func_name}: Nextcloud "
f"access was not provisioned at the time of "