feat(auth): decode_token rejects legacy 4-field JWTs as WORKSPACE_MISSING

After PR4 every JWT must carry wid (workspace_id). decode_token now
returns the new TokenError.WORKSPACE_MISSING when the signature is
valid but the payload lacks wid; expired tokens still report EXPIRED
first so /auth/refresh logic stays correct. AuthErrorCode gains a
matching WORKSPACE_REQUIRED for middleware to surface to clients.

Updates 13 existing test sites that issued tokens without wid to pass
workspace_id="ws-test" + role="owner", reflecting the new contract.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1445043649
2026-05-12 22:22:10 +08:00
parent 54cb94c30f
commit b4bef65079
6 changed files with 97 additions and 15 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ def test_decode_token_returns_token_error_on_malformed():
def test_decode_token_returns_payload_on_valid():
_setup_config()
token = create_access_token("user-123")
token = create_access_token("user-123", workspace_id="ws-test", role="owner")
result = decode_token(token)
assert not isinstance(result, TokenError)
assert result.sub == "user-123"