I am using the Atlassian Connect method to save authentication details in my app: https://developer.atlassian.com/cloud/jira/platform/authentication-for-apps/.
Here is some example code for how I call the Jira REST endpoints (`createmeta` in this case).
url = "https://some_account.atlassian.net/rest/api/2/issue/createmeta"
issuer = 'issuer-something' # Defined in your atlassian-connect.json
shared_secret = 'secret' #received from installation
client_key = 'client_key' # received from installation
begin
uri = URI.parse(url)
rescue URI::InvalidURIError
uri = URI.parse(URI.escape(url)) # Atlassian Jwt will throw an error if an unescaped url is passed in
end
claims = Atlassian::Jwt.build_claims(issuer,uri,request_method)
jwt = JWT.encode(claims,shared_secret)
query_arr = URI.decode_www_form(uri.query || '') << ["jwt", jwt]
uri.query = URI.encode_www_form(query_arr)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
request.content_type = "application/json"
response = http.request(request)
I am finding that after some time (maybe like a week or so), this same code that used to return 200s is now 401ing me. Does the shared secret expire? If so, can someone link docs explaining this?