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

Subsequent Auth Fails with Token #11

Open
NimishVerma opened this issue Jan 24, 2021 · 4 comments
Open

Subsequent Auth Fails with Token #11

NimishVerma opened this issue Jan 24, 2021 · 4 comments

Comments

@NimishVerma
Copy link

Hi Tom,

Neat project. I noticed something weird. I am using a FastAPI app, in my app.py I always make a connection and instantiate the Q object (= Questrade(refresh_token='XX') ).
The first time I run the code it works fine, and a restart causes 400 bad requests. It only works if I change the refresh token from the dashboard or have Q = Questrade() (without the refresh token).

I figure this might be an issue with the API maybe.

@kerouac01850
Copy link

This code works fine BUT you must authenticate with the token first and only once. Thereafter use the cached OAuth credentials.

@momelod
Copy link

momelod commented Mar 20, 2021

I'm running into the same issue. How can we validate if the access_token in ~/.questrade.json is still valid and if not use the refresh_token to get a new access_token

@kerouac01850
Copy link

I admit that managing the life cycle is not intuitive. You can check my fork of this repository to see where I added some behavior that removes OAuth state caching from the file system. Also look at my Python Connection class to see how it handles the API logic. For my application I didn't want files lying around that had valid OAuth credentials.

Possibly another way to do this without any modification of the API is to generate a new token and immediately delete ~/.questrade.json. Use the presence of ~/.questrade.json as a discriminant to figure out if the connection needs a token parameter.

@RuslanBergenov
Copy link

I would just do this:

try:
    q = Questrade(refresh_token=refresh_token)
except Exception as e:
    print(e)
    q = Questrade()

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

4 participants