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:
parent
559b76c3ef
commit
f0e5259584
@ -2,6 +2,7 @@ package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// AuthenticationService handles authentication for the JIRA instance / API.
|
||||
@ -25,6 +26,7 @@ type Session struct {
|
||||
LastFailedLoginTime string `json:"lastFailedLoginTime"`
|
||||
PreviousLoginTime string `json:"previousLoginTime"`
|
||||
} `json:"loginInfo"`
|
||||
SetCoockie []*http.Cookie
|
||||
}
|
||||
|
||||
// AcquireSessionCookie creates a new session for a user in JIRA.
|
||||
@ -51,6 +53,10 @@ func (s *AuthenticationService) AcquireSessionCookie(username, password string)
|
||||
|
||||
session := new(Session)
|
||||
resp, err := s.client.Do(req, session)
|
||||
|
||||
cookies := resp.Cookies()
|
||||
session.SetCoockie = cookies
|
||||
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Auth at JIRA instance failed (HTTP(S) request). %s", err)
|
||||
}
|
||||
|
5
jira.go
5
jira.go
@ -3,7 +3,6 @@ package jira
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -83,7 +82,9 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ
|
||||
|
||||
// Set session cookie if there is one
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user