def METHOD_NAME(self):
    auth = init_saml_auth()
    auth.process_response()
    errors = auth.get_errors()
    logger.info("Request: %s %s", request, request.headers)
    if len(errors) != 0:
        logger.error("Authentication failed: %s", "; ".join(errors))
        abort(500, "Authentication failed")
    if not auth.is_authenticated():
        logger.error("User returned unauthorized from IdP")
        abort(401, "Unauthorized")
    attributes = get_attribute_dict(auth)
    logger.debug("User data: %s", attributes)
    email = format_user_field(get_env("INFRABOX_ACCOUNT_SAML_EMAIL_FORMAT"), attributes).lower()
    # Check if user already exists in database
    user = g.db.execute_one_dict("""
            SELECT id FROM "user"
            WHERE email = %s
        """, [email])
    if not user:
        name = format_user_field(get_env("INFRABOX_ACCOUNT_SAML_NAME_FORMAT"), attributes)
        username = format_user_field(get_env("INFRABOX_ACCOUNT_SAML_USERNAME_FORMAT"), attributes)
        user = g.db.execute_one_dict("""
            INSERT INTO "user" (name, username, email)
            VALUES (%s, %s, %s) RETURNING id
        """, [name, username, email])
    token = encode_user_token(user["id"])
    g.db.commit()
    redirect_url = get_root_url("global") + "/dashboard/"
    logger.debug("Redirecting authenticated user to %s", redirect_url)
    response = redirect(redirect_url)
    response.set_cookie("token", token)
    return response