jwt

package module
v0.0.0-...-d25ab8c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2021 License: MIT Imports: 10 Imported by: 0

README

atlassian-jwt


atlassian-jwt
JWT library for Atlassian in Go.

Build Status

atlassian-jwt is a library that makes it easy to authenticate with JIRA from a variety of app types.

Installation

go get github.com/rbriski/atlassian-jwt

Usage (with go-jira)

import (
    jira "github.com/andygrunwald/go-jira"
    jwt "github.com/rbriski/atlassian-jwt"
)

c := &jwt.Config{
    Key: "some_key",
    ClientKey: "some_client_key",
    SharedSecret: "so_freakin_secret",
    BaseUrl: "http://example.com",
}

// Pass the JWT client into the library client
jiraClient, _ := jira.NewClient(c.Client(), c.BaseURL)

Examples

There are a number of different ways that an app can authenticate with JIRA. Right now, atlassian-jwt only handles JWT authentication as an add-on.

Using ngrok, you can spin up a working example to authenticate with.

> cd examples/jwt
> BASE_URL=https://<some_string>.ngrok.io go run main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AtlassianClaims

type AtlassianClaims struct {
	QSH string `json:"qsh"`

	jwt.StandardClaims
}

AtlassianClaims are all mandatory claims for Atlassian JWT

type AuthSetter

type AuthSetter interface {
	// SetAuthHeader takes a request pointer and sets the
	// Authorization header with a valid Atlassian JWT
	SetAuthHeader(*http.Request) error
}

A AuthSetter is anything that can set the authorization header on an http.Request

type Config

type Config struct {
	// Key holds the app key described in the Atlassian Connect
	// JSON file
	Key string

	// ClientKey holds the key that JIRA returns to validate JWT
	// tokens from Jira
	ClientKey string

	// SharedSecret is the signing secret for the Authorization header
	SharedSecret string

	// BaseURL is the base URL of the JIRA instance
	BaseURL string
}

Config holds the configuration information for JWT operation between an app and JIRA

func (*Config) Claims

func (c *Config) Claims(qsh string) *AtlassianClaims

Claims returns a valid set of claims for creating an Atlassian JWT

func (*Config) Client

func (c *Config) Client() *http.Client

Client returns an *http.Client that makes requests that are authenticated using Atlassian JWT authentication

func (*Config) QSH

func (c *Config) QSH(req *http.Request) string

QSH returns the query string hash for this request https://developer.atlassian.com/cloud/bitbucket/query-string-hash/

func (*Config) SetAuthHeader

func (c *Config) SetAuthHeader(r *http.Request) error

SetAuthHeader takes a request pointer and sets the Authorization header with a valid Atlassian JWT

func (*Config) Token

func (c *Config) Token(r *http.Request) *jwt.Token

Token returns an unsigned Atlassian JWT

type Transport

type Transport struct {
	// SetAuth sets the
	// Authorization headers.
	Config AuthSetter

	// Base is the base RoundTripper used to make HTTP requests.
	// If nil, http.DefaultTransport is used.
	Base http.RoundTripper
}

Transport is a http.RoundTripper for tagging requests to Atlassian with a JWT auth header

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip authenticates the request with a JWT token

Directories

Path Synopsis
examples
jwt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL