ory / sdk

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

Python client expects scope to be int instead of str #220

Closed SavvasMohito closed 1 year ago

SavvasMohito commented 1 year ago

Preflight checklist

Describe the bug

Hello there.

Today I updated my ory_hydra_client python library and ory/hydra backend to version 2.0.1. After that, when trying to get a token using the OAuth2Api.oauth2_token_exchange(grant_type="client_credentials"), I am getting an error saying "Invalid type for variable 'scope'. Required value type is int and passed type was str at ['received_data']['scope']".

I looked into it and the issue seems to be here https://github.com/ory/sdk/blob/847fa4451dd67b624a2820402e92ec6385128921/clients/hydra/python/ory_hydra_client/model/o_auth2_token_exchange.py#L89 where the client expects to receive an integer for the scope field from the hydra server but instead it receives a string (as it should).

Performing the same flow with the same credentials through an HTTP call (using postman) works fine. The previous version of the library worked also fine for o_auth2_token() function. This looks like a typo to me.

I can provide my code but I don't think this is an issue caused by my config.

Reproducing the bug

Steps to reproduce:

  1. Have hydra server v2.0.1 running somewhere.
  2. Install ory_hydra_client v2.0.1 python library and setup the endpoints to hydra server.
  3. Create an oauth2 client (through the python library or HTTP request to hydra server).
  4. Try to perform the oauth 2 token flow using the OAuth2Api.oauth2_token_exchange() function of the ory_hydra_client library.
  5. You should get the same error as me.

Relevant log output

Traceback (most recent call last):
  File "/code/./app/routers/public.py", line 65, in request_access_token
    result = client.oauth2_token_exchange(grant_type="client_credentials").to_dict()
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/api/o_auth2_api.py", line 3057, in oauth2_token_exchange
    return self.oauth2_token_exchange_endpoint.call_with_http_info(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/api_client.py", line 880, in call_with_http_info
    return self.api_client.call_api(
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/api_client.py", line 422, in call_api
    return self.__call_api(resource_path, method,
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/api_client.py", line 227, in __call_api
    return_data = self.deserialize(
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/api_client.py", line 333, in deserialize
    deserialized_data = validate_and_convert_types(
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 1583, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 1472, in attempt_convert_item
    raise conversion_exc
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 1463, in attempt_convert_item
    return deserialize_model(input_value, valid_class,
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 1377, in deserialize_model
    return model_class._new_from_openapi_data(**kw_args)
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 49, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 372, in _new_from_openapi_data
    return cls._from_openapi_data(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 49, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model/o_auth2_token_exchange.py", line 192, in _from_openapi_data
    setattr(self, var_name, var_value)
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 190, in __setattr__
    self[attr] = value
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 511, in __setitem__
    self.set_attribute(name, value)
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 162, in set_attribute
    value = validate_and_convert_types(
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 1583, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/usr/local/lib/python3.10/site-packages/ory_hydra_client/model_utils.py", line 1458, in attempt_convert_item
    raise get_type_error(input_value, path_to_item, valid_classes,
ory_hydra_client.exceptions.ApiTypeError: Invalid type for variable 'scope'. Required value type is int and passed type was str at ['received_data']['scope']

Relevant configuration

hydra:
    image: oryd/hydra:v2.0.1
    container_name: hydra
    ports:
      - "4444:4444" # Public port
      - "4445:4445" # Admin port
      - "5555:5555" # Port for hydra token user
    command: serve -c /etc/config/hydra/hydra.yml all --dev
    volumes:
      - type: bind
        source: ./config/hydra
        target: /etc/config/hydra
    environment:
      - DSN=mysql://root:secret@tcp(mysql-admin:3306)/mysql?max_conns=20&max_idle_conns=4
      - HYDRA_URL=http://localhost:4445
    restart: unless-stopped
    depends_on:
      - hydra-migrate
  hydra-migrate:
    container_name: hydra-migrate
    image: oryd/hydra:v2.0.1
    environment:
      - DSN=mysql://root:secret@tcp(mysql-admin:3306)/mysql?max_conns=20&max_idle_conns=4
    command: migrate -c /etc/config/hydra/hydra.yml sql -e --yes
    volumes:
      - type: bind
        source: ./config/hydra
        target: /etc/config/hydra
    restart: on-failure
    depends_on:
      - mysql-admin

Version

2.0.1

On which operating system are you observing this issue?

Linux

In which environment are you deploying?

Docker Compose

Additional Context

No response

aeneasr commented 1 year ago

That’s very strange, thank you for the report!

SavvasMohito commented 1 year ago

Hi @aeneasr, as you can see I have now created PR #223 with the necessary change to fix this issue. I have tested it locally with my project and I can confirm it works as expected. 🙂

SavvasMohito commented 1 year ago

Fixed in https://github.com/ory/hydra/pull/3337. Hopefully the clients will function properly once re-generated.