def METHOD_NAME(
    self,
    state,
    auth_data,
    urlopen,
    expect_success=True,
    customer_domain="",
    has_2fa=False,
    **kwargs,
):
    headers = {"Content-Type": "application/json"}
    urlopen.return_value = MockResponse(headers, json.dumps(auth_data))
    query = urlencode({"code": "1234", "state": state})
    resp = self.client.get(f"{self.sso_path}?{query}", **kwargs)
    if expect_success:
        if has_2fa:
            assert resp["Location"] == "/auth/2fa/"
            with mock.patch(
                "sentry.auth.authenticators.TotpInterface.validate_otp", return_value=True
            ):
                assert resp.status_code == 302
                resp = self.client.post(reverse("sentry-2fa-dialog"), {"otp": "something"})
                assert resp.status_code == 302
                assert resp["Location"].startswith("http://testserver/auth/sso/?")
                resp = self.client.get(resp["Location"])
        assert resp.status_code == 302
        assert resp["Location"] == f"{customer_domain}/auth/login/"
        resp = self.client.get(resp["Location"], follow=True)
        assert resp.status_code == 200
        assert resp.redirect_chain == [("/organizations/baz/issues/", 302)]
        assert resp.context["user"].id == self.user.id
        assert urlopen.called
        data = urlopen.call_args[1]["data"]
        assert data == {
            "grant_type": "authorization_code",
            "code": "1234",
            "redirect_uri": "http://testserver/auth/sso/",
            "client_id": "my_client_id",
            "client_secret": "my_client_secret",
        }
    return resp