Can't access Assets REST API from connect app

According to the documentation (Authorization) it should be possible to access the Assets REST API from a connect app, based on the Atlassian Connect Spring Boot framework, out of the box:

Ensure your request comes with a valid Connect JWT - this should be handled by the Connect app framework already…

But when I use atlassianHostRestClients.authenticatedAs(hostUser) I get this error:

java.lang.IllegalArgumentException: Aborting the request to https://api.atlassian.com/jsm/assets/workspace/cdc886***/v1/object/3 because this RestTemplate is associated with https://***.atlassian.net
        at com.atlassian.connect.spring.internal.request.AtlassianConnectHttpRequestInterceptor.assertRequestToHost(AtlassianConnectHttpRequestInterceptor.java:41) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at com.atlassian.connect.spring.internal.request.oauth2.OAuth2HttpRequestInterceptor.getHostForRequest(OAuth2HttpRequestInterceptor.java:32) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at com.atlassian.connect.spring.internal.request.AtlassianConnectHttpRequestInterceptor.intercept(AtlassianConnectHttpRequestInterceptor.java:30) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:88) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:72) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:889) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:790) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:404) ~[spring-web-6.1.11.jar:6.1.11]

When I use atlassianHostRestClients.authenticatedAsAddon(host) I get a similar error:

java.lang.IllegalArgumentException: The given URI is not under the base URL of the given host
        at com.atlassian.connect.spring.internal.request.jwt.JwtGenerator.assertRequestToHost(JwtGenerator.java:80) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at com.atlassian.connect.spring.internal.request.jwt.JwtGenerator.createJwtToken(JwtGenerator.java:53) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at com.atlassian.connect.spring.internal.request.jwt.JwtSigningClientHttpRequestInterceptor.rewrapRequest(JwtSigningClientHttpRequestInterceptor.java:62) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at com.atlassian.connect.spring.internal.request.AtlassianConnectHttpRequestInterceptor.wrapRequest(AtlassianConnectHttpRequestInterceptor.java:56) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at com.atlassian.connect.spring.internal.request.AtlassianConnectHttpRequestInterceptor.lambda$intercept$0(AtlassianConnectHttpRequestInterceptor.java:30) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at java.base/java.util.Optional.map(Optional.java:260) ~[na:na]
        at com.atlassian.connect.spring.internal.request.AtlassianConnectHttpRequestInterceptor.intercept(AtlassianConnectHttpRequestInterceptor.java:30) ~[atlassian-connect-spring-boot-core-5.0.0.jar:na]
        at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:88) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:72) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:889) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:790) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:404) ~[spring-web-6.1.11.jar:6.1.11]

When I use atlassianHostRestClients.authenticatedAsAddon() I get this error:

org.springframework.web.client.HttpClientErrorException$Unauthorized: 401 Unauthorized: "{"code":401,"message":"Unauthorized"}"
        at org.springframework.web.client.HttpClientErrorException.create(HttpClientErrorException.java:106) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:183) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:137) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:942) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:891) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:790) ~[spring-web-6.1.11.jar:6.1.11]
        at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:404) ~[spring-web-6.1.11.jar:6.1.11]

The call to get the workspace ID and other calls to the Jira REST API work as expected.

Is it actually possible to use JWT authentication to call api.atlassian.com? And if so how?

1 Like

Apparently it is currently not possible for a Connect app to access Assets using JWT authentication, see: https://jira.atlassian.com/browse/JSDCLOUD-12080