Can't run OAuth in Python / Flask without manually asking for the code?

I want to create a Rule-Action app that updates some custom project metrics every time a task is completed. I already tested the Python script on a single project using a PAT, but now I need to use OAuth to make it accessible to everyone at the office.

The main problem is that I have no idea of how to automatically get the code to fetch a token after the user logged in. When I do it mannualy (enter the URL > get redirected > get the code) the code works as a charm. But as soon as I try to make it work in Flask/PythonEverywhere to make it accessible through a rule, things don’t work and I can’t seen to find a solution around here. I already saw some people finding similar barriers 4 years ago (OAuth avoid user interaction?) but without actually getting to a real solution.

So far, I tried using requests and requests-oauthlib, but when I get to the point where I need to get the code back from the user, I have no idea of how to properly proceed, as requests.get won’t redirect the URL to the post-login URL. Any help? Am I missing something that is obvious?

Thanks in advance!

When creating a custom code for an Action in Rule, you have to understand that your user will go through an OAuth process when installing this action. It means you need to store that code along with the user gid. Then every time the rule runs and calls your server, you need to get the code (or more likely the refresh token) from your own database to generate a new authorization code and run your piece of code.

Does it help? @Phil_Seeman is what I am saying correct?


Hi Bastien,

You rocked, I wasn’t understanding properly how to work with the OAuth workflow using Flask, found some useful code and advice from this blog: OAuth Authentication with Flask in 2023, and they more or less tell how to setup what you suggested.

Have to keep working on the Rule-Action stuff now, but this part of OAuth stuff was driving me crazy.


OAuth is the hardest thing I had to deal with in the last years as a developer. Took me a long while to really understand how it works. @Anthony_Lines can testify, he went through the same thing recently!

1 Like