nxtlo / aiobungie

Python and asyncio Bungie API wrapper.
https://nxtlo.github.io/aiobungie/
MIT License
52 stars 10 forks source link

Refresh access token gives a bad request: "cannot parse client_id" #318

Closed MagneticZer0 closed 11 months ago

MagneticZer0 commented 11 months ago

Bad request returned for refresh_access_token method

After the most recent update, v0.2.9, I am no longer able to use the above method to refresh an access token as it returns a Bad Request due to not being able to parse the client_id. This same code worked in a previous version, specifically revision 8a62a05c1606e19f388ba049f089e747e0e0328d (may work in a later one, I just know that it at least works in this one as I've reverted back to it)

Below is a stacktrace

import asyncio
import aiobungie
import os
bungie_client_pool = aiobungie.RESTPool(os.getenv("DESTINY_TOKEN"), client_id=int(os.getenv("DESTINY_OAUTH_CLIENT_ID")), client_secret=os.getenv("DESTINY_SECRET"))
async with bungie_client_pool.acquire() as client:
    tokens = await client.refresh_access_token(<refresh token>)
    print(tokens)

Traceback (most recent call last):
  File "...Python\Python311\Lib\concurrent\futures\_base.py", line 456, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "...Python\Python311\Lib\concurrent\futures\_base.py", line 401, in __get_result
    raise self._exception
  File "<console>", line 2, in <module>
  File "...pypoetry\Cache\virtualenvs\lmp3z72L-py3.11\Lib\site-packages\aiobungie\rest.py", line 678, in refresh_access_token
    response = await self._request(RequestMethod.POST, "", json=data, oauth2=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "...pypoetry\Cache\virtualenvs\lmp3z72L-py3.11\Lib\site-packages\aiobungie\rest.py", line 585, in _request
    raise await error.raise_error(response)
aiobungie.error.BadRequest: ('UNDEFINED_MESSAGE', 'https://www.bungie.net/Platform/App/OAuth/token/', {'error': 'invalid_request', 'error_description': 'Cannot parse client_id'}, ...

Platform + aiobungie(version) Info

Windows 11, Python 3.11, aiobungie tag 0.2.9 installed via poetry

Not entirely sure what the issue is, but I noticed that there was a change in the refresh access token method. The data parameter used to be passed in via the data kwarg to the _request method and in the latest update it is now passed in via the json kwarg. Not sure if this is related as there does seem to be some additional logic added to the _request method but I haven't had the time to comb it over just yet myself.

nxtlo commented 11 months ago

Not entirely sure what the issue is, but I noticed that there was a change in the refresh access token method. The data parameter used to be passed in via the data kwarg to the _request method and in the latest update it is now passed in via the json kwarg.

This is indeed why, will fix this ASAP.

nxtlo commented 11 months ago

0.2.10 is now released on pypi which fixes this bug, Thanks for reporting; o7.