1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-02-09 13:36:58 +02:00

Change Coocke session get from request

This commit is contained in:
Evgen Kostenko 2016-05-27 13:01:54 +03:00
parent 559b76c3ef
commit f0e5259584
2 changed files with 9 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package jira
import ( import (
"fmt" "fmt"
"net/http"
) )
// AuthenticationService handles authentication for the JIRA instance / API. // AuthenticationService handles authentication for the JIRA instance / API.
@ -25,6 +26,7 @@ type Session struct {
LastFailedLoginTime string `json:"lastFailedLoginTime"` LastFailedLoginTime string `json:"lastFailedLoginTime"`
PreviousLoginTime string `json:"previousLoginTime"` PreviousLoginTime string `json:"previousLoginTime"`
} `json:"loginInfo"` } `json:"loginInfo"`
SetCoockie []*http.Cookie
} }
// AcquireSessionCookie creates a new session for a user in JIRA. // AcquireSessionCookie creates a new session for a user in JIRA.
@ -51,6 +53,10 @@ func (s *AuthenticationService) AcquireSessionCookie(username, password string)
session := new(Session) session := new(Session)
resp, err := s.client.Do(req, session) resp, err := s.client.Do(req, session)
cookies := resp.Cookies()
session.SetCoockie = cookies
if err != nil { if err != nil {
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). %s", err) return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). %s", err)
} }

View File

@ -3,7 +3,6 @@ package jira
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -83,7 +82,9 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ
// Set session cookie if there is one // Set session cookie if there is one
if c.session != nil { if c.session != nil {
req.Header.Set("Cookie", fmt.Sprintf("%s=%s", c.session.Session.Name, c.session.Session.Value)) for _, cookie := range c.session.SetCoockie {
req.AddCookie(cookie)
}
} }
return req, nil return req, nil