|
14 | 14 | from webapp.extensions import csrf |
15 | 15 | from webapp.login.macaroon import MacaroonRequest, MacaroonResponse |
16 | 16 | from webapp.publisher.snaps import logic |
| 17 | +import requests |
17 | 18 |
|
18 | 19 | login = flask.Blueprint( |
19 | 20 | "login", __name__, template_folder="/templates", static_folder="/static" |
@@ -72,6 +73,57 @@ def login_handler(): |
72 | 73 | ) |
73 | 74 |
|
74 | 75 |
|
| 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(LOGIN_URL) |
| 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 | + |
75 | 127 | @open_id.after_login |
76 | 128 | def after_login(resp): |
77 | 129 | flask.session["macaroon_discharge"] = resp.extensions["macaroon"].discharge |
|
0 commit comments