fix: Align AccessPolicyConstraint methods / types enums with actual API casing#553
Open
BinoyOza-okta wants to merge 1 commit into
Open
fix: Align AccessPolicyConstraint methods / types enums with actual API casing#553BinoyOza-okta wants to merge 1 commit into
methods / types enums with actual API casing#553BinoyOza-okta wants to merge 1 commit into
Conversation
… casing
This commit fixes Pydantic deserialization failures on `PolicyApi.list_policy_rules()` (GET `/api/v1/policies/{policyId}/rules`) when an access policy rule's `constraints[]` contains lowercase `methods` or `types` values (e.g. `"password"`, `"push"`, `"webauthn"`).
Problem:
- The Okta API returns `methods` and `types` constraint values in lowercase (e.g. `"types": ["password"]`, `"methods": ["push"]`), but the OpenAPI spec defined the corresponding enums as UPPERCASE-only (`PASSWORD`, `PUSH`, `WEBAUTHN`, ...).
- Generated Pydantic validators rejected the real API payload with: each list item must be one of ('PASSWORD', 'SECURITY_QUESTION', 'SMS', 'VOICE', 'EMAIL', 'PUSH', 'SIGNED_NONCE', 'OTP', 'TOTP', 'WEBAUTHN', 'DUO', 'IDP', 'CERT')
- This broke `list_policy_rules()` for any access policy whose rules carry `KnowledgeConstraint` / `PossessionConstraint` / base `AccessPolicyConstraint` blocks (i.e. most modern authentication policies).
Root Cause:
- Enum case mismatch between the OAS3 spec and the live API response for `AccessPolicyConstraint.methods[]` and `AccessPolicyConstraint.types[]` (inherited by `KnowledgeConstraint` and `PossessionConstraint`).
Solution:
1. Updated `openapi/api.yaml` to redefine both enums in lowercase to match what the API actually returns:
- `methods[]`: password, security_question, sms, voice, email, push, signed_nonce, otp, totp, webauthn, duo, idp, cert
- `types[]`: security_key, phone, email, password, security_question, app, federated
2. Regenerated the affected models so their `field_validator` allow-lists and error messages reflect the lowercase values:
- `okta/models/access_policy_constraint.py`
- `okta/models/knowledge_constraint.py`
- `okta/models/possession_constraint.py`
Testing:
- Verified against a live Okta org with an access policy whose knowledge constraint contains `"types": ["password"]`. `client.list_policy_rules(policy_id)` now returns the full rule list without raising `ValidationError`, and `constraints[].knowledge.types` deserializes cleanly.
- All three regenerated models accept the lowercase values; no other factor / policy code paths were touched.
Backward Compatibility:
- This is a wire-format alignment fix: previously the SDK could not parse real API responses at all, so no existing successful call is affected. Callers constructing constraints client-side must now use lowercase values (matching API behavior).
Fixes: OKTA-1172239
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: Align AccessPolicyConstraint
methods/typesenums with actual API casingSummary
Fixes Pydantic
ValidationErrorraised byPolicyApi.list_policy_rules()(GET/api/v1/policies/{policyId}/rules)when an access policy rule contains lowercase
methodsortypesvalues inside itsconstraints[]block.The Okta API returns these values in lowercase (e.g.
"password","push","webauthn"), but the OpenAPI spec defined the enums as UPPERCASE-only, causing every modern authentication policy rule to fail deserialization.Problem
Calling
list_policy_rules()against a policy whose rules carry aKnowledgeConstraint(orPossessionConstraint, or baseAccessPolicyConstraint) raised:Root Cause
Enum case mismatch between the OAS3 spec (
policies.yaml→openapi/api.yaml) and the live API response for:AccessPolicyConstraint.methods[]AccessPolicyConstraint.types[]KnowledgeConstraintandPossessionConstraintinherit the same field definitions, so all three generated Pydantic models carried the incorrect UPPERCASE allow-list.Solution
Per the JIRA's chosen resolution ("Update the OpenAPI spec to define enums as lowercase (matching what the API actually returns)"):
1. OpenAPI spec (
openapi/api.yaml)Redefined both enums in lowercase to mirror the API contract:
methods[]:password,security_question,sms,voice,email,push,signed_nonce,otp,totp,webauthn,duo,idp,certtypes[]:security_key,phone,email,password,security_question,app,federated2. Regenerated models
The three affected Pydantic v2 models had their
field_validatorallow-lists and error messages regenerated to lowercase:
okta/models/access_policy_constraint.pyokta/models/knowledge_constraint.pyokta/models/possession_constraint.pyNo model class names, field names, or method signatures changed — only the contents of the validator sets and the corresponding
ValueErrormessages.Files Changed
openapi/api.yamlmethods/typesenums → lowercase onAccessPolicyConstraint,KnowledgeConstraint,PossessionConstraintokta/models/access_policy_constraint.pyokta/models/knowledge_constraint.pyokta/models/possession_constraint.pyTesting
"types": ["password"].client.list_policy_rules(policy_id)now returns the full rule list without raisingValidationError, and the lowercase values deserialize cleanly intoKnowledgeConstraint.types.methodsvalues such as"push","webauthn", and"signed_nonce"are also accepted post-fix.tests/continue to pass.Backward Compatibility
This is a wire-format alignment fix. Before this change the SDK could not deserialize real API responses for affected policies at all, so no previously-working call is broken.
AccessPolicyConstraint/KnowledgeConstraint/PossessionConstraintobjects on the client side must now supply the constraint values in lowercase (e.g.types=["password"]rather thantypes=["PASSWORD"]). This matches the casing the API itself uses on both request and response.Related
GET /api/v1/policies/{policyId}/rules(
PolicyApi.list_policy_rules)openapi/api.yamland regenerates the affected models.