Good day.
I have a problem with flask-dance, using github oauth. This is my code:
from flask import Flask, redirect, url_for
from flask_dance.contrib.github import make_github_blueprint, github
app = Flask(__name__)
app.secret_key = "supersekrit6546ihugf98779"
blueprint = make_github_blueprint(
client_id="9f5534a3e8dd8a7f612b",
client_secret="c91568077277c22cf44e095952b96f4250524a7b",
)
app.register_blueprint(blueprint, url_prefix="/auth")
@app.route("/")
def index():
if not github.authorized:
return redirect(url_for("github.login"))
resp = github.get("/user")
assert resp.ok
return "You are @{login} on GitHub".format(login=resp.json()["login"])
The github blueprint register two endpoints:
GET /auth/github/
GET /auth/github/authorized/
This occurs internally, the problem is, in this simple setup, the GET /auth/github/
endpoint returns a 404 not found error. this was functioning very well, but during development y make a mistake and create something like a recursive loop or something like that:
127.0.0.1 - - [26/Dec/2019 01:09:24] "GET /github/ HTTP/1.1" 302 -
127.0.0.1 - - [26/Dec/2019 01:09:24] "GET /auth/github/ HTTP/1.1" 404 -
127.0.0.1 - - [26/Dec/2019 01:09:36] "GET /github/ HTTP/1.1" 302 -
127.0.0.1 - - [26/Dec/2019 01:09:36] "GET /auth/github/ HTTP/1.1" 404 -
127.0.0.1 - - [26/Dec/2019 01:10:07] "GET /github/ HTTP/1.1" 302 -
127.0.0.1 - - [26/Dec/2019 01:10:07] "GET /auth/github/ HTTP/1.1" 404 -
This happen once, when trying to test the login, the flask app spit all that log at once, a total of three request. from that point to here, my flask app never works again and instead of the normal flow:
127.0.0.1 - - [26/Dec/2019 00:13:24] "GET /github/ HTTP/1.1" 302 -
127.0.0.1 - - [26/Dec/2019 00:13:24] "GET /auth/github HTTP/1.1" 302 -
127.0.0.1 - - [26/Dec/2019 00:13:29] "GET /auth/github/authorized?code=4f89165770b11a7adbf0&state=M1M7ImawYggug4Vz98B49nYmvEwOpc HTTP/1.1" 302 -
i get this flow:
127.0.0.1 - - [26/Dec/2019 01:11:27] "GET /github/ HTTP/1.1" 302 -
127.0.0.1 - - [26/Dec/2019 01:11:27] "GET /auth/github/ HTTP/1.1" 404 -
Please dont let yourself guide by the mismatching client ids of the github oauth apps, i change all that ones in the test for try to fix this, but instead take the general flow of the login process: login route -> flask-dance login route -> flask-dance login route with args for GitHub to work. Also y reduce the app to the minimum, in fact this is the flask dance example code for getting started, so the endpoints in the logs dont match.
This is strange, because when i print app.url_map i get all correctly:
Map([
<Rule '/auth/github/authorized' (GET, OPTIONS, HEAD) -> github.authorized>,
<Rule '/auth/github' (GET, OPTIONS, HEAD) -> github.login>,
<Rule '/' (GET, OPTIONS, HEAD) -> index>,
<Rule '/static/<filename>' (GET, OPTIONS, HEAD) -> static>
])
as you can see, "/" is the login entry point in this test app.
I have a main app currently under development, and this also happen there, i first think in something like a ban from github, so i delete the github oauth app and create a new one but that dont solve the problem. I still think some type of ban was applied to me, but im not sure if my toughs are correctly. Maybe the ban was applied to my IP but not sure too, cant test outside my network.
The app starts working, but im not sure why. So this is not any type of ban, just my ignorance.