Smart123s / BeFake

BeReal Python API wrapper
The Unlicense
11 stars 3 forks source link

401 after some time #4

Closed clam0r closed 7 months ago

clam0r commented 8 months ago

Hi there,

first thanks a lot for keeping this project up and running!

Your last fix in https://github.com/NicoWeio/BeFake/tree/fix-auth did indeed work really well.

Unfourtunately after some time (seems to be only a couple of hours) the api throws 401 Unauthorized. After logging in again with the otp code everything works again for some time.

Error Message:

~/befake/BeFake $ python3 BeFake/befake.py me [16:24:23] DEBUG HTTP Request: POST https://securetoken.googleapis.com/v1/token?key=AIzaSyDwjfEeparokD7sXPVQli9NsTuhT6fJ6iA "HTTP/1.1 200 OK" _client.py:1016 [16:24:24] DEBUG HTTP Request: GET https://mobile.bereal.com/api/person/me "HTTP/1.1 401 Unauthorized" _client.py:1016 Traceback (most recent call last): File "/home/clamor/befake/BeFake/BeFake/befake.py", line 6, in <module> cli(obj={}) File "/home/clamor/.local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__ return self.main(*args, **kwargs) File "/home/clamor/.local/lib/python3.9/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/home/clamor/.local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/clamor/.local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/clamor/.local/lib/python3.9/site-packages/click/core.py", line 760, in invoke return __callback(*args, **kwargs) File "/home/clamor/befake/BeFake/BeFake/BeFake/__main__.py", line 36, in wrapper return func(bf, *args, **kwargs) File "/home/clamor/befake/BeFake/BeFake/BeFake/__main__.py", line 99, in me user = bf.get_user_info() File "/home/clamor/befake/BeFake/BeFake/BeFake/BeFake.py", line 416, in get_user_info res = self.api_request("get", "person/me") File "/home/clamor/befake/BeFake/BeFake/BeFake/BeFake.py", line 164, in api_request res.raise_for_status() File "/home/clamor/.local/lib/python3.9/site-packages/httpx/_models.py", line 736, in raise_for_status raise HTTPStatusError(message, request=request, response=self) httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://mobile.bereal.com/api/person/me' For more information check: https://httpstatuses.com/401

clam0r commented 8 months ago

It seems to me that the new firebase refresh token isnt propperly saved, thus after expiring the authentication fails.

Adding

self.grant_access_token() self.save()

to the end of def firebase_refresh_tokens(self) -> None: seems to work for me.

NicoWeio commented 8 months ago

If only I had seen this earlier (I wasn't pinged). :laughing: I managed to get it to work by reverting https://github.com/Smart123s/BeFake/commit/335ced752d30633a8c5cf346f30eca2301afb907, that is reinstating self.refresh_tokens(). No idea if that is appropriate and sustainable, so for now, I simply applied your proposal to my PR. Thanks!

Smart123s commented 7 months ago

I've rebased my fork on NicoWeio's master branch. I would generally recommend using his for though, as he's more active with updates and bug fixes. Thanks for your contributions!