def METHOD_NAME(request, idp_slug):
    """
    ACS stands for "Assertion Consumer Service". The Identity Provider will send
    its response to this view after authenticating a user. This is often
    referred to as the "Entity ID" in the IdP's Service Provider configuration.
    In this view we verify the received SAML 2.0 response and then log in the user
    to CommCare HQ.
    """
    request_id = request.session.get('AuthNRequestID')
    try:
        request.saml2_auth.process_response(request_id=request_id)
        errors = request.saml2_auth.get_errors()
    except OneLogin_Saml2_Error as e:
        if e.code == OneLogin_Saml2_Error.SAML_RESPONSE_NOT_FOUND:
            return redirect("sso_saml_login", idp_slug=idp_slug)
        errors = [e]
    if errors:
        return render_saml_acs_error(
            request,
            saml_error_reason=request.saml2_auth.get_last_error_reason() or errors[0],
            idp_service_name=request.idp.service_name,
        )
    if not request.saml2_auth.is_authenticated():
        return render_sso_user_login_failed(request)
    if 'AuthNRequestID' in request.session:
        del request.session['AuthNRequestID']
    store_saml_data_in_session(request)
    user = auth.authenticate(
        request=request,
        username=request.session['samlNameId'],
        idp_slug=idp_slug,
        is_handshake_successful=True,
    )
    show_sso_login_success_or_error_messages(request)
    if user:
        auth.login(request, user)
        process_async_signup_requests(request, user)
        relay_state = request.saml2_request_data['post_data'].get('RelayState')
        if relay_state not in [
            OneLogin_Saml2_Utils.get_self_url(request.saml2_request_data),
            get_saml_login_url(request.idp),
        ]:
            # redirect to next=<relay_state>
            return HttpResponseRedirect(
                request.saml2_auth.redirect_to(relay_state)
            )
        return redirect("homepage")
    return render_saml_acs_error(
        request,
        login_error=getattr(request, 'sso_login_error', None),
    )