Cannot authenticate request to my app in Confluence

Hi @ajdionisio,

As the example is a bit outdated I suspect you are running into the recent changes described in this topic. There’s a few steps you’ll need to take in order to get it working:

  • Set <atlassian-connect-spring-boot.version>2.1.0</atlassian-connect-spring-boot.version> to 2.1.5 or later in the pom.xml
  • Add the @ContextJwt annotation to the endpoint in the DataController
  • Add the following to your atlassian-connect.json (might actually not be required anymore):
  "apiMigrations": {
     "context-qsh": true
  }

EDIT: Sorry, I hadn’t looked at the JavaScript code in the repository and was blindly assuming it was using AP.context.getToken which it actually does not. To make what I wrote above work you’ll also need to adjust the JS in iframe.html:

$(document).ready(function() {
	$('#hello').click(function() {
		AP.context.getToken().then(function(token) {
			$.ajax({
				url: 'data',
				beforeSend: function(request) {
					request.setRequestHeader('Authorization', 'JWT ' + token);
				}
			}).done(function(data) {
				alert(JSON.stringify(data, null, '\t'));
			});
		});
	});
});

To be honest, I’m not 100% sure why it doesn’t work with the token that’s generated on the backend. But it might still be related to the context QSH changes.


After doing all of that, and re-installing your app into your instance, I think it should work. Hope this helps!

Cheers,
Sven

2 Likes