Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular 401 Unauthorized's #395

Open
fredericvl opened this issue Jul 29, 2023 · 4 comments
Open

Regular 401 Unauthorized's #395

fredericvl opened this issue Jul 29, 2023 · 4 comments

Comments

@fredericvl
Copy link

I want to share some insights that seems to be odd behaviour to me.
It looks like TGTG is invalidating access tokens at random times and then it results into a 401 Unauthorized error when calling the item/v8 url.
This causes the scanner to not work until the refresh time period is reached.
Because I was intrigued to know what the official TGTG app did in such case I set up Proxyman for iOS to intercept the traffic between my TGTG app & their API.
It looks like the tokens of the official app are also invalidated at some times and they return a 401 Unauthorized but they immediately call the refresh token URL after that and then use the new token which then works fine.

Would it be an idea to also refresh the token when the API returns 401 Unauthorized and when a valid token is already present in the scanner?

Just as a reference how often this happens, it is a lot to me:
tgtg-scanner.log

@floriegl
Copy link
Contributor

floriegl commented Aug 3, 2023

Such a problem never occurred for me. It would be possible to add such a behavior but in the meantime you can reduce AccessTokenLifetime as a workaround. I f.e. have mine set to 1800 just be on the safe side. You can check https://github.com/Der-Henning/tgtg/wiki/Configuration on how to configure that in your setup. I don't know what exactly is going wrong on your end, but your logs imply that pretty much after one hour the RefreshToken gets invalidated. Maybe try setting the AccessTokenLifetime to 3600 or enabling Debug in the configuration to check if you are not sending too many requests…

@fredericvl
Copy link
Author

The access token lifetime was already set to one hour (3600) with the provided log file, so it actually got invalidated immediately.
I now configured the lifetime to only 55 seconds, forcing it to get a new token each API call and even then I still sometimes get invalidated tokens (but at least it starts to work again after one or two minutes):
tgtgscanner.log

Regarding debug logging, I enabled it once before and it doesn't reveal any useful information except for the 401 Unauthorized (so no 429 ratelimit status code or 403 forbidden status code).

Anyways, I have a workaround so this is not urgent to me but I think it would be a great improvement to handle these regular unauthorized's in the same way that the official TGTG app does.
I also find it pretty odd that no one else experienced similar issues...

@floriegl
Copy link
Contributor

floriegl commented Aug 3, 2023

Wait… could this issue be that you have your AccessTokenLifetime set to short? Maybe you get invalid AccessTokenLifetime because your interval is set too short. Did you start with a AccessTokenLifetime when using this project or did you switch to it because you already got 401 a lot?

@fredericvl
Copy link
Author

I started with the default access token lifetime, which is set to 4 hours if I remember correctly but even then I got the 401's and tried a shorter lifetime of 1 hour and eventually 55 seconds to get the best results in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants