user3525290
user3525290

Reputation: 1619

Python flask azure google auth fails

I created a flask app and deployed it to azure web services. The authorized redirect is https https://testapp.azurewebsites.net/google_login/callback/ The error I am getting

oauthlib.oauth2.rfc6749.errors.InsecureTransportError: (insecure_transport) OAuth 2 MUST utilize https.
"GET /google_login/callback/?state=<code>&code=<code>&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid&authuser=0&prompt=none HTTP/1.1" 500 265 "https://accounts.google.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0"

Everything works on development and using 127.0.0.1:5005/google_login/callback/ as my callback but in azure it breaks.

Upvotes: 0

Views: 51

Answers (1)

user3525290
user3525290

Reputation: 1619

I am not sure, why it happens in azure but https gets stripped from request.url. The response that comes back from google is not providing https or python or azure is somehow stripping. During production I wrote a regex to add it back to request.url.

pattern = re.compile(r"^http://testapp")
results = pattern.search(request.url)

if results:
    request.url = re.sub('http://testapp','https://testapp',request.url)

Upvotes: 0

Related Questions