Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use API Token to authenticate to Jira Cloud REST from Swagger generated code?

Atlassian Admin CloudPay
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 8, 2022

I'm brand new to the swagger-gen Jira REST API for Cloud.

I have the code generated but cannot authenticate using Basic, which is expected because it's deprecated. I have my API token generated but cannot figure out how to use it.

The two posts that show how to use the API, they use Basic auth.

(https://community.atlassian.com/t5/Jira-articles/Generating-a-REST-client-for-Jira-Cloud/ba-p/1307133)

and diving into the code, Jersey then sends a BASIC authentication which gets rejected.

Looking at the generated ApiClient.java it has two methods defined


authentications = new HashMap<String, Authentication>();
authentications.put("OAuth2", new OAuth());
authentications.put("basicAuth", new HttpBasicAuth());

But there's a third way in the code - ApiKeyAuth.java
and I think that's what I now need to use.

How do I use it?
Do I regenerate the code with some extra options to swagger or do I edit Atlassian's JSON:

I see this section in the JSON for each call, is it now wrong?
"security": [
{
"basicAuth": []
},
{
"OAuth2": [
"read:jira-work"
]
},

I hope that all makes sense, it's been an afternoon of rabbit holes. But if I'm right the docs need an update because they keep referring to Basic auth.
many thanks

0 answers

Suggest an answer

Log in or Sign up to answer