ory / ory/sdk

OAuth2 Clients: Error in Fetching Clients due to Lifespan fields throwing validation errors

Open
#376 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
178
Forks
96
Avg merge
6d 23h
Merged PRs (30d)
3

Description

Preflight checklist
Ory Network Project

https://elated-johnson-lfg0voad5z.projects.oryapis.com

Describe the bug

I am able to successfully create auth2 clients using Ory REST API by setting these two lifespan fields for OAuth2 clients:

"client_credentials_grant_access_token_lifespan": "720h",
"jwt_bearer_grant_access_token_lifespan": "720h",

I am able to fetch the client using the REST endpoint, it returns these two values as:

    "client_credentials_grant_access_token_lifespan": "720h0m0s",
    "jwt_bearer_grant_access_token_lifespan": "720h0m0s",

But it throws exception when I try to create or list existing Oauth2 clients using Python SDK:

ValidationError: 2 validation errors for OAuth2Client
client_credentials_grant_access_token_lifespan
  Value error, must validate the regular expression /^[0-9]+(ns|us|ms|s|m|h)$/ [type=value_error, input_value='720h0m0s', input_type=str]
    For further information visit https://errors.pydantic.dev/2.9/v/value_error
jwt_bearer_grant_access_token_lifespan
  Value error, must validate the regular expression /^[0-9]+(ns|us|ms|s|m|h)$/ [type=value_error, input_value='720h0m0s', input_type=str]
    For further information visit https://errors.pydantic.dev/2.9/v/value_error
Reproducing the bug
  1. Create M2M Client with OAuth2Client as:
ory_client.OAuth2Client(
        client_name=client_name,
        grant_types=["client_credentials"],
        response_types=["token"],
        access_token_strategy="jwt",
        skip_consent=True,
        audience=["dev-audience"],
        scope="read:all",
        token_endpoint_auth_method="client_secret_post",
        token_endpoint_auth_signing_alg="RS256",
        jwt_bearer_grant_access_token_lifespan="720h",
        client_credentials_grant_access_token_lifespan="720h",
    )
    
    api_response = api_instance.create_o_auth2_client(m2m_client)
Relevant log output
Exception when calling OAuth2Api->list_o_auth2_clients: 2 validation errors for OAuth2Client
client_credentials_grant_access_token_lifespan
  Value error, must validate the regular expression /^[0-9]+(ns|us|ms|s|m|h)$/ [type=value_error, input_value='720h0m0s', input_type=str]
    For further information visit https://errors.pydantic.dev/2.9/v/value_error
jwt_bearer_grant_access_token_lifespan
  Value error, must validate the regular expression /^[0-9]+(ns|us|ms|s|m|h)$/ [type=value_error, input_value='720h0m0s', input_type=str]
Relevant configuration

No response

Version

v1.12.2

On which operating system are you observing this issue?

None

In which environment are you deploying?

None

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python SDK's OAuth2Client model and its validation for client_credentials_grant_access_token_lifespan and jwt_bearer_grant_access_token_lifespan. Reproduce the issue with list_o_auth2_clients and the shown 720h configuration, then verify that the REST response value 720h0m0s is accepted without validation errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.