Skip to content

Commit b3fdeca

Browse files
Add cookie support
1 parent 396933d commit b3fdeca

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

README.md

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

97+
#### Cloud server where PAT or OAuth is unavailable
98+
99+
Some tenants have disabled or restricted the ability to create personal Jira API tokens / OAuth credentials. In these cases, you can fall back to the browser session cookie `tenant.session.token`. Note that this cookie usually expires in about 24 hours, so you will need to refresh it periodically.
100+
101+
1. Log in to Jira with your browser. Open the developer tools (Application/Storage tab) and find the cookie value for `tenant.session.token`. Then set the environment variable `JIRA_API_TOKEN` to that value.
102+
103+
```sh
104+
export JIRA_API_TOKEN=ey..
105+
```
106+
107+
2. Bootstrap your CLI
108+
109+
```sh
110+
jira init --installation cloud --server https://<COMPANY>.atlassian.net --auth-type cookie --project ABC
111+
```
112+
97113
#### On-premise installation
98114

99115
1. Export required environment variables:
@@ -119,9 +135,10 @@ See [FAQs](https://github.com/ankitpokhrel/jira-cli/discussions/categories/faqs)
119135

120136
#### Authentication types
121137

122-
The tool supports `basic`, `bearer` (Personal Access Token), and `mtls` (Client Certificates) authentication types. Basic auth is used by
138+
The tool supports `basic`, `cookie` (browser session), `bearer` (Personal Access Token), and `mtls` (Client Certificates) authentication types. Basic auth is used by
123139
default.
124140

141+
* If you want to use a browser session cookie, set `--auth-type cookie` (or `JIRA_AUTH_TYPE=cookie`) and set `JIRA_API_TOKEN` to the value of `tenant.session.token`.
125142
* If you want to use PAT, you need to set `JIRA_AUTH_TYPE` as `bearer`.
126143
* If you want to use `mtls` run `jira init`. Select installation type `Local`, and then select authentication type as `mtls`.
127144
* In case `JIRA_API_TOKEN` variable is set it will be used together with `mtls`.

internal/cmd/init/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewCmdInit() *cobra.Command {
4040
cmd.Flags().String("installation", "", "Is this a 'cloud' or 'local' jira installation?")
4141
cmd.Flags().String("server", "", "Link to your jira server")
4242
cmd.Flags().String("login", "", "Jira login username or email based on your setup")
43-
cmd.Flags().String("auth-type", "", "Authentication type can be basic, bearer or mtls")
43+
cmd.Flags().String("auth-type", "", "Authentication type can be basic, cookie, bearer or mtls")
4444
cmd.Flags().String("project", "", "Your default project key")
4545
cmd.Flags().String("board", "", "Name of your default board in the project")
4646
cmd.Flags().Bool("force", false, "Forcefully override existing config if it exists")

internal/config/generator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,11 @@ func (c *JiraCLIConfigGenerator) configureLocalAuthType() error {
229229
if c.usrCfg.AuthType == "" {
230230
qs := &survey.Select{
231231
Message: "Authentication type:",
232-
Help: `Authentication type coud be: basic (login), bearer (PAT) or mtls (client certs)
232+
Help: `Authentication type could be: basic (login), cookie (browser session), bearer (PAT) or mtls (client certs)
233233
? If you are using your login credentials, the auth type is probably 'basic' (most common for local installation)
234+
? If you are using a browser session cookie, choose 'cookie'
234235
? If you are using a personal access token, the auth type is probably 'bearer'`,
235-
Options: []string{"basic", "bearer", "mtls"},
236+
Options: []string{"basic", "cookie", "bearer", "mtls"},
236237
Default: "basic",
237238
}
238239
if err := survey.AskOne(qs, &authType); err != nil {

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ import (
77
const (
88
// AuthTypeBasic is a basic auth.
99
AuthTypeBasic AuthType = "basic"
10-
// AuthTypeBearer is a bearer auth.
10+
// AuthTypeCookie is a cookie (browser session) auth.
11+
AuthTypeCookie AuthType = "cookie"
12+
// AuthTypeBearer is a bearer (PAT) auth.
1113
AuthTypeBearer AuthType = "bearer"
1214
// AuthTypeMTLS is a mTLS auth.
1315
AuthTypeMTLS AuthType = "mtls"
1416
)
1517

1618
// AuthType is a jira authentication type.
17-
// Currently supports basic and bearer (PAT).
19+
// Currently supports basic, cookie, bearer (PAT) and mtls (client certificates).
1820
// Defaults to basic for empty or invalid value.
1921
type AuthType string
2022

0 commit comments

Comments
 (0)