Skip to content

Commit b01cbe7

Browse files
Add cookie support
Signed-off-by: Johannes Larsson <[email protected]>
1 parent adab79f commit b01cbe7

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ Follow the [installation guide](https://github.com/ankitpokhrel/jira-cli/wiki/In
9090
2. Run `jira init`, select installation type as `Cloud`, and provide required details to generate a config file required
9191
for the tool.
9292

93+
#### Cloud server without personal access token
94+
Some tenants has disabled the ability to create personal Jira API tokens. The alternative then is to use the browser session cookie/token `tenant.session.token`. These will last for a day before they expire.
95+
96+
1. Configure your cli by creating the `~/.config/.jira/.config.yml`
97+
```
98+
installation: cloud
99+
server: https://<COMPANY>.atlassian.net
100+
auth_type: cookie
101+
```
102+
103+
2. Login to Jira with your browser. View the developer extension and find the cookie value of `tenant.session.token`. Then set `JIRA_SESSION_TOKEN` as that value.
104+
105+
```
106+
export JIRA_SESSION_TOKEN=ey..
107+
```
108+
109+
93110
#### On-premise installation
94111

95112
1. Export required environment variables:
@@ -672,7 +689,7 @@ $ jira sprint add SPRINT_ID ISSUE-1 ISSUE-2
672689

673690
### Releases
674691

675-
Interact with releases (project versions).
692+
Interact with releases (project versions).
676693
Ensure the [feature is enabled](https://support.atlassian.com/jira-software-cloud/docs/enable-releases-and-versions/) on your instance.
677694

678695
#### List

internal/cmd/root/root.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func checkForJiraToken(server string, login string) {
160160
return
161161
}
162162

163+
if os.Getenv("JIRA_SESSION_TOKEN") != "" {
164+
return
165+
}
166+
163167
netrcConfig, _ := netrc.Read(server, login)
164168
if netrcConfig != nil {
165169
return
@@ -170,13 +174,13 @@ func checkForJiraToken(server string, login string) {
170174
return
171175
}
172176

173-
msg := fmt.Sprintf(`The tool needs a Jira API token to function.
177+
msg := fmt.Sprintf(`The tool needs a Jira API or Session token to function.
174178
175179
For cloud server: you can generate the token using this link: %s
176180
For local server: you can use the password you use to log in to Jira for basic auth or get a token from your Jira profile for PAT.
177181
178182
After generating the token, you can either:
179-
- Export API token to your shell as a JIRA_API_TOKEN env variable
183+
- Export API token to your shell as a JIRA_API_TOKEN or JIRA_SESSION_TOKEN env variable
180184
- Or, you can use a .netrc file to define required machine details
181185
182186
Once you are done with the above steps, run 'jira init' to generate the config if you haven't already.

pkg/jira/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ func (c *Client) request(ctx context.Context, method, endpoint string, body []by
281281
}
282282
case string(AuthTypeBearer):
283283
req.Header.Add("Authorization", "Bearer "+c.token)
284+
case string(AuthTypeCookie):
285+
jiraSessionToken, _ := os.LookupEnv("JIRA_SESSION_TOKEN")
286+
req.Header.Add("Cookie", "tenant.session.token="+jiraSessionToken)
284287
case string(AuthTypeBasic):
285288
req.SetBasicAuth(c.login, c.token)
286289
}

pkg/jira/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
const (
88
// AuthTypeBasic is a basic auth.
99
AuthTypeBasic AuthType = "basic"
10+
// AuthTypeBasic is a cookie auth.
11+
AuthTypeCookie AuthType = "cookie"
1012
// AuthTypeBearer is a bearer auth.
1113
AuthTypeBearer AuthType = "bearer"
1214
// AuthTypeMTLS is a mTLS auth.

0 commit comments

Comments
 (0)