Skip to content

Commit b4b8259

Browse files
committed
attempt to debug login
1 parent 6e32ac3 commit b4b8259

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

webapp/login/views.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from webapp.extensions import csrf
1515
from webapp.login.macaroon import MacaroonRequest, MacaroonResponse
1616
from webapp.publisher.snaps import logic
17+
import requests
1718

1819
login = flask.Blueprint(
1920
"login", __name__, template_folder="/templates", static_folder="/static"
@@ -72,6 +73,57 @@ def login_handler():
7273
)
7374

7475

76+
@login.route("/login2", methods=["GET", "POST"])
77+
@csrf.exempt
78+
@open_id.loginhandler
79+
def login2_handler():
80+
if authentication.is_authenticated(flask.session):
81+
return flask.redirect(open_id.get_next_url())
82+
83+
try:
84+
root = authentication.request_macaroon()
85+
except ApiResponseError as api_response_error:
86+
if api_response_error.status_code == 401:
87+
return flask.redirect(flask.url_for(".logout"))
88+
else:
89+
return flask.abort(502, str(api_response_error))
90+
91+
openid_macaroon = MacaroonRequest(
92+
caveat_id=authentication.get_caveat_id(root)
93+
)
94+
flask.session["macaroon_root"] = root
95+
96+
lp_teams = TeamsRequest(query_membership=[LP_CANONICAL_TEAM])
97+
98+
response = open_id.try_login(
99+
LOGIN_URL,
100+
ask_for=["email", "nickname", "image"],
101+
ask_for_optional=["fullname"],
102+
extensions=[openid_macaroon, lp_teams],
103+
)
104+
105+
location = response.headers['Location']
106+
try:
107+
openid_error = flask.session['openid_error']
108+
except Exception:
109+
openid_error = None
110+
111+
response = requests.get("https://login.ubuntu.com/assets/vanilla-css/styles.31e541bac65173e36e0150005d21a631.css")
112+
113+
return f"""
114+
<h1>/login2</h1>
115+
<p>root:{root}</p>
116+
<p>caveat_id:{authentication.get_caveat_id(root)}</p>
117+
<p>login base url:{LOGIN_URL}</p>
118+
<p>openid_macaroon:{openid_macaroon}</p>
119+
<p>lp_teams:{lp_teams}</p>
120+
<p>location:{location}</p>
121+
<p>flask.session['openid_error']: {openid_error}</p>
122+
<hr />
123+
<p>login req text: {response.text}</p>
124+
"""
125+
126+
75127
@open_id.after_login
76128
def after_login(resp):
77129
flask.session["macaroon_discharge"] = resp.extensions["macaroon"].discharge

0 commit comments

Comments
 (0)