ory / sdk

The place where ORY's SDKs are being auto-generated
Apache License 2.0
141 stars 85 forks source link

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

Open anichrelay-bloom opened 2 months ago

anichrelay-bloom commented 2 months ago

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

aeneasr commented 2 months ago

Thank you for the report, can you please try with a newer version of the SDK?

anichrelay-bloom commented 2 months ago

Thank you for the report, can you please try with a newer version of the SDK?

I believe I am seeing this error on the latest version, I did not specify any version while doing pip install

aeneasr commented 2 months ago

In your issue it says:

Version

v0.0.54

anichrelay-bloom commented 2 months ago

I mentioned the latest release tag I saw for ory/sdk on github. Updated the issue with ory-client version I am using.