func HandleGenericOauthTestRequest(w http.ResponseWriter, req *http.Request, c oauth2_client.OAuth2Client, method, test_url_property, body string, useTemplate *template.Template) {
	props := getProperties()
	if req.Method == oauth2_client.POST {
		if err := req.ParseForm(); err != nil {
			w.Header().Set("Content-Type", "text/plain")
			w.WriteHeader(500)
			io.WriteString(w, "Unable to parse form:\n\n")
			io.WriteString(w, err.Error())
			return
		}
		for k, arr := range req.Form {
			for _, v := range arr {
				props.Set(k, v)
			}
		}
	}
	for k, arr := range req.URL.Query() {
		for _, v := range arr {
			props.Set(k, v)
		}
	}
	c.Initialize(props)
	uri := props.GetAsString(test_url_property)
	log.Printf("Client is: %T -> %#v", c, c)
	var reader io.Reader = nil
	if len(body) > 0 {
		reader = bytes.NewBufferString(body)
	}
	resp, _, err := oauth2_client.AuthorizedRequest(c, method, nil, uri, nil, reader)
	m := make(map[string]interface{})
	isError := false
	m["c"] = c
	m["url"] = uri
	if err != nil {
		m["output"] = err.Error()
		isError = true
	} else {
		b, err := httputil.DumpResponse(resp, true)
		if err != nil {
			m["output"] = err.Error()
			isError = true
		} else {
			m["output"] = string(b)
		}
	}
	if isError {
		w.Header().Set("Content-Type", "text/plain")
		w.WriteHeader(500)
	} else {
		w.Header().Set("Content-Type", "text/html")
		w.WriteHeader(200)
	}
	err = useTemplate.Execute(w, m)
	if err != nil {
		oauth2_client.LogErrorf("Error: %T %v", err, err)
	}
}
func HandleClientAccept(w http.ResponseWriter, req *http.Request) {
	var c oauth2_client.OAuth2Client = nil
	method := "GET"
	headers := make(http.Header)
	uri := ""
	query := make(url.Values)
	var reader io.Reader = nil
	props := getProperties()
	q := req.URL.Query()
	oauth2_client.LogInfo("=================================")
	oauth2_client.LogInfo("Received request from User: "******"=================================")
	var useTemplate *template.Template = nil
	var useTemplateData interface{} = nil
	if site := q.Get("site"); len(site) > 0 {
		if index := strings.Index(site, "?"); index >= 0 {
			site = site[0:index]
		}
		m := make(map[string]interface{})
		switch site {
		case "facebook.com":
			c = NewFacebookOauth2ClientTester(props)
			uri = props.GetAsString("facebook.client.test_url")
			useTemplate = PARSED_FACEBOOK_TEMPLATE
		case "google.com":
			c = NewGoogleOauth2ClientTester(props)
			uri = props.GetAsString("google.client.test_url")
			useTemplate = PARSED_GOOGLE_TEMPLATE
		case "plus.google.com":
			c = NewGooglePlusOauth2ClientTester(props)
			uri = props.GetAsString("googleplus.client.test_url")
			useTemplate = PARSED_GOOGLEPLUS_TEMPLATE
		case "linkedin.com":
			c = NewLinkedInOauth2ClientTester(props)
			uri = props.GetAsString("linkedin.client.test_url")
			useTemplate = PARSED_LINKEDIN_TEMPLATE
		case "smugmug.com":
			// smugmug doesn't support query strings properly
			newRawUrl := strings.Replace(req.URL.String(), "site=smugmug.com?", "site=smugmug.com&", 1)
			newUrl, _ := url.Parse(newRawUrl)
			if newUrl != nil {
				req.URL = newUrl
				q = newUrl.Query()
			}
			c = NewSmugMugOauth2ClientTester(props)
			uri = props.GetAsString("smugmug.client.test_url")
			useTemplate = PARSED_SMUGMUG_TEMPLATE
		case "twitter.com":
			c = NewTwitterOauth2ClientTester(props)
			uri = props.GetAsString("twitter.client.test_url")
			useTemplate = PARSED_TWITTER_TEMPLATE
		case "yahoo.com":
			c = NewYahooOauth2ClientTester(props)
			uri = props.GetAsString("yahoo.client.test_url")
			useTemplate = PARSED_YAHOO_TEMPLATE
		default:
			log.Fatal("Unable to determine OAuth client to handle response: ", req.URL.String())
		}
		m["c"] = c
		m["url"] = uri
		m["output"] = ""
		useTemplateData = m
	} else {
		log.Fatal("Unable to determine OAuth client to handle response: ", req.URL.String())
	}
	err := c.ExchangeRequestTokenForAccess(req)
	if err != nil {
		w.Header().Set("Content-Type", "text/plain")
		w.WriteHeader(500)
		io.WriteString(w, "Error exchanging request token for access token\n\n")
		io.WriteString(w, err.Error())
		return
	}
	if useTemplate != nil {
		w.Header().Set("Content-Type", "text/html")
		w.WriteHeader(200)
		err = useTemplate.Execute(w, useTemplateData)
		if err != nil {
			oauth2_client.LogErrorf("Error: %T %v", err, err)
		}
	} else {
		oauth2_client.LogInfo("Retrieving User Info...")
		userInfo, err3 := c.RetrieveUserInfo()
		oauth2_client.LogInfof("UserInfo: %T %v", userInfo, userInfo)
		oauth2_client.LogInfof("Error: %T %v", err3, err3)

		r, _, err2 := oauth2_client.AuthorizedRequest(c, method, headers, uri, query, reader)
		if err2 != nil {
			w.Header().Set("Content-Type", "text/plain")
			w.WriteHeader(500)
			io.WriteString(w, "Error retrieving authorized response for "+uri+"?"+query.Encode()+"\n\n")
			io.WriteString(w, err.Error())
			return
		}
		h := w.Header()
		for k, v := range r.Header {
			for _, v1 := range v {
				h.Add(k, v1)
			}
		}
		w.WriteHeader(r.StatusCode)
		io.Copy(w, r.Body)
		return
	}
}