Skip to content

Commit a7b0a95

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

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-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 then environment variable `JIRA_API_TOKEN` as that value.
104+
105+
```
106+
export JIRA_API_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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@ func checkForJiraToken(server string, login string) {
170170
return
171171
}
172172

173-
msg := fmt.Sprintf(`The tool needs a Jira API token to function.
173+
msg := fmt.Sprintf(`The tool needs a Jira API or Session token to function.
174174
175175
For cloud server: you can generate the token using this link: %s
176176
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.
177177
178178
After generating the token, you can either:
179-
- Export API token to your shell as a JIRA_API_TOKEN env variable
179+
- Export API token to your shell as a JIRA_API_TOKEN or JIRA_SESSION_TOKEN env variable
180180
- Or, you can use a .netrc file to define required machine details
181181
182182
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ 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+
req.Header.Add("Cookie", "tenant.session.token="+c.token)
284286
case string(AuthTypeBasic):
285287
req.SetBasicAuth(c.login, c.token)
286288
}

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)