Exemplo n.º 1
0
def login_handler():
    is_test_backend = flask.request.args.get("test_backend", False)

    api_url = flask.current_app.config["CONTRACTS_LIVE_API_URL"]

    if is_test_backend:
        api_url = flask.current_app.config["CONTRACTS_TEST_API_URL"]

    if user_info(flask.session):
        return flask.redirect(open_id.get_next_url())

    response = session.request(method="get",
                               url=f"{api_url}/v1/canonical-sso-macaroon")
    flask.session["macaroon_root"] = response.json()["macaroon"]

    for caveat in Macaroon.deserialize(
            flask.session["macaroon_root"]).third_party_caveats():
        if caveat.location == "login.ubuntu.com":
            openid_macaroon = MacaroonRequest(caveat_id=caveat.caveat_id)
            break

    return open_id.try_login(
        flask.current_app.config["CANONICAL_LOGIN_URL"],
        ask_for=["email", "nickname", "image"],
        ask_for_optional=["fullname"],
        extensions=[openid_macaroon],
    )
Exemplo n.º 2
0
def login_handler():
    if "openid" in flask.session and "macaroon_root" in flask.session:
        return flask.redirect(open_id.get_next_url())

    root = request_macaroon()
    token = root["metadata"]["token"]
    location = urlparse(LOGIN_URL).hostname
    (caveat, ) = [
        c for c in Macaroon.deserialize(token).third_party_caveats()
        if c.location == location
    ]
    openid_macaroon = MacaroonRequest(caveat_id=caveat.caveat_id)

    flask.session["macaroon_root"] = token
    return open_id.try_login(LOGIN_URL,
                             ask_for=["email"],
                             extensions=[openid_macaroon])
Exemplo n.º 3
0
def login_handler():
    if "authentication_token" in flask.session:
        return flask.redirect(open_id.get_next_url())
    flask.session["invitation_code"] = request.args.get("invitation_code")
    response = _api_request(url_path="/1.0/token",
                            method="GET",
                            params={"provider": "usso"})
    root = response["metadata"]["token"]
    location = urlparse(LOGIN_URL).hostname
    (caveat, ) = [
        c for c in Macaroon.deserialize(root).third_party_caveats()
        if c.location == location
    ]
    openid_macaroon = MacaroonRequest(caveat_id=caveat.caveat_id)

    flask.session["macaroon_root"] = root
    return open_id.try_login(LOGIN_URL,
                             ask_for=["email"],
                             extensions=[openid_macaroon])
Exemplo n.º 4
0
def login_handler():
    if auth.is_authenticated(flask.session):
        return flask.redirect(open_id.get_next_url())

    root = advantage_api.get_macaroon()

    for caveat in Macaroon.deserialize(root).third_party_caveats():
        if caveat.location == "login.ubuntu.com":
            openid_macaroon = MacaroonRequest(caveat_id=caveat.caveat_id)
            break

    flask.session["macaroon_root"] = root

    return open_id.try_login(
        "https://login.ubuntu.com",
        ask_for=["email", "nickname", "image"],
        ask_for_optional=["fullname"],
        extensions=[openid_macaroon],
    )
Exemplo n.º 5
0
def login_handler():
    api_url = os.getenv("CONTRACTS_API_URL", "https://contracts.canonical.com")

    if user_info(flask.session):
        return flask.redirect(open_id.get_next_url())

    response = session.request(method="get",
                               url=f"{api_url}/v1/canonical-sso-macaroon")
    flask.session["macaroon_root"] = response.json()["macaroon"]

    for caveat in Macaroon.deserialize(
            flask.session["macaroon_root"]).third_party_caveats():
        if caveat.location == "login.ubuntu.com":
            openid_macaroon = MacaroonRequest(caveat_id=caveat.caveat_id)
            break

    return open_id.try_login(
        CANONICAL_LOGIN_URL,
        ask_for=["email", "nickname", "image"],
        ask_for_optional=["fullname"],
        extensions=[openid_macaroon],
    )