I am attempting to register a web hook to my Jira cloud instance and I am following their documentation but I have not been able to make it work.
Specifically the section: Making API requests to the product as the add-on:
atlassianHostRestClients.authenticatedAsAddon(AddonAuthenticationType.OAUTH2).getForObject("/rest/api/example", Void.class);
My issue is when I run it I get an error:
401 Unauthorized: "{"message":"Client must be authenticated to access this >resource.","status-code":401}"
Now, I know I am not authenticated, but atlassianHostRestClients object, which according to their documentation:
atlassian-connect-spring-boot will automatically sign requests from your add-on to an >installed host product with JSON Web Tokens. To make a request, just autowire an > AtlassianHostRestClients object into your class.
So, anyone has experience with this that could help?
I do this using kotlin and have a generic function in my class
JiraApiHelpers.kt:This let me format the returned object to given data class:
Here
hostUserorigins from my controller which is called by the webhook:This is implemented in a connect-app where the webhook is defined within the app in
atlassian-connect.json:To test your scenario I removed
hostfrom my call to Jira API and it worked as expected:I see in the documentation you linked to, that the use of
AddonAuthenticationType.OAUTH2is limited to Connect-on-Forge apps. Maybe that is why you get 401.