How to authenticate to the Confluence rest api using jwt token ruby

I am trying to make api calls to Confluence cloud by authenticating with jwt. In my descriptor file, I have opted for the read scope.

I am following this guide on how to generate the jwt token. In my code base, I have

require 'atlassian/jwt'
require 'json'
require 'httparty'

url = ""
issuer = 'my_issuer'
http_method = 'get'
shared_secret = 'shared_secret'

claim = Atlassian::Jwt.build_claims(issuer, url, http_method)
jwt = JWT.encode(claim, shared_secret)

response = HTTParty.get("", :headers => {'Content-Type' => 'application/json', authorization: jwt})
puts response

I get the error {“message”:“Current user not permitted to use Confluence”,“statusCode”:403} . I dont know what I am doing wrong. How do I fix this and authenticate properly with jwt token in ruby?

@ibuchanan any help on this will be appreciated


Not a lot of Ruby folks here I guess.

It looks to me like you are forming the Authorization header incorrectly. If it were plain text, it would look like Authorization: JWT abc123. So you have to manually pad the JWT and a space before the jwt variable that you have calculated.

I’m just eyeballing it, so I’m not sure if there are other problems too.