Skip to content

Commit 4496e87

Browse files
authored
Merge pull request #586 from andygrunwald/pr-469
Onpremise/Auth: Update README and examples for Bearer Auth
2 parents b835d6c + 051e945 commit 4496e87

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Latest stable release: [v1.16.0](https://github.com/andygrunwald/go-jira/release
2929

3030
## Features
3131

32-
* Authentication (HTTP Basic, OAuth, Session Cookie)
32+
* Authentication (HTTP Basic, OAuth, Session Cookie, Bearer (for PATs))
3333
* Create and retrieve issues
3434
* Create and retrieve issue transitions (status updates)
3535
* Call every API endpoint of the Jira, even if it is not directly implemented in this library
@@ -92,7 +92,7 @@ func main() {
9292
### Authentication
9393

9494
The `go-jira` library does not handle most authentication directly. Instead, authentication should be handled within
95-
an `http.Client`. That client can then be passed into the `NewClient` function when creating a jira client.
95+
an `http.Client`. That client can then be passed into the `NewClient` function when creating a jira client.
9696

9797
For convenience, capability for basic and cookie-based authentication is included in the main library.
9898

@@ -118,11 +118,20 @@ func main() {
118118
}
119119
```
120120

121+
#### Bearer - Personal Access Tokens (self-hosted Jira)
122+
123+
For **self-hosted Jira** (v8.14 and later), Personal Access Tokens (PATs) were introduced.
124+
Similar to the API tokens, PATs are a safe alternative to using username and password for authentication with scripts and integrations.
125+
PATs use the Bearer authentication scheme.
126+
Read more about Jira PATs [here](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html).
127+
128+
See [examples/bearerauth](onpremise/examples/bearerauth/main.go) for how to use the Bearer authentication scheme with Jira in Go.
129+
121130
#### Basic (self-hosted Jira)
122131

123132
Password-based API authentication works for self-hosted Jira **only**, and has been [deprecated for users of Atlassian Cloud](https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/).
124133

125-
The above token authentication example may be used, substituting a user's password for a generated token.
134+
Depending on your version of Jira, either of the above token authentication examples may be used, substituting a user's password for a generated token.
126135

127136
#### Authenticate with OAuth
128137

@@ -223,6 +232,7 @@ func main() {
223232
fmt.Printf("Status after transition: %+v\n", issue.Fields.Status.Name)
224233
}
225234
```
235+
226236
### Get all the issues for JQL with Pagination
227237

228238
Jira API has limit on maxResults it can return. You may have a usecase where you need to get all issues for given JQL.
@@ -354,6 +364,7 @@ You can read more about them at https://blog.developer.atlassian.com/cloud-ecosy
354364
## Releasing
355365

356366
Install [standard-version](https://github.com/conventional-changelog/standard-version)
367+
357368
```bash
358369
npm i -g standard-version
359370
```

onpremise/examples/bearerauth/main.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
jira "github.com/andygrunwald/go-jira/v2/onpremise"
8+
)
9+
10+
func main() {
11+
jiraURL := "<your-jira-instance>"
12+
13+
// See "Using Personal Access Tokens"
14+
// https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html
15+
tp := jira.BearerAuthTransport{
16+
Token: "<persona-access-token>",
17+
}
18+
client, err := jira.NewClient(jiraURL, tp.Client())
19+
if err != nil {
20+
panic(err)
21+
}
22+
23+
u, _, err := client.User.GetSelf(context.Background())
24+
if err != nil {
25+
panic(err)
26+
}
27+
28+
fmt.Printf("Email: %v\n", u.EmailAddress)
29+
fmt.Println("Success!")
30+
}

0 commit comments

Comments
 (0)