Authorization Server and Resource Server OAuth token schema rollback compatibility
0 reputation · 28 Mar 2021, 13:26 UTC
0 reputation · 28 Mar 2021, 13:26 UTC
The goal is to guarantee that a change to the OAuth token store schema—such as adding a column or altering a data type—can be rolled back without causing validation failures for tokens that were issued before or after the change.
Constraints include the lack of a standardized schema‑version signal in the token introspection response, the need for both the Authorization Server (which writes tokens) and the Resource Server (which reads/introspects them) to tolerate the previous schema during the rollback window, and the variability of token‑store implementations across libraries and back‑ends.
Given these factors, what migration patterns ensure bidirectional compatibility? How can developers verify that tokens issued under the new schema remain validatable after reverting to the old schema without introducing version‑specific code? Are there safe defaults or nullable‑column strategies that eliminate the need for coordinated downtime?
34775 reputation · 28 Mar 2021, 23:37 UTC
To guarantee that a schema change can be rolled back without invalidating tokens issued during the deployment window, you must decouple the physical storage schema from the logical token validation. The most effective pattern is the Additive-Only Migration combined with Graceful Degradation.
Never modify or delete existing columns during a forward migration. To introduce a change:
NULLABLE. The Authorization Server (AS) begins writing to both the old and new columns.token_metadata_v2) rather than altering the existing column.Because the old columns remain untouched and populated, a rollback of the AS code will simply result in the system ignoring the new columns, while the old logic continues to find the data it expects.
The Resource Server must be programmed to treat new schema attributes as optional. If the RS uses token introspection, the introspection endpoint should be configured to return a stable set of claims regardless of the underlying storage version. If the RS validates tokens locally (e.g., JWTs), it should ignore unknown claims rather than throwing a validation error.
To verify that tokens issued under the new schema remain valid after a rollback without writing if (version == 2) blocks, use Cross-Version Integration Testing:
To eliminate coordinated downtime, adopt these defaults:
INSERT operations without knowing about the new fields.Missing Diagnostic Detail: Are you using opaque tokens (requiring a database lookup/introspection) or self-contained tokens (like JWTs)? The strategy for RS validation differs significantly if the RS is hitting a database versus verifying a cryptographic signature.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 28 Mar 2021, 15:28 UTC
One addition to the expand-and-dual-write approach: the compatibility window does not have to be open-ended. Access tokens are transient, so the period in which both schemas must stay readable is naturally capped by the longest token TTL the Authorization Server issues, plus clock skew and any Resource Server cache lifetime.
Expiry is already part of the token model, so this needs no schema-version signal in introspection — it turns migration timing into a checkable condition.