feat(token-vault): require exactly one of accessToken or refreshToken #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Enforce an explicit and unambiguous subject token choice for Token Vault exchanges by requiring exactly one of
accessTokenorrefreshToken. This aligns with how the backend must identify the subject token type for exchange and prevents accidental misuse.What & Why
The Token Vault exchange methods (
getTokenForConnectionin auth-js andgetAccessTokenForConnectionin api-js) now enforce XORvalidation: callers must provide exactly one of
accessTokenorrefreshToken, not both and not neither.subject_token_typefor the exchange. Allowing both tokens would inviteconfusion or accidental mismatches.
Changes
Scope: Enhanced types + validation + docs + tests
auth0-auth-js
src/auth-client.ts:SUBJECT_TYPE_ACCESS_TOKENandSUBJECT_TYPE_REFRESH_TOKENwith usage guidancegetTokenForConnection()src/types.ts:SubjectTokendiscriminated union for compile-time XOR enforcementTokenForConnectionOptionswith comprehensive guidancesrc/auth-client.spec.ts: Updated test to match new error messageEXAMPLES.md: Added note about XOR requirementauth0-api-js
src/api-client.ts: Added XOR runtime validation ingetAccessTokenForConnection()src/types.ts:SubjectTokendiscriminated unionAccessTokenForConnectionOptionssrc/api-client.spec.ts: Added new test for XOR validationEXAMPLES.md: DocumentedrefreshTokenparameter and XOR requirementType-Level Enforcement
TypeScript users get compile-time safety:
Runtime Validation
JavaScript users get clear runtime errors:
Backwards Compatibility
Tests
Documentation