auth0 / auth0-python

Auth0 SDK for Python
https://auth0-python.readthedocs.io
MIT License
506 stars 164 forks source link

API management call and headers like X-Correlation-ID #529

Open a-marcellini opened 11 months ago

a-marcellini commented 11 months ago

Checklist

Describe the problem you'd like to have solved

Hi all, I need to specify X-Correlation-ID header in every management call, however, despite the fact that the low-level RestClient api allow to specify any request-header, the high-level ones don't. As an example in users lib the method to get a user is:

    def get(
        self, id: str, fields: List[str] | None = None, include_fields: bool = True
    ) -> dict[str, Any]:
        """Get a user.

        Args:
            id (str): The user_id of the user to retrieve.

            fields (list of str, optional): A list of fields to include or
                exclude from the result (depending on include_fields). Leave empty to
                retrieve all fields.

            include_fields (bool, optional): True if the fields specified are
                to be included in the result, False otherwise. Defaults to True.

        See: https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id
        """
        params = {
            "fields": fields and ",".join(fields) or None,
            "include_fields": str(include_fields).lower(),
        }

        return self.client.get(self._url(id), params=params)

That doesn't allow to specify any request parameter.

Describe the ideal solution

What about change all the method signatures specifying an optional last parameter with the request_headers like this:

def get(
        self, id: str, fields: List[str] | None = None, include_fields: bool = True, request_headers: dict = None
    ) -> dict[str, Any]:

  ...

  return self.client.get(self._url(id), params=params, headers=request_headers)

Alternatives and current workarounds

No response

Additional context

No response

adamjmcgrath commented 11 months ago

Thanks for raising this @a-marcellini - i'll review your request and get back to you

adamjmcgrath commented 11 months ago

Hi @a-marcellini - we can do this, but I can't give you a timeline. You're welcome to offer a PR in the meantime, or wait for us to schedule it in.

aleksandr-vin commented 8 months ago

Came here with same request :)