Open alhuede-thncs opened 2 years ago
I feel your pain. I am also trying to get this working with Django and requests_oauthlib.
To make things worse the Flask examples all have a root/file level session, but in Django the session only exists inside the view request.session. This means the session is not accessible inside the functions oauth2_token_getter or oauth2_token_saver which the xero_python SDK calls internally.
I'm not sure if there is a way to have this actually work with Django, which would seems improbable given Django's popularity as a/the major production python framework, but I can't find any Django examples online official or otherwise.
I feel your pain. I am also trying to get this working with Django and requests_oauthlib.
To make things worse the Flask examples all have a root/file level session, but in Django the session only exists inside the view request.session. This means the session is not accessible inside the functions oauth2_token_getter or oauth2_token_saver which the xero_python SDK calls internally.
I'm not sure if there is a way to have this actually work with Django, which would seems improbable given Django's popularity as a/the major production python framework, but I can't find any Django examples online official or otherwise.
Levitybot,
I am sorry to hear you are suffering from the same issues. However I have some insight into how to remedy the situation, even if it is not complete. I have not had the strict business requirement of completely solving this problem myself yet so I have let it go for the meantime, however I have come across some things that may be very helpful to you.
There are a couple of quirks with how Django works with the xero api and how things are constructed in the Flask examples that are worth noting. It would be difficult to explain everything here in text form, but for the sake of future readers is is probably worthwhile that I do so.
I think the best thing I could do is provide an actual working Django example, however at this point I am not 100% sure it will work as I am currently using the custom connections API.
In regards to the oauth_token_setter and getter not being able to access any data in the django sessions, I actually solved this by binding a parameter to the getter and setter function using pythons 'functools partial' function. When storing the getter / setter, I bind parameters to the functions that give the required context to the getter and setter to retrieve and store the correct xero token.
https://docs.python.org/3/library/functools.html -> look for the function 'partial'
If you would like me to try and create a Django example that replicates what the Flask examples are providing, I can spend some time over the weekend to try and make that happen.
Looking forward to hearing from you!
I feel your pain. I am also trying to get this working with Django and requests_oauthlib.
To make things worse the Flask examples all have a root/file level session, but in Django the session only exists inside the view request.session. This means the session is not accessible inside the functions oauth2_token_getter or oauth2_token_saver which the xero_python SDK calls internally.
I'm not sure if there is a way to have this actually work with Django, which would seems improbable given Django's popularity as a/the major production python framework, but I can't find any Django examples online official or otherwise.
also sorry, I am the same user as 'alhuede-thncs', I have multiple github accounts, I didnt look at which one I was posting from
I also feel the pain. I'm trying to get this working with FastAPI...But blocked by the Oauth2 for2 weeks.
Hello,
I am developing a django application that interacts with the Xero API. Your example applications are extremely useful, however as someone who has never used flask before, I have had a very difficult time picking apart the application and replacing flask specific code with more generic libraries.
Specifically, the flask_oauthlib related code has been very annoying to deal with. I am attempting to replace it with requests_oauthlib, however not having extensive background in python or using oauth libraries like this, it has been quite painful.
It would be really appreciated if in your sample applications you did not tie so much to the framework you are using, so the code can be translated more easily to other frameworks. I have not found any library that provides an interface similar to flask_oauthlib in terms of providing an api client that will accept the authorization / access token / refresh token url and provide automatic refreshing of the token for you.
Normally integrating something like this would take a very minimal amount of time, however I am finding myself spending hours making sure the token fetching and refreshing is happening correctly. An example of how to do this 'framework agnostic' would be extremely helpful.
Thanks for reading.