Skip to content

Commit 5f36c5d

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

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

webapp/login/views.py

Lines changed: 48 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,53 @@ 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+
return f"""
112+
<html>
113+
<head>
114+
<meta http-equiv="refresh" content="0; url={location}">
115+
</head>
116+
<body>
117+
<h1>Redirecting you to Ubuntu One login...</h1>
118+
</body>
119+
</html>
120+
"""
121+
122+
75123
@open_id.after_login
76124
def after_login(resp):
77125
flask.session["macaroon_discharge"] = resp.extensions["macaroon"].discharge

0 commit comments

Comments
 (0)