Exemple #1
0
func (rt RT) authenticate(jar *cookiejar.Jar) error {

	client := &http.Client{
		Jar: jar,
	}

	data := url.Values{}
	data.Add("user", rt.Username)
	data.Add("pass", rt.Password)

	client.PostForm(rt.BaseURL, data)

	// Check that we got back at least one cookie -> probably successful authentication!
	// Alternatively could check that RT_SID_url.80 exists
	url, err := url.Parse(rt.BaseURL)
	if err != nil {
		syslog.Errf("Unable to parse BaseURL: %v", err)
		panic(err)
	}
	if len(jar.Cookies(url)) < 1 {
		return errors.New("Authentication to RT failed!")
	}

	return nil
}
func GetCookie(cookieJar *cookiejar.Jar, name string) string {
	cookieUrl, _ := url.Parse("http://tieba.baidu.com")
	cookies := cookieJar.Cookies(cookieUrl)
	for _, cookie := range cookies {
		if name == cookie.Name {
			return cookie.Value
		}
	}
	return ""
}
func (sd *SessionData) AddCookies(cookies *cookiejar.Jar) {
	cookies.SetCookies(cookiePath, []*http.Cookie{
		&http.Cookie{
			Name:   "mobileClientVersion",
			Value:  "0 (2.1.3)",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "mobileClient",
			Value:  "android",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "Steam_Language",
			Value:  "english",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "steamid",
			Value:  strconv.FormatUint(sd.SteamID, 10),
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:     "steamLogin",
			Value:    sd.SteamLogin,
			Path:     "/",
			Domain:   ".steamcommunity.com",
			HttpOnly: true,
		},
		&http.Cookie{
			Name:     "steamLoginSecure",
			Value:    sd.SteamLoginSecure,
			Path:     "/",
			Domain:   ".steamcommunity.com",
			Secure:   true,
			HttpOnly: true,
		},
		&http.Cookie{
			Name:   "dob",
			Value:  "",
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
		&http.Cookie{
			Name:   "sessionid",
			Value:  sd.SessionID,
			Path:   "/",
			Domain: ".steamcommunity.com",
		},
	})
}
Exemple #4
0
func login(privKey box.PrivateKey) error {
	var err error
	var challenge []byte
	var ok bool
	var jar *cookiejar.Jar
	c := make(map[string]string)
	// Step1: request challenge
	resp, err := http.Get(fmt.Sprintf("%s/%s", api["auth"].String(), username))
	if err != nil {
		return err
	}
	d := json.NewDecoder(resp.Body)
	defer resp.Body.Close()
	d.Decode(&c)
	data := decodeBase64(c["challenge"])
	if box.BoxIsSigned(data) {
		log.Println("opening signed box...")
		challenge, ok = box.OpenAndVerify(data, privKey, srvKey)
	} else {
		log.Println("opening box...")
		challenge, ok = box.Open(data, privKey)
	}
	if !ok {
		log.Println("unboxing returned not ok")
		return &internalError{E_AUTH}
	}

	// Step2: validate challenge
	step2, err := json.Marshal(&map[string]string{"id": c["id"], "challenge": base64.StdEncoding.EncodeToString(challenge)})
	if err != nil {
		return err
	}
	resp, err = http.Post(api["auth"].String(), jsonMime, strings.NewReader(string(step2)))
	if err != nil {
		return err
	}
	if resp.StatusCode == http.StatusUnauthorized {
		return &internalError{E_AUTH}
	}
	if resp.StatusCode != http.StatusOK {
		return &internalError{E_SERVER}
	}

	jar, err = cookiejar.New(nil)
	if err != nil {
		log.Fatalf("Failed opening cookiejar: %v\n", err)
	}
	jar.SetCookies(api["/"], resp.Cookies())
	myId, _ = strconv.ParseInt(c["id"], 10, 64)
	client = &http.Client{Jar: jar}

	return nil
}
Exemple #5
0
func Http_send(strUrl string, postDict map[string]string, cookies string, header map[string]string) ([]byte, string, error) {

	var gCurCookieJar *cookiejar.Jar
	gCurCookieJar, _ = cookiejar.New(nil)
	httpClient := &http.Client{Jar: gCurCookieJar}
	tr := &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
	httpClient.Transport = tr
	var httpReq *http.Request
	var err error = nil
	if nil == postDict {
		httpReq, _ = http.NewRequest("GET", strUrl, nil)
	} else {
		postValues := url.Values{}
		for postKey, PostValue := range postDict {
			postValues.Set(postKey, PostValue)
		}
		postDataStr := postValues.Encode()
		postDataBytes := []byte(postDataStr)
		postBytesReader := bytes.NewReader(postDataBytes)

		httpReq, _ = http.NewRequest("POST", strUrl, postBytesReader)
		if header["Content-Type"] == "" {
			httpReq.Header.Add("Content-Type", "application/x-www-form-urlencoded")
		}

	}
	httpReq.Header.Add("Cookie", cookies)
	for headerKey, headerValue := range header {
		httpReq.Header.Add(headerKey, headerValue)
	}
	httpResp, err := httpClient.Do(httpReq)
	if err != nil {
		return make([]byte, 1), "", err
	}
	defer httpResp.Body.Close()
	body, errReadAll := ioutil.ReadAll(httpResp.Body)
	if errReadAll != nil {
		return make([]byte, 1), "", errReadAll
	}
	var gCurCookies []*http.Cookie
	gCurCookies = gCurCookieJar.Cookies(httpReq.URL)
	var cookieNum int = len(gCurCookies)
	cookies = ""
	for i := 0; i < cookieNum; i++ {
		var curCk *http.Cookie = gCurCookies[i]
		cookies += curCk.Name + "=" + curCk.Value + ";"
	}

	return body, cookies, nil
}
Exemple #6
0
func csrfTokenFromCookies(cookiejar *cookiejar.Jar) string {
	urlParse, _ := url.Parse(INSTAGRAM_HOST)
	for _, cookie := range cookiejar.Cookies(urlParse) {
		if cookie.Name == "csrftoken" {
			return cookie.Value
		}
	}
	return ""
}
	"github.com/concourse/atc/auth"
	"github.com/concourse/atc/auth/fakes"
	"github.com/concourse/atc/auth/provider"
	providerFakes "github.com/concourse/atc/auth/provider/fakes"
)

