|
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,62 @@ 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 | + |
| 112 | + try: |
| 113 | + response = requests.get("https://login.ubuntu.com/assets/vanilla-css/styles.31e541bac65173e36e0150005d21a631.css") |
| 114 | + response = response.text |
| 115 | + except Exception as e: |
| 116 | + response = e |
| 117 | + |
| 118 | + return f""" |
| 119 | + <h1>/login2</h1> |
| 120 | + <p>root:{root}</p> |
| 121 | + <p>caveat_id:{authentication.get_caveat_id(root)}</p> |
| 122 | + <p>login base url:{LOGIN_URL}</p> |
| 123 | + <p>openid_macaroon:{openid_macaroon}</p> |
| 124 | + <p>lp_teams:{lp_teams}</p> |
| 125 | + <p>location:{location}</p> |
| 126 | + <p>flask.session['openid_error']: {openid_error}</p> |
| 127 | + <hr /> |
| 128 | + <p>login req text: {response}</p> |
| 129 | + """ |
| 130 | + |
| 131 | + |
75 | 132 | @open_id.after_login |
76 | 133 | def after_login(resp): |
77 | 134 | flask.session["macaroon_discharge"] = resp.extensions["macaroon"].discharge |
|
0 commit comments