__name__, template_folder="/templates", static_folder="/static") LOGIN_URL = os.getenv("LOGIN_URL", "https://login.ubuntu.com") LP_CANONICAL_TEAM = "canonical" open_id = OpenID( store_factory=lambda: None, safe_roots=[], extension_responses=[MacaroonResponse, TeamsResponse], ) publisher_api = SnapPublisher(api_publisher_session) candid = CandidClient(api_publisher_session) @login.route("/login", methods=["GET", "POST"]) @csrf.exempt @open_id.loginhandler def login_handler(): if authentication.is_authenticated(flask.session): return flask.redirect(open_id.get_next_url()) try: root = authentication.request_macaroon() except ApiResponseError as api_response_error: if api_response_error.status_code == 401: return flask.redirect(flask.url_for(".logout")) else:
from canonicalwebteam.candid import CandidClient from webapp.helpers import is_safe_url from webapp import authentication login = flask.Blueprint( "login", __name__, template_folder="/templates", static_folder="/static" ) LOGIN_URL = os.getenv("LOGIN_URL", "https://login.ubuntu.com") LOGIN_LAUNCHPAD_TEAM = os.getenv( "LOGIN_LAUNCHPAD_TEAM", "canonical-webmonkeys" ) request_session = talisker.requests.get_session() candid = CandidClient(request_session) publisher_api = CharmPublisher(request_session) @login.route("/logout") def logout(): authentication.empty_session(flask.session) return flask.redirect("/") @login.route("/login/") def publisher_login(): # Get a bakery v2 macaroon from the publisher API to be discharged # and save it in the session flask.session["publisher-macaroon"] = publisher_api.get_macaroon()