var _ = Describe("OAuthBeginHandler", func() {
	var (
		fakeProviderA *providerFakes.FakeProvider
		fakeProviderB *providerFakes.FakeProvider

		fakeProviderFactory *fakes.FakeProviderFactory

		fakeAuthDB *fakes.FakeAuthDB

		signingKey *rsa.PrivateKey

		cookieJar *cookiejar.Jar

		server *httptest.Server
		client *http.Client
	)

	BeforeEach(func() {
		fakeProviderA = new(providerFakes.FakeProvider)
		fakeProviderB = new(providerFakes.FakeProvider)

		fakeProviderFactory = new(fakes.FakeProviderFactory)

		fakeAuthDB = new(fakes.FakeAuthDB)
Exemple #8
0
func getFinalURL(jar *cookiejar.Jar, addr *url.URL, level int) (*url.URL, error) {
	if flDebug {
		log.Printf("new request (level %d): %s", level, addr.String())
	}
	if level == 0 {
		return nil, fmt.Errorf("too many redirects")
	}
	if addr.Scheme != "http" && addr.Scheme != "https" {
		return nil, fmt.Errorf("unsupported url scheme: %s", addr.Scheme)
	}
	req, err := http.NewRequest("GET", addr.String(), nil)
	if err != nil {
		return nil, fmt.Errorf("request create err: %s", err)
	}
	cookies := jar.Cookies(addr)
	for _, cookie := range cookies {
		if flDebug {
			log.Printf("add cookie: %s", cookie.String())
		}
		req.AddCookie(cookie)
	}
	req.Header.Set("User-Agent", userAgent)
	resp, err := http.DefaultTransport.RoundTrip(req)
	if err != nil {
		if uErr, ok := err.(*url.Error); !ok || uErr.Err != errStopRedirect {
			return nil, fmt.Errorf("request err: %s", err)
		}
	}
	defer resp.Body.Close()
	ct := strings.ToLower(resp.Header.Get("Content-Type"))
	if flDebug {
		log.Printf("response code: %d, content-type %s", resp.StatusCode, ct)
	}
	jar.SetCookies(resp.Request.URL, resp.Cookies())
	if resp.StatusCode == 301 || resp.StatusCode == 302 || resp.StatusCode == 303 || resp.StatusCode == 307 {
		location := resp.Header.Get("Location")
		addr, err = url.Parse(location)
		if err != nil {
			return nil, err
		}
		return getFinalURL(jar, addr, level-1)
	}
	if !strings.HasPrefix(ct, "text/html") {
		if flDebug {
			log.Printf("not html content-type: %s", ct)
		}
		return resp.Request.URL, err
	}
	buf := &bytes.Buffer{}
	_, err = io.CopyN(buf, resp.Body, 1024*1024*10)
	if err != nil && err != io.EOF {
		return nil, err
	}
	data := bytes.ToLower(buf.Bytes())
	if flDebug {
		log.Printf("html: %s", string(data))
	}
	metaRedirect, err := findMetaRedirect(data)
	if err != nil {
		return nil, fmt.Errorf("meta redirect err: %s", err)
	}
	if metaRedirect == nil {
		return addr, nil
	}
	if flDebug {
		log.Printf("html meta redirect: %s", metaRedirect)
	}
	return getFinalURL(jar, metaRedirect, level-1)
}
func GetCookies(cookieJar *cookiejar.Jar) []*http.Cookie {
	cookieUrl, _ := url.Parse("http://tieba.baidu.com")
	cookies := cookieJar.Cookies(cookieUrl)
	return cookies
}