def METHOD_NAME(self, request, username, idp_slug, is_handshake_successful):
    if not (request and username and idp_slug and is_handshake_successful):
        return None
    username = username.lower()
    try:
        identity_provider = IdentityProvider.objects.get(slug=idp_slug)
    except IdentityProvider.DoesNotExist:
        # not sure how we would even get here, but just in case
        request.sso_login_error = f"Identity Provider {idp_slug} does not exist."
        return None
    if not identity_provider.is_active:
        request.sso_login_error = f"This Identity Provider {idp_slug} is not active."
        return None
    email_domain = get_email_domain_from_username(username)
    if not email_domain:
        # not a valid username
        request.sso_login_error = f"Username {username} is not valid."
        return None
    if not AuthenticatedEmailDomain.objects.filter(
        email_domain=email_domain, identity_provider=identity_provider
    ).exists():
        # if this user's email domain is not authorized by this identity
        # do not continue with authentication
        request.sso_login_error = (
            f"The Email Domain {email_domain} is not allowed to "
            f"authenticate with this Identity Provider ({idp_slug})."
        )
        return None
    async_signup = AsyncSignupRequest.get_by_username(username)
    # because the django messages middleware is not yet available...
    request.sso_new_user_messages = {
        'success': [],
        'error': [],
    }
    try:
        user = User.objects.get(username=username)
        is_new_user = False
        web_user = WebUser.get_by_username(username)
    except User.DoesNotExist:
        user, web_user = self._create_new_user(request, username, async_signup)
        is_new_user = True
    if async_signup and async_signup.invitation:
        self._process_invitation(request, async_signup.invitation, web_user, is_new_user)
    request.sso_login_error = None
    return user