Exemplo n.º 1
0
// Like Verify on a parsed URL
func VerifyValues(values url.Values) (grant bool, identifier string, err error) {
	err = nil

	var postArgs url.Values
	postArgs = url.Values(map[string][]string{})

	// Create the url
	URLEndPoint := values.Get("openid.op_endpoint")
	if URLEndPoint == "" {
		log.Printf("no openid.op_endpoint")
		return false, "", errors.New("no openid.op_endpoint")
	}
	for k, v := range values {
		postArgs[k] = v
	}
	postArgs.Set("openid.mode", "check_authentication")
	postContent := postArgs.Encode()

	// Post the request
	var client = new(http.Client)
	postReader := bytes.NewBuffer([]byte(postContent))
	response, err := client.Post(URLEndPoint, "application/x-www-form-urlencoded", postReader)
	if err != nil {
		log.Printf("VerifyValues failed at post")
		return false, "", err
	}

	// Parse the response
	// Convert the reader
	// We limit the size of the response to 1024 bytes but it should be large enough for most cases
	buffer := make([]byte, 1024)
	_, err = response.Body.Read(buffer)
	if err != nil {
		log.Printf("VerifyValues failed reading response")
		return false, "", err
	}

	// Check for ns
	rematch := REVerifyDirectNs.FindSubmatch(buffer)
	if rematch == nil {
		return false, "", errors.New("VerifyValues: ns value not found on the response of the OP")
	}
	nsValue := string(rematch[1])
	if !bytes.Equal([]byte(nsValue), []byte("http://specs.openid.net/auth/2.0")) {
		return false, "", errors.New("VerifyValues: ns value not correct: " + nsValue)
	}

	// Check for is_valid
	match, err := regexp.Match(REVerifyDirectIsValid, buffer)
	if err != nil {
		return false, "", err
	}

	identifier = values.Get("openid.claimed_id")
	if !match {
		log.Printf("no is_valid:true in \"%s\"", buffer)
	}

	return match, identifier, nil
}
Exemplo n.º 2
0
// NewPOSTTask creates a Task that will POST to a path with the given form data.
func NewPOSTTask(path string, params url.Values) *Task {
	h := make(http.Header)
	h.Set("Content-Type", "application/x-www-form-urlencoded")
	return &Task{
		Path:    path,
		Payload: []byte(params.Encode()),
		Header:  h,
		Method:  "POST",
	}
}
Exemplo n.º 3
0
// Build a URL+query string based on a given server URL, serverId and user
// input
func (s *ServerAuth) BuildQuery(serverId, user string) (query string) {
	queryValues := url.Values{
		"serverId": {serverId},
		"user":     {user},
	}

	queryUrl := s.baseUrl
	queryUrl.RawQuery = queryValues.Encode()

	return queryUrl.String()
}
Exemplo n.º 4
0
Arquivo: gohub.go Projeto: supr/gohub
func (p *PullRequest) NewIssueComment(body string) (*Comment, os.Error) {
	url_ := fmt.Sprintf("%v/repos/%v/%v/issues/%v/comments", p.g.apiHost, p.Head.Repo.Name, p.Head.Repo.Owner.Login, p.Number)
	params := url.Values{}
	params.Add("body", body)
	out, err := p.g.makePostRequest(url_, strings.NewReader(params.Encode()))
	if err != nil {
		return nil, err
	}

	var comment Comment
	err = json.Unmarshal(out, &comment)
	if err != nil {
		return nil, err
	}

	return &comment, nil
}
Exemplo n.º 5
0
Arquivo: gohub.go Projeto: supr/gohub
func (g *GoHub) makeGetRequest(url_ string, params url.Values) ([]byte, os.Error) {
	req, err := g.makeAuthRequest("GET", url_, strings.NewReader(params.Encode()))
	if err != nil {
		return nil, err
	}

	resp, err := g.client.Do(req)
	if err != nil {
		return nil, err
	}

	outbuf, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	return outbuf, err
}
Exemplo n.º 6
0
func sesGet(data url.Values) (string, os.Error) {
	data.Add("AWSAccessKeyId", accessKey)
	urlstr := fmt.Sprintf("%s?%s", endpoint, data.Encode())
	endpointURL, _ := url.Parse(urlstr)
	headers := map[string][]string{}

	now := time.UTC()
	date := now.Format("Mon, 02 Jan 2006 15:04:05 -0700")
	headers["Date"] = []string{date}

	h := hmac.NewSHA256([]uint8(secretKey))
	h.Write([]uint8(date))
	signature := base64.StdEncoding.EncodeToString(h.Sum())
	auth := fmt.Sprintf("AWS3-HTTPS AWSAccessKeyId=%s, Algorithm=HmacSHA256, Signature=%s", accessKey, signature)
	headers["X-Amzn-Authorization"] = []string{auth}

	req := http.Request{
		URL:        endpointURL,
		Method:     "GET",
		ProtoMajor: 1,
		ProtoMinor: 1,
		Close:      true,
		Header:     headers,
	}

	r, err := http.DefaultClient.Do(&req)
	if err != nil {
		return "", err
	}

	resultbody, _ := ioutil.ReadAll(r.Body)
	r.Body.Close()

	if r.StatusCode != 200 {
		return "", os.NewError(string(resultbody))
	}

	return string(resultbody), nil
}
Exemplo n.º 7
0
func (nc *Client) request(path string, data url.Values) (*response, os.Error) {
	// endpoint
	url := "https://api.notifo.com/v1" + path
	// encode request params
	reqBody := strings.NewReader(data.Encode())
	// build request
	req, err := http.NewRequest("POST", url, reqBody)
	if err != nil {
		return nil, err
	}
	req.Method = "POST"
	req.SetBasicAuth(nc.Username, nc.ApiSecret)
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	// make request
	client := new(http.Client)
	r, err := client.Do(req)
	// check connection
	if err != nil {
		return nil, err
	}
	defer r.Body.Close()
	// read response
	body, _ := ioutil.ReadAll(r.Body)
	// decode json
	response := new(response)
	err = json.Unmarshal(body, &response)
	if err != nil {
		return nil, err
	}
	// check for success code
	if response.Code != 2201 {
		return nil, fmt.Errorf("notifo: %s", response.Message)
	}
	// no error
	return response, nil
}
Exemplo n.º 8
0
// PostForm issues a POST to the specified URL,
// with data's keys and values urlencoded as the request body.
//
// Caller should close r.Body when done reading from it.
func (c *Client) PostForm(url string, data url.Values) (r *Response, err os.Error) {
	return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
}