Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onpremise/Auth: Update README and examples for Bearer Auth #586

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Latest stable release: [v1.16.0](https://github.com/andygrunwald/go-jira/release

## Features

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

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

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

Expand All @@ -118,11 +118,20 @@ func main() {
}
```

#### Bearer - Personal Access Tokens (self-hosted Jira)

For **self-hosted Jira** (v8.14 and later), Personal Access Tokens (PATs) were introduced.
Similar to the API tokens, PATs are a safe alternative to using username and password for authentication with scripts and integrations.
PATs use the Bearer authentication scheme.
Read more about Jira PATs [here](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html).

See [examples/bearerauth](onpremise/examples/bearerauth/main.go) for how to use the Bearer authentication scheme with Jira in Go.

#### Basic (self-hosted Jira)

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/).

The above token authentication example may be used, substituting a user's password for a generated token.
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.

#### Authenticate with OAuth

Expand Down Expand Up @@ -223,6 +232,7 @@ func main() {
fmt.Printf("Status after transition: %+v\n", issue.Fields.Status.Name)
}
```

### Get all the issues for JQL with Pagination

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

Install [standard-version](https://github.com/conventional-changelog/standard-version)

```bash
npm i -g standard-version
```
Expand Down
30 changes: 30 additions & 0 deletions onpremise/examples/bearerauth/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
"context"
"fmt"

jira "github.com/andygrunwald/go-jira/v2/onpremise"
)

func main() {
jiraURL := "<your-jira-instance>"

// See "Using Personal Access Tokens"
// https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html
tp := jira.BearerAuthTransport{
Token: "<persona-access-token>",
}
client, err := jira.NewClient(jiraURL, tp.Client())
if err != nil {
panic(err)
}

u, _, err := client.User.GetSelf(context.Background())
if err != nil {
panic(err)
}

fmt.Printf("Email: %v\n", u.EmailAddress)
fmt.Println("Success!")
}